Loading...

verticapy.machine_learning.vertica.cluster.NearestCentroid.predict_proba#

NearestCentroid.predict_proba(vdf: str | vDataFrame, X: str | list[str] | None = None, name: str | None = None, pos_label: bool | float | str | timedelta | datetime | None = None, inplace: bool = True) vDataFrame#

Returns the model’s probabilities using the input relation.

Parameters#

vdf: SQLRelation

Object used to run the prediction. You can also specify a customized relation, but you must enclose it with an alias. For example, (SELECT 1) x is valid, whereas (SELECT 1) and “SELECT 1” are invalid.

X: SQLColumns, optional

List of the columns used to deploy the models. If empty, the model predictors are used.

name: str, optional

Name of the added vDataColumn. If empty, a name is generated.

pos_label: PythonScalar, optional

Class label. For binary classification, this can be either 1 or 0.

inplace: bool, optional

If set to True, the prediction is added to the vDataFrame.

Returns#

vDataFrame

the input object.

Examples#

For this example, we will use the Iris dataset.

import verticapy.datasets as vpd

data = vpd.load_iris()

train, test = data.train_test_split(test_size = 0.2)
123
SepalLengthCm
Numeric(7)
123
SepalWidthCm
Numeric(7)
123
PetalLengthCm
Numeric(7)
123
PetalWidthCm
Numeric(7)
Abc
Species
Varchar(30)
13.34.55.67.8Iris-setosa
23.34.55.67.8Iris-setosa
33.34.55.67.8Iris-setosa
43.34.55.67.8Iris-setosa
53.34.55.67.8Iris-setosa
63.34.55.67.8Iris-setosa
73.34.55.67.8Iris-setosa
83.34.55.67.8Iris-setosa
93.34.55.67.8Iris-setosa
103.34.55.67.8Iris-setosa
113.34.55.67.8Iris-setosa
123.34.55.67.8Iris-setosa
133.34.55.67.8Iris-setosa
143.34.55.67.8Iris-setosa
153.34.55.67.8Iris-setosa
163.34.55.67.8Iris-setosa
173.34.55.67.8Iris-setosa
183.34.55.67.8Iris-setosa
193.34.55.67.8Iris-setosa
203.34.55.67.8Iris-setosa
213.34.55.67.8Iris-setosa
223.34.55.67.8Iris-setosa
233.34.55.67.8Iris-setosa
243.34.55.67.8Iris-setosa
253.34.55.67.8Iris-setosa
263.34.55.67.8Iris-setosa
273.34.55.67.8Iris-setosa
283.34.55.67.8Iris-setosa
293.34.55.67.8Iris-setosa
303.34.55.67.8Iris-setosa
313.34.55.67.8Iris-setosa
323.34.55.67.8Iris-setosa
333.34.55.67.8Iris-setosa
343.34.55.67.8Iris-setosa
353.34.55.67.8Iris-setosa
363.34.55.67.8Iris-setosa
373.34.55.67.8Iris-setosa
383.34.55.67.8Iris-setosa
393.34.55.67.8Iris-setosa
403.34.55.67.8Iris-setosa
413.34.55.67.8Iris-setosa
423.34.55.67.8Iris-setosa
434.33.01.10.1Iris-setosa
444.34.79.61.8Iris-virginica
454.34.79.61.8Iris-virginica
464.34.79.61.8Iris-virginica
474.34.79.61.8Iris-virginica
484.34.79.61.8Iris-virginica
494.34.79.61.8Iris-virginica
504.34.79.61.8Iris-virginica
514.34.79.61.8Iris-virginica
524.34.79.61.8Iris-virginica
534.34.79.61.8Iris-virginica
544.34.79.61.8Iris-virginica
554.34.79.61.8Iris-virginica
564.34.79.61.8Iris-virginica
574.34.79.61.8Iris-virginica
584.34.79.61.8Iris-virginica
594.34.79.61.8Iris-virginica
604.34.79.61.8Iris-virginica
614.34.79.61.8Iris-virginica
624.34.79.61.8Iris-virginica
634.34.79.61.8Iris-virginica
644.34.79.61.8Iris-virginica
654.34.79.61.8Iris-virginica
664.34.79.61.8Iris-virginica
674.34.79.61.8Iris-virginica
684.34.79.61.8Iris-virginica
694.34.79.61.8Iris-virginica
704.34.79.61.8Iris-virginica
714.34.79.61.8Iris-virginica
724.34.79.61.8Iris-virginica
734.34.79.61.8Iris-virginica
744.34.79.61.8Iris-virginica
754.34.79.61.8Iris-virginica
764.34.79.61.8Iris-virginica
774.34.79.61.8Iris-virginica
784.34.79.61.8Iris-virginica
794.34.79.61.8Iris-virginica
804.34.79.61.8Iris-virginica
814.34.79.61.8Iris-virginica
824.34.79.61.8Iris-virginica
834.34.79.61.8Iris-virginica
844.34.79.61.8Iris-virginica
854.34.79.61.8Iris-virginica
864.42.91.40.2Iris-setosa
874.43.01.30.2Iris-setosa
884.43.21.30.2Iris-setosa
894.52.31.30.3Iris-setosa
904.63.11.50.2Iris-setosa
914.63.21.40.2Iris-setosa
924.63.41.40.3Iris-setosa
934.63.61.00.2Iris-setosa
944.73.21.30.2Iris-setosa
954.73.21.60.2Iris-setosa
964.83.01.40.1Iris-setosa
974.83.01.40.3Iris-setosa
984.83.11.60.2Iris-setosa
994.83.41.60.2Iris-setosa
1004.83.41.90.2Iris-setosa
Rows: 1-100 | Columns: 5

Let’s import the model:

from verticapy.machine_learning.vertica import NearestCentroid

Then we can create the model:

model = NearestCentroid(p = 2)

We can now fit the model:

model.fit(
    train,
    [
        "SepalLengthCm",
        "SepalWidthCm",
        "PetalLengthCm",
        "PetalWidthCm",
    ],
    "Species",
    test,
)

We can then get the prediction:

model.predict_proba(test, name = "prediction"
123
SepalLengthCm
Numeric(7)
123
SepalWidthCm
Numeric(7)
123
PetalLengthCm
Numeric(7)
123
PetalWidthCm
Numeric(7)
Abc
Species
Varchar(30)
123
prediction_irissetosa
Float(22)
123
prediction_irisversicolor
Float(22)
123
prediction_irisvirginica
Float(22)
13.34.55.67.8Iris-setosa0.4246096458439560.2723435749038730.30304677925217
23.34.55.67.8Iris-setosa0.4246096458439560.2723435749038730.30304677925217
33.34.55.67.8Iris-setosa0.4246096458439560.2723435749038730.30304677925217
43.34.55.67.8Iris-setosa0.4246096458439560.2723435749038730.30304677925217
53.34.55.67.8Iris-setosa0.4246096458439560.2723435749038730.30304677925217
63.34.55.67.8Iris-setosa0.4246096458439560.2723435749038730.30304677925217
73.34.55.67.8Iris-setosa0.4246096458439560.2723435749038730.30304677925217
83.34.55.67.8Iris-setosa0.4246096458439560.2723435749038730.30304677925217
93.34.55.67.8Iris-setosa0.4246096458439560.2723435749038730.30304677925217
103.34.55.67.8Iris-setosa0.4246096458439560.2723435749038730.30304677925217
114.33.01.10.1Iris-setosa0.3557786261782960.4114154087897830.232805965031921
124.34.79.61.8Iris-virginica0.2155321491075330.2393957736327460.545072077259721
134.34.79.61.8Iris-virginica0.2155321491075330.2393957736327460.545072077259721
144.34.79.61.8Iris-virginica0.2155321491075330.2393957736327460.545072077259721
154.34.79.61.8Iris-virginica0.2155321491075330.2393957736327460.545072077259721
164.34.79.61.8Iris-virginica0.2155321491075330.2393957736327460.545072077259721
174.34.79.61.8Iris-virginica0.2155321491075330.2393957736327460.545072077259721
184.34.79.61.8Iris-virginica0.2155321491075330.2393957736327460.545072077259721
194.34.79.61.8Iris-virginica0.2155321491075330.2393957736327460.545072077259721
204.52.31.30.3Iris-setosa0.3449522712318250.4268330615985440.228214667169631
214.63.61.00.2Iris-setosa0.3613020478152980.4068319586983830.231865993486319
225.02.33.31.0Iris-versicolor0.2568059374796630.5563741531262650.186819909394073
235.03.01.60.2Iris-setosa0.3307461582757630.4456725270444440.223581314679793
245.12.53.01.1Iris-versicolor0.275462452912160.5396831920539030.184854355033937
255.13.51.40.2Iris-setosa0.3409131200905560.432139520004780.226947359904664
265.13.81.60.2Iris-setosa0.34037573752870.4318837791796720.227740483291628
275.13.81.90.4Iris-setosa0.3378779186664580.4402712390949290.221850842238613
285.22.73.91.4Iris-versicolor0.2009918013579190.6454931658538170.153515032788264
295.23.51.50.2Iris-setosa0.3358668756380060.4382199860083470.225913138353647
305.62.53.91.1Iris-versicolor0.1451462806551120.7291794075318570.125674311813031
315.62.74.21.3Iris-versicolor0.1046480758609410.8002607412368210.0950911829022381
325.62.93.61.3Iris-versicolor0.1845022453560860.6770179958038620.138479758840052
335.72.94.21.3Iris-versicolor0.08930218304350140.8289954911885730.0817023257679252
345.82.85.12.4Iris-virginica0.2337565090755430.5078264076544420.258417083270014
355.84.01.20.2Iris-setosa0.3378204347539380.4294518793435790.232727685902483
365.93.24.81.8Iris-versicolor0.1710088167614640.6421845892983340.186806593940202
376.32.85.11.5Iris-virginica0.1506248401983240.6459583339159940.203416825885682
386.33.36.02.5Iris-virginica0.2157380043522720.3643432413827160.419918754265012
396.42.75.31.9Iris-virginica0.1845438403201510.556448052042720.25900810763713
406.53.05.51.8Iris-virginica0.1878513929235490.5113810406665080.300767566409943
416.62.94.61.3Iris-versicolor0.1298292719389380.7202189111937880.149951816867274
426.72.55.81.8Iris-virginica0.1937152985385930.4720980416031560.334186659858251
436.73.05.01.7Iris-versicolor0.1738427262649710.6014933152388160.224663958496213
446.83.25.92.3Iris-virginica0.2118595189175420.4038925788310040.384247902251454
457.23.66.12.5Iris-virginica0.223167023869030.3647107469749640.412122229156007
467.93.86.42.0Iris-virginica0.2193593281150320.3611460897813310.419494582103637
473.34.55.67.8Iris-setosa0.4246096458439560.2723435749038730.30304677925217
484.34.79.61.8Iris-virginica0.2155321491075330.2393957736327460.545072077259721
493.34.55.67.8Iris-setosa0.4246096458439560.2723435749038730.30304677925217
504.34.79.61.8Iris-virginica0.2155321491075330.2393957736327460.545072077259721
Rows: 1-50 | Columns: 8

Important

For this example, a specific model is utilized, and it may not correspond exactly to the model you are working with. To see a comprehensive example specific to your class of interest, please refer to that particular class.