Model.predict_proba

In [ ]:
Model.predict_proba(vdf: Union[str, vDataFrame],
                    X: list = [],
                    name: str = "",
                    pos_label: Union[int, str, float] = None,
                    inplace: bool = True)

Returns the model's probabilities using the input relation.

Parameters

Name Type Optional Description
vdf
str / vDataFrame
Object to use to run the prediction. It can also be a customized relation but you need to englobe it using an alias. For example "(SELECT 1) x" is correct whereas "(SELECT 1)" or "SELECT 1" are incorrect.
X
list
List of the columns used to deploy the models. If empty, the model predictors will be used.
name
str
Name of the added vcolumn. If empty, a name will be generated.
pos_label
int / str / float
Class label, the class for which the probability is calculated. If name is specified and pos_label is unspecified, the probability column names use the following format: name_class1, name_class2, etc.
inplace
bool
If set to True, the prediction will be added to the vDataFrame.

Returns

vDataFrame : the input object.

Example

In [1]:
from verticapy.datasets import load_iris
iris = load_iris()
display(iris)
123
SepalLengthCm
Numeric(5,2)
123
SepalWidthCm
Numeric(5,2)
123
PetalLengthCm
Numeric(5,2)
123
PetalWidthCm
Numeric(5,2)
Abc
Species
Varchar(30)
14.33.01.10.1Iris-setosa
24.42.91.40.2Iris-setosa
34.43.01.30.2Iris-setosa
44.43.21.30.2Iris-setosa
54.52.31.30.3Iris-setosa
64.63.11.50.2Iris-setosa
74.63.21.40.2Iris-setosa
84.63.41.40.3Iris-setosa
94.63.61.00.2Iris-setosa
104.73.21.30.2Iris-setosa
114.73.21.60.2Iris-setosa
124.83.01.40.1Iris-setosa
134.83.01.40.3Iris-setosa
144.83.11.60.2Iris-setosa
154.83.41.60.2Iris-setosa
164.83.41.90.2Iris-setosa
174.92.43.31.0Iris-versicolor
184.92.54.51.7Iris-virginica
194.93.01.40.2Iris-setosa
204.93.11.50.1Iris-setosa
214.93.11.50.1Iris-setosa
224.93.11.50.1Iris-setosa
235.02.03.51.0Iris-versicolor
245.02.33.31.0Iris-versicolor
255.03.01.60.2Iris-setosa
265.03.21.20.2Iris-setosa
275.03.31.40.2Iris-setosa
285.03.41.50.2Iris-setosa
295.03.41.60.4Iris-setosa
305.03.51.30.3Iris-setosa
315.03.51.60.6Iris-setosa
325.03.61.40.2Iris-setosa
335.12.53.01.1Iris-versicolor
345.13.31.70.5Iris-setosa
355.13.41.50.2Iris-setosa
365.13.51.40.2Iris-setosa
375.13.51.40.3Iris-setosa
385.13.71.50.4Iris-setosa
395.13.81.50.3Iris-setosa
405.13.81.60.2Iris-setosa
415.13.81.90.4Iris-setosa
425.22.73.91.4Iris-versicolor
435.23.41.40.2Iris-setosa
445.23.51.50.2Iris-setosa
455.24.11.50.1Iris-setosa
465.33.71.50.2Iris-setosa
475.43.04.51.5Iris-versicolor
485.43.41.50.4Iris-setosa
495.43.41.70.2Iris-setosa
505.43.71.50.2Iris-setosa
515.43.91.30.4Iris-setosa
525.43.91.70.4Iris-setosa
535.52.34.01.3Iris-versicolor
545.52.43.71.0Iris-versicolor
555.52.43.81.1Iris-versicolor
565.52.54.01.3Iris-versicolor
575.52.64.41.2Iris-versicolor
585.53.51.30.2Iris-setosa
595.54.21.40.2Iris-setosa
605.62.53.91.1Iris-versicolor
615.62.74.21.3Iris-versicolor
625.62.84.92.0Iris-virginica
635.62.93.61.3Iris-versicolor
645.63.04.11.3Iris-versicolor
655.63.04.51.5Iris-versicolor
665.72.55.02.0Iris-virginica
675.72.63.51.0Iris-versicolor
685.72.84.11.3Iris-versicolor
695.72.84.51.3Iris-versicolor
705.72.94.21.3Iris-versicolor
715.73.04.21.2Iris-versicolor
725.73.81.70.3Iris-setosa
735.74.41.50.4Iris-setosa
745.82.64.01.2Iris-versicolor
755.82.73.91.2Iris-versicolor
765.82.74.11.0Iris-versicolor
775.82.75.11.9Iris-virginica
785.82.75.11.9Iris-virginica
795.82.85.12.4Iris-virginica
805.84.01.20.2Iris-setosa
815.93.04.21.5Iris-versicolor
825.93.05.11.8Iris-virginica
835.93.24.81.8Iris-versicolor
846.02.24.01.0Iris-versicolor
856.02.25.01.5Iris-virginica
866.02.75.11.6Iris-versicolor
876.02.94.51.5Iris-versicolor
886.03.04.81.8Iris-virginica
896.03.44.51.6Iris-versicolor
906.12.65.61.4Iris-virginica
916.12.84.01.3Iris-versicolor
926.12.84.71.2Iris-versicolor
936.12.94.71.4Iris-versicolor
946.13.04.61.4Iris-versicolor
956.13.04.91.8Iris-virginica
966.22.24.51.5Iris-versicolor
976.22.84.81.8Iris-virginica
986.22.94.31.3Iris-versicolor
996.23.45.42.3Iris-virginica
1006.32.34.41.3Iris-versicolor
Rows: 1-100 | Columns: 5
In [2]:
from verticapy.learn.ensemble import RandomForestClassifier
model = RandomForestClassifier(name = "public.RF_iris",
                               n_estimators = 20,
                               max_features = "auto",
                               max_leaf_nodes = 32, 
                               sample = 0.7,
                               max_depth = 3,
                               min_samples_leaf = 5,
                               min_info_gain = 0.0,
                               nbins = 32)
model.fit(iris, ["PetalLengthCm", "PetalWidthCm"], "Species")
model.predict_proba(iris, 
                    X = ["PetalLengthCm", "PetalWidthCm"],
                    name = "iris_prediction")
Out[2]:
123
SepalLengthCm
Numeric(5,2)
123
SepalWidthCm
Numeric(5,2)
123
PetalLengthCm
Numeric(5,2)
123
PetalWidthCm
Numeric(5,2)
Abc
Species
Varchar(30)
Abc
iris_prediction_irissetosa
Varchar(128)
Abc
iris_prediction_irisversicolor
Varchar(128)
Abc
iris_prediction_irisvirginica
Varchar(128)
14.33.01.10.1Iris-setosa100
24.42.91.40.2Iris-setosa100
34.43.01.30.2Iris-setosa100
44.43.21.30.2Iris-setosa100
54.52.31.30.3Iris-setosa100
64.63.11.50.2Iris-setosa100
74.63.21.40.2Iris-setosa100
84.63.41.40.3Iris-setosa100
94.63.61.00.2Iris-setosa100
104.73.21.30.2Iris-setosa100
114.73.21.60.2Iris-setosa100
124.83.01.40.1Iris-setosa100
134.83.01.40.3Iris-setosa100
144.83.11.60.2Iris-setosa100
154.83.41.60.2Iris-setosa100
164.83.41.90.2Iris-setosa0.9028570.09428570.00285714
174.92.43.31.0Iris-versicolor0.01707250.9658550.0170725
184.92.54.51.7Iris-virginica0.04135080.9172980.0413508
194.93.01.40.2Iris-setosa100
204.93.11.50.1Iris-setosa100
214.93.11.50.1Iris-setosa100
224.93.11.50.1Iris-setosa100
235.02.03.51.0Iris-versicolor0.01707250.9658550.0170725
245.02.33.31.0Iris-versicolor0.01707250.9658550.0170725
255.03.01.60.2Iris-setosa100
265.03.21.20.2Iris-setosa100
275.03.31.40.2Iris-setosa100
285.03.41.50.2Iris-setosa100
295.03.41.60.4Iris-setosa100
305.03.51.30.3Iris-setosa100
315.03.51.60.6Iris-setosa0.9006580.09868420.000657895
325.03.61.40.2Iris-setosa100
335.12.53.01.1Iris-versicolor0.01707250.9658550.0170725
345.13.31.70.5Iris-setosa100
355.13.41.50.2Iris-setosa100
365.13.51.40.2Iris-setosa100
375.13.51.40.3Iris-setosa100
385.13.71.50.4Iris-setosa100
395.13.81.50.3Iris-setosa100
405.13.81.60.2Iris-setosa100
415.13.81.90.4Iris-setosa0.9028570.09428570.00285714
425.22.73.91.4Iris-versicolor0.02546060.9490790.0254606
435.23.41.40.2Iris-setosa100
445.23.51.50.2Iris-setosa100
455.24.11.50.1Iris-setosa100
465.33.71.50.2Iris-setosa100
475.43.04.51.5Iris-versicolor0.03375270.9324950.0337527
485.43.41.50.4Iris-setosa100
495.43.41.70.2Iris-setosa100
505.43.71.50.2Iris-setosa100
515.43.91.30.4Iris-setosa100
525.43.91.70.4Iris-setosa100
535.52.34.01.3Iris-versicolor0.01707250.9658550.0170725
545.52.43.71.0Iris-versicolor0.01707250.9658550.0170725
555.52.43.81.1Iris-versicolor0.01707250.9658550.0170725
565.52.54.01.3Iris-versicolor0.01707250.9658550.0170725
575.52.64.41.2Iris-versicolor0.01707250.9658550.0170725
585.53.51.30.2Iris-setosa100
595.54.21.40.2Iris-setosa100
605.62.53.91.1Iris-versicolor0.01707250.9658550.0170725
615.62.74.21.3Iris-versicolor0.01707250.9658550.0170725
625.62.84.92.0Iris-virginica0.05395230.05395230.892095
635.62.93.61.3Iris-versicolor0.01707250.9658550.0170725
645.63.04.11.3Iris-versicolor0.01707250.9658550.0170725
655.63.04.51.5Iris-versicolor0.03375270.9324950.0337527
665.72.55.02.0Iris-virginica0.05395230.05395230.892095
675.72.63.51.0Iris-versicolor0.01707250.9658550.0170725
685.72.84.11.3Iris-versicolor0.01707250.9658550.0170725
695.72.84.51.3Iris-versicolor0.02536460.9492710.0253646
705.72.94.21.3Iris-versicolor0.01707250.9658550.0170725
715.73.04.21.2Iris-versicolor0.01707250.9658550.0170725
725.73.81.70.3Iris-setosa100
735.74.41.50.4Iris-setosa100
745.82.64.01.2Iris-versicolor0.01707250.9658550.0170725
755.82.73.91.2Iris-versicolor0.01707250.9658550.0170725
765.82.74.11.0Iris-versicolor0.01707250.9658550.0170725
775.82.75.11.9Iris-virginica0.02740860.02740860.945183
785.82.75.11.9Iris-virginica0.02740860.02740860.945183
795.82.85.12.4Iris-virginica0.02740860.02740860.945183
805.84.01.20.2Iris-setosa100
815.93.04.21.5Iris-versicolor0.02546060.9490790.0254606
825.93.05.11.8Iris-virginica0.02740860.02740860.945183
835.93.24.81.8Iris-versicolor0.05395230.05395230.892095
846.02.24.01.0Iris-versicolor0.01707250.9658550.0170725
856.02.25.01.5Iris-virginica0.1082860.5940160.297698
866.02.75.11.6Iris-versicolor0.09204980.5549850.352965
876.02.94.51.5Iris-versicolor0.03375270.9324950.0337527
886.03.04.81.8Iris-virginica0.05395230.05395230.892095
896.03.44.51.6Iris-versicolor0.04135080.9172980.0413508
906.12.65.61.4Iris-virginica0.08445170.5701810.345367
916.12.84.01.3Iris-versicolor0.01707250.9658550.0170725
926.12.84.71.2Iris-versicolor0.02536460.9492710.0253646
936.12.94.71.4Iris-versicolor0.03375270.9324950.0337527
946.13.04.61.4Iris-versicolor0.03375270.9324950.0337527
956.13.04.91.8Iris-virginica0.05395230.05395230.892095
966.22.24.51.5Iris-versicolor0.03375270.9324950.0337527
976.22.84.81.8Iris-virginica0.05395230.05395230.892095
986.22.94.31.3Iris-versicolor0.01707250.9658550.0170725
996.23.45.42.3Iris-virginica0.02740860.02740860.945183
1006.32.34.41.3Iris-versicolor0.01707250.9658550.0170725
Rows: 1-100 | Columns: 8
In [3]:
# You can also specify a pos_label
model.predict_proba(iris, 
                    X = ["PetalLengthCm", "PetalWidthCm"],
                    name = "iris_prob_setosa",
                    pos_label = "Iris-setosa")
Out[3]:
123
SepalLengthCm
Numeric(5,2)
123
SepalWidthCm
Numeric(5,2)
123
PetalLengthCm
Numeric(5,2)
123
PetalWidthCm
Numeric(5,2)
Abc
Species
Varchar(30)
Abc
iris_prediction_irissetosa
Varchar(128)
Abc
iris_prediction_irisversicolor
Varchar(128)
Abc
iris_prediction_irisvirginica
Varchar(128)
Abc
iris_prob_setosa
Varchar(128)
14.33.01.10.1Iris-setosa1001
24.42.91.40.2Iris-setosa1001
34.43.01.30.2Iris-setosa1001
44.43.21.30.2Iris-setosa1001
54.52.31.30.3Iris-setosa1001
64.63.11.50.2Iris-setosa1001
74.63.21.40.2Iris-setosa1001
84.63.41.40.3Iris-setosa1001
94.63.61.00.2Iris-setosa1001
104.73.21.30.2Iris-setosa1001
114.73.21.60.2Iris-setosa1001
124.83.01.40.1Iris-setosa1001
134.83.01.40.3Iris-setosa1001
144.83.11.60.2Iris-setosa1001
154.83.41.60.2Iris-setosa1001
164.83.41.90.2Iris-setosa0.9028570.09428570.002857140.902857
174.92.43.31.0Iris-versicolor0.01707250.9658550.01707250.0170725
184.92.54.51.7Iris-virginica0.04135080.9172980.04135080.0413508
194.93.01.40.2Iris-setosa1001
204.93.11.50.1Iris-setosa1001
214.93.11.50.1Iris-setosa1001
224.93.11.50.1Iris-setosa1001
235.02.03.51.0Iris-versicolor0.01707250.9658550.01707250.0170725
245.02.33.31.0Iris-versicolor0.01707250.9658550.01707250.0170725
255.03.01.60.2Iris-setosa1001
265.03.21.20.2Iris-setosa1001
275.03.31.40.2Iris-setosa1001
285.03.41.50.2Iris-setosa1001
295.03.41.60.4Iris-setosa1001
305.03.51.30.3Iris-setosa1001
315.03.51.60.6Iris-setosa0.9006580.09868420.0006578950.900658
325.03.61.40.2Iris-setosa1001
335.12.53.01.1Iris-versicolor0.01707250.9658550.01707250.0170725
345.13.31.70.5Iris-setosa1001
355.13.41.50.2Iris-setosa1001
365.13.51.40.2Iris-setosa1001
375.13.51.40.3Iris-setosa1001
385.13.71.50.4Iris-setosa1001
395.13.81.50.3Iris-setosa1001
405.13.81.60.2Iris-setosa1001
415.13.81.90.4Iris-setosa0.9028570.09428570.002857140.902857
425.22.73.91.4Iris-versicolor0.02546060.9490790.02546060.0254606
435.23.41.40.2Iris-setosa1001
445.23.51.50.2Iris-setosa1001
455.24.11.50.1Iris-setosa1001
465.33.71.50.2Iris-setosa1001
475.43.04.51.5Iris-versicolor0.03375270.9324950.03375270.0337527
485.43.41.50.4Iris-setosa1001
495.43.41.70.2Iris-setosa1001
505.43.71.50.2Iris-setosa1001
515.43.91.30.4Iris-setosa1001
525.43.91.70.4Iris-setosa1001
535.52.34.01.3Iris-versicolor0.01707250.9658550.01707250.0170725
545.52.43.71.0Iris-versicolor0.01707250.9658550.01707250.0170725
555.52.43.81.1Iris-versicolor0.01707250.9658550.01707250.0170725
565.52.54.01.3Iris-versicolor0.01707250.9658550.01707250.0170725
575.52.64.41.2Iris-versicolor0.01707250.9658550.01707250.0170725
585.53.51.30.2Iris-setosa1001
595.54.21.40.2Iris-setosa1001
605.62.53.91.1Iris-versicolor0.01707250.9658550.01707250.0170725
615.62.74.21.3Iris-versicolor0.01707250.9658550.01707250.0170725
625.62.84.92.0Iris-virginica0.05395230.05395230.8920950.0539523
635.62.93.61.3Iris-versicolor0.01707250.9658550.01707250.0170725
645.63.04.11.3Iris-versicolor0.01707250.9658550.01707250.0170725
655.63.04.51.5Iris-versicolor0.03375270.9324950.03375270.0337527
665.72.55.02.0Iris-virginica0.05395230.05395230.8920950.0539523
675.72.63.51.0Iris-versicolor0.01707250.9658550.01707250.0170725
685.72.84.11.3Iris-versicolor0.01707250.9658550.01707250.0170725
695.72.84.51.3Iris-versicolor0.02536460.9492710.02536460.0253646
705.72.94.21.3Iris-versicolor0.01707250.9658550.01707250.0170725
715.73.04.21.2Iris-versicolor0.01707250.9658550.01707250.0170725
725.73.81.70.3Iris-setosa1001
735.74.41.50.4Iris-setosa1001
745.82.64.01.2Iris-versicolor0.01707250.9658550.01707250.0170725
755.82.73.91.2Iris-versicolor0.01707250.9658550.01707250.0170725
765.82.74.11.0Iris-versicolor0.01707250.9658550.01707250.0170725
775.82.75.11.9Iris-virginica0.02740860.02740860.9451830.0274086
785.82.75.11.9Iris-virginica0.02740860.02740860.9451830.0274086
795.82.85.12.4Iris-virginica0.02740860.02740860.9451830.0274086
805.84.01.20.2Iris-setosa1001
815.93.04.21.5Iris-versicolor0.02546060.9490790.02546060.0254606
825.93.05.11.8Iris-virginica0.02740860.02740860.9451830.0274086
835.93.24.81.8Iris-versicolor0.05395230.05395230.8920950.0539523
846.02.24.01.0Iris-versicolor0.01707250.9658550.01707250.0170725
856.02.25.01.5Iris-virginica0.1082860.5940160.2976980.108286
866.02.75.11.6Iris-versicolor0.09204980.5549850.3529650.0920498
876.02.94.51.5Iris-versicolor0.03375270.9324950.03375270.0337527
886.03.04.81.8Iris-virginica0.05395230.05395230.8920950.0539523
896.03.44.51.6Iris-versicolor0.04135080.9172980.04135080.0413508
906.12.65.61.4Iris-virginica0.08445170.5701810.3453670.0844517
916.12.84.01.3Iris-versicolor0.01707250.9658550.01707250.0170725
926.12.84.71.2Iris-versicolor0.02536460.9492710.02536460.0253646
936.12.94.71.4Iris-versicolor0.03375270.9324950.03375270.0337527
946.13.04.61.4Iris-versicolor0.03375270.9324950.03375270.0337527
956.13.04.91.8Iris-virginica0.05395230.05395230.8920950.0539523
966.22.24.51.5Iris-versicolor0.03375270.9324950.03375270.0337527
976.22.84.81.8Iris-virginica0.05395230.05395230.8920950.0539523
986.22.94.31.3Iris-versicolor0.01707250.9658550.01707250.0170725
996.23.45.42.3Iris-virginica0.02740860.02740860.9451830.0274086
1006.32.34.41.3Iris-versicolor0.01707250.9658550.01707250.0170725
Rows: 1-100 | Columns: 9