Model.predict

In [ ]:
Model.predict(vdf: Union[str, vDataFrame],
              X: list = [],
              name: str = "",
              cutoff: float = 0.5,
              inplace: bool = True)

Predicts 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.
cutoff
float
Cutoff for which the tested category will be accepted as a prediction. This parameter is only used for binary classification.
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.303.001.100.10Iris-setosa
24.402.901.400.20Iris-setosa
34.403.001.300.20Iris-setosa
44.403.201.300.20Iris-setosa
54.502.301.300.30Iris-setosa
64.603.101.500.20Iris-setosa
74.603.201.400.20Iris-setosa
84.603.401.400.30Iris-setosa
94.603.601.000.20Iris-setosa
104.703.201.300.20Iris-setosa
114.703.201.600.20Iris-setosa
124.803.001.400.10Iris-setosa
134.803.001.400.30Iris-setosa
144.803.101.600.20Iris-setosa
154.803.401.600.20Iris-setosa
164.803.401.900.20Iris-setosa
174.902.403.301.00Iris-versicolor
184.902.504.501.70Iris-virginica
194.903.001.400.20Iris-setosa
204.903.101.500.10Iris-setosa
214.903.101.500.10Iris-setosa
224.903.101.500.10Iris-setosa
235.002.003.501.00Iris-versicolor
245.002.303.301.00Iris-versicolor
255.003.001.600.20Iris-setosa
265.003.201.200.20Iris-setosa
275.003.301.400.20Iris-setosa
285.003.401.500.20Iris-setosa
295.003.401.600.40Iris-setosa
305.003.501.300.30Iris-setosa
315.003.501.600.60Iris-setosa
325.003.601.400.20Iris-setosa
335.102.503.001.10Iris-versicolor
345.103.301.700.50Iris-setosa
355.103.401.500.20Iris-setosa
365.103.501.400.20Iris-setosa
375.103.501.400.30Iris-setosa
385.103.701.500.40Iris-setosa
395.103.801.500.30Iris-setosa
405.103.801.600.20Iris-setosa
415.103.801.900.40Iris-setosa
425.202.703.901.40Iris-versicolor
435.203.401.400.20Iris-setosa
445.203.501.500.20Iris-setosa
455.204.101.500.10Iris-setosa
465.303.701.500.20Iris-setosa
475.403.004.501.50Iris-versicolor
485.403.401.500.40Iris-setosa
495.403.401.700.20Iris-setosa
505.403.701.500.20Iris-setosa
515.403.901.300.40Iris-setosa
525.403.901.700.40Iris-setosa
535.502.304.001.30Iris-versicolor
545.502.403.701.00Iris-versicolor
555.502.403.801.10Iris-versicolor
565.502.504.001.30Iris-versicolor
575.502.604.401.20Iris-versicolor
585.503.501.300.20Iris-setosa
595.504.201.400.20Iris-setosa
605.602.503.901.10Iris-versicolor
615.602.704.201.30Iris-versicolor
625.602.804.902.00Iris-virginica
635.602.903.601.30Iris-versicolor
645.603.004.101.30Iris-versicolor
655.603.004.501.50Iris-versicolor
665.702.505.002.00Iris-virginica
675.702.603.501.00Iris-versicolor
685.702.804.101.30Iris-versicolor
695.702.804.501.30Iris-versicolor
705.702.904.201.30Iris-versicolor
715.703.004.201.20Iris-versicolor
725.703.801.700.30Iris-setosa
735.704.401.500.40Iris-setosa
745.802.604.001.20Iris-versicolor
755.802.703.901.20Iris-versicolor
765.802.704.101.00Iris-versicolor
775.802.705.101.90Iris-virginica
785.802.705.101.90Iris-virginica
795.802.805.102.40Iris-virginica
805.804.001.200.20Iris-setosa
815.903.004.201.50Iris-versicolor
825.903.005.101.80Iris-virginica
835.903.204.801.80Iris-versicolor
846.002.204.001.00Iris-versicolor
856.002.205.001.50Iris-virginica
866.002.705.101.60Iris-versicolor
876.002.904.501.50Iris-versicolor
886.003.004.801.80Iris-virginica
896.003.404.501.60Iris-versicolor
906.102.605.601.40Iris-virginica
916.102.804.001.30Iris-versicolor
926.102.804.701.20Iris-versicolor
936.102.904.701.40Iris-versicolor
946.103.004.601.40Iris-versicolor
956.103.004.901.80Iris-virginica
966.202.204.501.50Iris-versicolor
976.202.804.801.80Iris-virginica
986.202.904.301.30Iris-versicolor
996.203.405.402.30Iris-virginica
1006.302.304.401.30Iris-versicolor
Rows: 1-100 of 150 | Columns: 5
In [3]:
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(iris, 
              X = ["PetalLengthCm", "PetalWidthCm"],
              name = "iris_prediction")
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
Varchar(128)
14.303.001.100.10Iris-setosaIris-setosa
24.402.901.400.20Iris-setosaIris-setosa
34.403.001.300.20Iris-setosaIris-setosa
44.403.201.300.20Iris-setosaIris-setosa
54.502.301.300.30Iris-setosaIris-setosa
64.603.101.500.20Iris-setosaIris-setosa
74.603.201.400.20Iris-setosaIris-setosa
84.603.401.400.30Iris-setosaIris-setosa
94.603.601.000.20Iris-setosaIris-setosa
104.703.201.300.20Iris-setosaIris-setosa
114.703.201.600.20Iris-setosaIris-setosa
124.803.001.400.10Iris-setosaIris-setosa
134.803.001.400.30Iris-setosaIris-setosa
144.803.101.600.20Iris-setosaIris-setosa
154.803.401.600.20Iris-setosaIris-setosa
164.803.401.900.20Iris-setosaIris-setosa
174.902.403.301.00Iris-versicolorIris-versicolor
184.902.504.501.70Iris-virginicaIris-versicolor
194.903.001.400.20Iris-setosaIris-setosa
204.903.101.500.10Iris-setosaIris-setosa
214.903.101.500.10Iris-setosaIris-setosa
224.903.101.500.10Iris-setosaIris-setosa
235.002.003.501.00Iris-versicolorIris-versicolor
245.002.303.301.00Iris-versicolorIris-versicolor
255.003.001.600.20Iris-setosaIris-setosa
265.003.201.200.20Iris-setosaIris-setosa
275.003.301.400.20Iris-setosaIris-setosa
285.003.401.500.20Iris-setosaIris-setosa
295.003.401.600.40Iris-setosaIris-setosa
305.003.501.300.30Iris-setosaIris-setosa
315.003.501.600.60Iris-setosaIris-setosa
325.003.601.400.20Iris-setosaIris-setosa
335.102.503.001.10Iris-versicolorIris-versicolor
345.103.301.700.50Iris-setosaIris-setosa
355.103.401.500.20Iris-setosaIris-setosa
365.103.501.400.20Iris-setosaIris-setosa
375.103.501.400.30Iris-setosaIris-setosa
385.103.701.500.40Iris-setosaIris-setosa
395.103.801.500.30Iris-setosaIris-setosa
405.103.801.600.20Iris-setosaIris-setosa
415.103.801.900.40Iris-setosaIris-setosa
425.202.703.901.40Iris-versicolorIris-versicolor
435.203.401.400.20Iris-setosaIris-setosa
445.203.501.500.20Iris-setosaIris-setosa
455.204.101.500.10Iris-setosaIris-setosa
465.303.701.500.20Iris-setosaIris-setosa
475.403.004.501.50Iris-versicolorIris-versicolor
485.403.401.500.40Iris-setosaIris-setosa
495.403.401.700.20Iris-setosaIris-setosa
505.403.701.500.20Iris-setosaIris-setosa
515.403.901.300.40Iris-setosaIris-setosa
525.403.901.700.40Iris-setosaIris-setosa
535.502.304.001.30Iris-versicolorIris-versicolor
545.502.403.701.00Iris-versicolorIris-versicolor
555.502.403.801.10Iris-versicolorIris-versicolor
565.502.504.001.30Iris-versicolorIris-versicolor
575.502.604.401.20Iris-versicolorIris-versicolor
585.503.501.300.20Iris-setosaIris-setosa
595.504.201.400.20Iris-setosaIris-setosa
605.602.503.901.10Iris-versicolorIris-versicolor
615.602.704.201.30Iris-versicolorIris-versicolor
625.602.804.902.00Iris-virginicaIris-virginica
635.602.903.601.30Iris-versicolorIris-versicolor
645.603.004.101.30Iris-versicolorIris-versicolor
655.603.004.501.50Iris-versicolorIris-versicolor
665.702.505.002.00Iris-virginicaIris-virginica
675.702.603.501.00Iris-versicolorIris-versicolor
685.702.804.101.30Iris-versicolorIris-versicolor
695.702.804.501.30Iris-versicolorIris-versicolor
705.702.904.201.30Iris-versicolorIris-versicolor
715.703.004.201.20Iris-versicolorIris-versicolor
725.703.801.700.30Iris-setosaIris-setosa
735.704.401.500.40Iris-setosaIris-setosa
745.802.604.001.20Iris-versicolorIris-versicolor
755.802.703.901.20Iris-versicolorIris-versicolor
765.802.704.101.00Iris-versicolorIris-versicolor
775.802.705.101.90Iris-virginicaIris-virginica
785.802.705.101.90Iris-virginicaIris-virginica
795.802.805.102.40Iris-virginicaIris-virginica
805.804.001.200.20Iris-setosaIris-setosa
815.903.004.201.50Iris-versicolorIris-versicolor
825.903.005.101.80Iris-virginicaIris-virginica
835.903.204.801.80Iris-versicolorIris-virginica
846.002.204.001.00Iris-versicolorIris-versicolor
856.002.205.001.50Iris-virginicaIris-versicolor
866.002.705.101.60Iris-versicolorIris-virginica
876.002.904.501.50Iris-versicolorIris-versicolor
886.003.004.801.80Iris-virginicaIris-virginica
896.003.404.501.60Iris-versicolorIris-versicolor
906.102.605.601.40Iris-virginicaIris-virginica
916.102.804.001.30Iris-versicolorIris-versicolor
926.102.804.701.20Iris-versicolorIris-versicolor
936.102.904.701.40Iris-versicolorIris-versicolor
946.103.004.601.40Iris-versicolorIris-versicolor
956.103.004.901.80Iris-virginicaIris-virginica
966.202.204.501.50Iris-versicolorIris-versicolor
976.202.804.801.80Iris-virginicaIris-virginica
986.202.904.301.30Iris-versicolorIris-versicolor
996.203.405.402.30Iris-virginicaIris-virginica
1006.302.304.401.30Iris-versicolorIris-versicolor
Out[3]:
Rows: 1-100 of 150 | Columns: 6