Loading...

verticapy.machine_learning.vertica.neighbors.KNeighborsClassifier.predict_proba#

KNeighborsClassifier.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.4172690075988250.2755120126369730.307218979764202
23.34.55.67.8Iris-setosa0.4172690075988250.2755120126369730.307218979764202
33.34.55.67.8Iris-setosa0.4172690075988250.2755120126369730.307218979764202
43.34.55.67.8Iris-setosa0.4172690075988250.2755120126369730.307218979764202
53.34.55.67.8Iris-setosa0.4172690075988250.2755120126369730.307218979764202
63.34.55.67.8Iris-setosa0.4172690075988250.2755120126369730.307218979764202
73.34.55.67.8Iris-setosa0.4172690075988250.2755120126369730.307218979764202
83.34.55.67.8Iris-setosa0.4172690075988250.2755120126369730.307218979764202
93.34.55.67.8Iris-setosa0.4172690075988250.2755120126369730.307218979764202
103.34.55.67.8Iris-setosa0.4172690075988250.2755120126369730.307218979764202
114.34.79.61.8Iris-virginica0.20413468291770.226808591122360.569056725959939
124.34.79.61.8Iris-virginica0.20413468291770.226808591122360.569056725959939
134.34.79.61.8Iris-virginica0.20413468291770.226808591122360.569056725959939
144.34.79.61.8Iris-virginica0.20413468291770.226808591122360.569056725959939
154.34.79.61.8Iris-virginica0.20413468291770.226808591122360.569056725959939
164.34.79.61.8Iris-virginica0.20413468291770.226808591122360.569056725959939
174.83.41.90.2Iris-setosa0.3375160684812350.4474802339078830.215003697610882
184.93.11.50.1Iris-setosa0.3393718709173010.4423187584748990.218309370607801
195.03.31.40.2Iris-setosa0.3450702793477040.4373104735865960.2176192470657
205.03.51.30.3Iris-setosa0.3533463301954380.4289123915832820.21774127822128
215.13.81.50.3Iris-setosa0.3506502203798720.4313643829630140.217985396657114
225.13.81.90.4Iris-setosa0.3424326818067330.444831901521290.212735416671976
235.22.73.91.4Iris-versicolor0.1911138977707590.6730763891077690.135809713121472
245.24.11.50.1Iris-setosa0.3470482194191520.4282100223442370.224741758236611
255.72.84.11.3Iris-versicolor0.07196417151443580.8687686172421340.0592672112434307
265.74.41.50.4Iris-setosa0.3490502308056320.4271857790342380.22376399016013
275.82.64.01.2Iris-versicolor0.08798471096998480.8389904711293550.07302481790066
286.02.24.01.0Iris-versicolor0.1412283317493410.7335531651250630.125218503125596
296.02.25.01.5Iris-virginica0.1687968649335070.6386406850674790.192562449999014
306.03.44.51.6Iris-versicolor0.1658326930562160.6807076226675720.153459684276211
316.12.84.01.3Iris-versicolor0.08048375926167550.8519880545403940.0675281861979308
326.12.84.71.2Iris-versicolor0.1102221306418910.7706952748916090.1190825944665
336.13.04.61.4Iris-versicolor0.1094443691236820.7798130249683360.110742605907982
346.22.24.51.5Iris-versicolor0.143383492517360.7171310001902870.139485507292352
356.32.85.11.5Iris-virginica0.1651725055839420.6303805722851280.20444692213093
366.52.84.61.5Iris-versicolor0.1420116444546320.7114073702499230.146580985295445
376.53.05.82.2Iris-virginica0.2181011565660250.4344582907382270.347440552695748
386.62.94.61.3Iris-versicolor0.1469347583452330.696216908259360.156848333395407
396.83.05.52.1Iris-virginica0.2179057538576810.4790738045341020.303020441608217
406.93.15.42.1Iris-virginica0.2207200020589470.4840942960215120.295185701919541
417.23.05.81.6Iris-virginica0.2089398872440810.4559117564989250.335148356256994
427.23.26.01.8Iris-virginica0.2129874677554490.4192945447253390.367717987519212
437.42.86.11.9Iris-virginica0.2176574234180850.4177042423254080.364638334256507
447.63.06.62.1Iris-virginica0.2192232952573150.3667264641084280.414050240634257
457.72.86.72.0Iris-virginica0.2191384844186820.368551921852250.412309593729068
467.73.06.12.3Iris-virginica0.2328838466508410.3987270702761810.368389083072978
477.93.86.42.0Iris-virginica0.2290891298671120.3656120507117470.405298819421142
483.34.55.67.8Iris-setosa0.4172690075988250.2755120126369730.307218979764202
493.34.55.67.8Iris-setosa0.4172690075988250.2755120126369730.307218979764202
503.34.55.67.8Iris-setosa0.4172690075988250.2755120126369730.307218979764202
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.