woodpecker/sklearn/randomforest/random_forest_structure_classifier.py
def show_prediction_probabilities_distribution(self, dataset, correct_prediction=True, by_class=False,
                                                   figsize=(20, 10)):
        """Visualize prediction probabilities for correct or incorrect predictions.

        This is useful to see model confidence for its predictions. Predicted class is chosen based on it's prediction
        probabilities. A class is predicted if it has a probability between 0.5 and 1.0. Having a higher probability,
        it means that the model is more confident for predicted class.


        :param by_class: boolean
            by_class=True if we want to see prediction distribution by classes,
            by_class=False if we want to see prediction distribution in general
        :param dataset: pandas dataframe
            The dataset to make predictions on.
        :param correct_prediction: boolean
            correct_prediction=True if we want to see correct predicted classes, False otherwise.
        :param figsize: tuple
            The plot size
        """

        dataset = dataset.copy()
        dataset["predicted_class"] = self.rf.predict(dataset[self.features])
        dataset["predicted_max_proba"] = [max(predict_proba) for predict_proba in
                                          self.rf.predict_proba(dataset[self.features])]
        if correct_prediction:
            dataset = dataset[dataset[self.target] == dataset["predicted_class"]]
        elif not correct_prediction:
            dataset = dataset[dataset[self.target] != dataset["predicted_class"]]

        print(f"number of samples {dataset.shape[0]}")
        _ = plt.figure(figsize=figsize)
        if not by_class:
            _ = dataset.predicted_max_proba.plot.hist(bins=30)
        elif by_class:
            _ = dataset[dataset[self.target] == 0].predicted_max_proba.plot.hist(bins=30, label="class 0")
            _ = dataset[dataset[self.target] == 1].predicted_max_proba.plot.hist(bins=30, label="class 1")
            _ = plt.legend()
Visualize prediction probabilities for correct or incorrect predictions.

        This is useful to see model confidence for its predictions. Predicted class is chosen based on it's prediction
        probabilities. A class is predicted if it has a probability between 0.5 and 1.0. Having a higher probability,
        it means that the model is more confident for predicted class.


        :param by_class: boolean
            by_class=True if we want to see prediction distribution by classes,
            by_class=False if we want to see prediction distribution in general
        :param dataset: pandas dataframe
            The dataset to make predictions on.
        :param correct_prediction: boolean
            correct_prediction=True if we want to see correct predicted classes, False otherwise.
        :param figsize: tuple
            The plot size
        
Visualize prediction probabilities for correct or incorrect predictions.
This is useful to see model confidence for its predictions. Predicted class is chosen based on it's prediction
probabilities. A class is predicted if it has a probability between 0.5 and 1.0. Having a higher probability,
it means that the model is more confident for predicted class.
Visualize prediction probabilities for correct or incorrect predictions . This is useful to see model confidence for its predictions . Predicted class is chosen based on it ' s prediction probabilities . A class is predicted if it has a probability between 0 . 5 and 1 . 0 . Having a higher probability it means that the model is more confident for predicted class .
def show_prediction_probabilities_distribution(self, dataset, correct_prediction=True, by_class=False,
                                                   figsize=(20, 10)):
        dataset = dataset.copy()
        dataset["predicted_class"] = self.rf.predict(dataset[self.features])
        dataset["predicted_max_proba"] = [max(predict_proba) for predict_proba in
                                          self.rf.predict_proba(dataset[self.features])]
        if correct_prediction:
            dataset = dataset[dataset[self.target] == dataset["predicted_class"]]
        elif not correct_prediction:
            dataset = dataset[dataset[self.target] != dataset["predicted_class"]]
        print(f"number of samples {dataset.shape[0]}")
        _ = plt.figure(figsize=figsize)
        if not by_class:
            _ = dataset.predicted_max_proba.plot.hist(bins=30)
        elif by_class:
            _ = dataset[dataset[self.target] == 0].predicted_max_proba.plot.hist(bins=30, label="class 0")
            _ = dataset[dataset[self.target] == 1].predicted_max_proba.plot.hist(bins=30, label="class 1")
            _ = plt.legend()
def show_prediction_probabilities_distribution ( self , dataset , correct_prediction = True , by_class = False , figsize = ( 20 , 10 ) ) : dataset = dataset . copy ( ) dataset [ "predicted_class" ] = self . rf . predict ( dataset [ self . features ] ) dataset [ "predicted_max_proba" ] = [ max ( predict_proba ) for predict_proba in self . rf . predict_proba ( dataset [ self . features ] ) ] if correct_prediction : dataset = dataset [ dataset [ self . target ] == dataset [ "predicted_class" ] ] elif not correct_prediction : dataset = dataset [ dataset [ self . target ] != dataset [ "predicted_class" ] ] print ( f"number of samples {dataset.shape[0]}" ) _ = plt . figure ( figsize = figsize ) if not by_class : _ = dataset . predicted_max_proba . plot . hist ( bins = 30 ) elif by_class : _ = dataset [ dataset [ self . target ] == 0 ] . predicted_max_proba . plot . hist ( bins = 30 , label = "class 0" ) _ = dataset [ dataset [ self . target ] == 1 ] . predicted_max_proba . plot . hist ( bins = 30 , label = "class 1" ) _ = plt . legend ( )
Visualize prediction probabilities for correct or incorrect predictions.
Visualize prediction probabilities for correct or incorrect predictions .
"""Visualize prediction probabilities for correct or incorrect predictions.

        This is useful to see model confidence for its predictions. Predicted class is chosen based on it's prediction
        probabilities. A class is predicted if it has a probability between 0.5 and 1.0. Having a higher probability,
        it means that the model is more confident for predicted class.


        :param by_class: boolean
            by_class=True if we want to see prediction distribution by classes,
            by_class=False if we want to see prediction distribution in general
        :param dataset: pandas dataframe
            The dataset to make predictions on.
        :param correct_prediction: boolean
            correct_prediction=True if we want to see correct predicted classes, False otherwise.
        :param figsize: tuple
            The plot size
        """
self
dataset
pandas dataframe
The dataset to make predictions on.
pandas dataframe The dataset to make predictions on .
correct_prediction
boolean
correct_prediction=True if we want to see correct predicted classes, False otherwise.
boolean correct_prediction = True if we want to see correct predicted classes False otherwise .
by_class
boolean
by_class=True if we want to see prediction distribution by classes,
by_class=False if we want to see prediction distribution in general
boolean by_class = True if we want to see prediction distribution by classes by_class = False if we want to see prediction distribution in general
figsize
tuple
The plot size
tuple The plot size