Loading...

verticapy.machine_learning.vertica.tree.DecisionTreeRegressor.predict

DecisionTreeRegressor.predict(vdf: Annotated[str | vDataFrame, ''], X: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None, name: str | None = None, inplace: bool = True) → vDataFrame

Predicts 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 :py:class`vDataColumn`. If empty, a name is generated.

inplace: bool, optional

If set to True, the prediction is added to the :py:class`vDataFrame`.

Returns

vDataFrame

the input object.

Examples

We import verticapy:

import verticapy as vp

For this example, we will use the winequality dataset.

import verticapy.datasets as vpd

data = vpd.load_winequality()
123
fixed_acidity
Numeric(8)
123
volatile_acidity
Numeric(9)
123
citric_acid
Numeric(8)
123
residual_sugar
Numeric(9)
123
chlorides
Float(22)
123
free_sulfur_dioxide
Numeric(9)
123
total_sulfur_dioxide
Numeric(9)
123
density
Float(22)
123
pH
Numeric(8)
123
sulphates
Numeric(8)
123
alcohol
Float(22)
123
quality
Integer
123
good
Integer
Abc
color
Varchar(20)
13.90.2250.44.20.0329.0118.00.9893.570.3612.881white
24.70.3350.141.30.03669.0168.00.992123.470.4610.550white
34.70.4550.181.90.03633.0106.00.987463.210.8314.071white
44.70.7850.03.40.03623.0134.00.989813.530.9213.860white
54.90.3450.341.00.06832.0143.00.991383.240.410.150white
64.90.3450.341.00.06832.0143.00.991383.240.410.150white
74.90.420.02.10.04816.042.00.991543.710.7414.071red
85.00.270.41.20.07642.0124.00.992043.320.4710.160white
95.00.310.06.40.04643.0166.00.9943.30.639.960white
105.00.40.54.30.04629.080.00.99023.490.6613.660red
115.00.440.0418.60.03938.0128.00.99853.370.5710.260white
125.10.110.321.60.02812.090.00.990083.570.5212.260white
135.10.140.250.70.03915.089.00.99193.220.439.260white
145.10.1650.225.70.04742.0146.00.99343.180.559.960white
155.10.330.221.60.02718.089.00.98933.510.3812.571white
165.10.330.221.60.02718.089.00.98933.510.3812.571white
175.10.330.221.60.02718.089.00.98933.510.3812.571white
185.10.390.211.70.02715.072.00.98943.50.4512.560white
195.20.20.273.20.04716.093.00.992353.440.5310.171white
205.20.210.311.70.04817.061.00.989533.240.3712.071white
215.20.220.466.20.06641.0187.00.993623.190.429.7333333333333350white
225.20.310.22.40.02727.0117.00.988863.560.4513.071white
235.20.320.251.80.10313.050.00.99573.380.559.250red
245.20.340.376.20.03142.0133.00.990763.250.4112.560white
255.20.360.021.60.03124.0104.00.98963.440.3512.260white
265.20.3650.0813.50.04137.0142.00.9973.460.399.960white
275.20.480.041.60.05419.0106.00.99273.540.6212.271red
285.20.50.182.00.03623.0129.00.989493.360.7713.471white
295.30.160.391.00.02840.0101.00.991563.570.5910.660white
305.30.160.391.00.02840.0101.00.991563.570.5910.660white
315.30.1650.241.10.05125.0105.00.99253.320.479.150white
325.30.230.560.90.04146.0141.00.991193.160.629.750white
335.30.30.31.20.02925.093.00.987423.310.413.671white
345.30.330.31.20.04825.0119.00.990453.320.6211.360white
355.30.360.276.30.02840.0132.00.991863.370.411.660white
365.30.360.276.30.02840.0132.00.991863.370.411.660white
375.30.40.253.90.03145.0130.00.990723.310.5811.7571white
385.30.470.112.20.04816.089.00.991823.540.8813.671red
395.30.470.112.20.04816.089.00.991823.540.8813.566666666666771red
405.30.7150.191.50.1617.062.00.993953.620.6111.050red
415.40.220.291.20.04569.0152.00.991783.760.6311.071white
425.40.5950.12.80.04226.080.00.99323.360.389.350white
435.40.740.091.70.08916.026.00.994023.670.5611.660red
445.50.120.331.00.03823.0131.00.991643.250.459.850white
455.50.120.331.00.03823.0131.00.991643.250.459.850white
465.50.140.274.60.02922.0104.00.99493.340.449.050white
475.50.140.274.60.02922.0104.00.99493.340.449.050white
485.50.160.311.20.02631.068.00.98983.330.4411.6560white
495.50.160.311.20.02631.068.00.98983.330.4411.633333333333360white
505.50.180.225.50.03710.086.00.991563.460.4412.250white
515.50.240.451.70.04622.0113.00.992243.220.4810.050white
525.50.290.31.10.02220.0110.00.988693.340.3812.871white
535.50.310.293.00.02716.0102.00.990673.230.5611.260white
545.50.320.454.90.02825.0191.00.99223.510.4911.571white
555.50.350.351.10.04514.0167.00.9923.340.689.960white
565.50.3750.381.70.03617.098.00.991423.290.3910.560white
575.60.150.265.550.05151.0139.00.993363.470.511.060white
585.60.150.315.30.0388.079.00.99233.30.3910.560white
595.60.160.271.40.04453.0168.00.99183.280.3710.160white
605.60.1750.290.80.04320.067.00.991123.280.489.960white
615.60.1850.197.10.04836.0110.00.994383.260.419.560white
625.60.1850.197.10.04836.0110.00.994383.260.419.560white
635.60.220.321.20.02429.097.00.988233.20.4613.0571white
645.60.260.181.40.03418.0135.00.991743.320.3510.260white
655.60.260.265.70.03112.080.00.99233.250.3810.850white
665.60.260.511.40.02925.093.00.994283.230.4910.560white
675.60.280.284.20.04452.0158.00.9923.350.4410.771white
685.60.30.16.40.04334.0142.00.993823.140.489.850white
695.60.350.145.00.04648.0198.00.99373.30.7110.350white
705.60.490.134.50.03917.0116.00.99073.420.913.771white
715.60.490.134.50.03917.0116.00.99073.420.913.771white
725.60.660.02.20.0873.011.00.993783.710.6312.871red
735.60.660.02.20.0873.011.00.993783.710.6312.871red
745.70.150.4711.40.03549.0128.00.994563.030.3410.581white
755.70.180.262.20.02321.095.00.98933.070.5412.360white
765.70.180.361.20.0469.071.00.991993.70.6810.971white
775.70.20.32.50.04638.0125.00.992763.340.59.960white
785.70.210.320.90.03838.0121.00.990743.240.4610.660white
795.70.210.374.50.0458.0140.00.993323.290.6210.660white
805.70.220.216.00.04441.0113.00.998623.220.468.960white
815.70.220.216.00.04441.0113.00.998623.220.468.960white
825.70.220.216.00.04441.0113.00.998623.220.468.960white
835.70.220.216.00.04441.0113.00.998623.220.468.960white
845.70.220.216.00.04441.0113.00.998623.220.468.960white
855.70.220.293.50.0427.0146.00.989993.170.3612.160white
865.70.230.289.650.02526.0121.00.99253.280.3811.360white
875.70.250.2612.50.04952.5106.00.996913.080.459.460white
885.70.250.2612.50.04952.5120.00.996913.080.459.460white
895.70.250.2711.50.0424.0120.00.994113.330.3110.860white
905.70.260.2417.80.05923.0124.00.997733.30.510.150white
915.70.260.2417.80.05923.0124.00.997733.30.510.150white
925.70.260.2417.80.05923.0124.00.997733.30.510.150white
935.70.270.321.20.04620.0155.00.99343.80.4110.260white
945.70.280.2417.50.04460.0167.00.99893.310.449.450white
955.70.320.181.40.02926.0104.00.99063.440.3711.060white
965.70.320.384.750.03323.094.00.9913.420.4211.871white
975.70.360.344.20.02621.077.00.99073.410.4511.960white
985.80.140.156.10.04227.0123.00.993623.060.69.960white
995.80.150.321.20.03714.0119.00.991373.190.510.260white
1005.80.170.341.80.04596.0170.00.990353.380.911.881white
Rows: 1-100 | Columns: 14

Divide your dataset into training and testing subsets.

data = vpd.load_winequality()
train, test = data.train_test_split(test_size = 0.2)

Let’s import the model:

from verticapy.machine_learning.vertica import LinearRegression

Then we can create the model:

model = LinearRegression(
    tol = 1e-6,
    max_iter = 100,
    solver = 'newton',
    fit_intercept = True,
)

We can now fit the model:

model.fit(
    train,
    [
        "fixed_acidity",
        "volatile_acidity",
        "citric_acid",
        "residual_sugar",
        "chlorides",
        "density",
    ],
    "quality",
    test,
)



=======
details
=======
   predictor    |coefficient|std_err | t_value |p_value 
----------------+-----------+--------+---------+--------
   Intercept    | 149.80642 | 6.83430|21.91978 | 0.00000
 fixed_acidity  |  0.14534  | 0.01249|11.63893 | 0.00000
volatile_acidity| -0.73376  | 0.08752|-8.38347 | 0.00000
  citric_acid   | -0.16034  | 0.09518|-1.68460 | 0.09213
 residual_sugar |  0.04545  | 0.00385|11.81257 | 0.00000
   chlorides    |  0.00542  | 0.37950| 0.01428 | 0.98861
    density     |-145.75416 | 6.95208|-20.96554| 0.00000


==============
regularization
==============
type| lambda 
----+--------
none| 1.00000


===========
call_string
===========
linear_reg('"public"."_verticapy_tmp_linearregression_v_mldb_c0547b72979c11efa8720242ac120002_"', '"public"."_verticapy_tmp_view_v_mldb_c0a0d71a979c11efa8720242ac120002_"', '"quality"', '"fixed_acidity", "volatile_acidity", "citric_acid", "residual_sugar", "chlorides", "density"'
USING PARAMETERS optimizer='newton', epsilon=1e-06, max_iterations=100, regularization='none', lambda=1, alpha=0.5, fit_intercept=true)

===============
Additional Info
===============
       Name       |Value
------------------+-----
 iteration_count  |  1  
rejected_row_count|  0  
accepted_row_count|5193 

Prediction is straight-forward:

model.predict(
    test,
    [
        "fixed_acidity",
        "volatile_acidity",
        "citric_acid",
        "residual_sugar",
        "chlorides",
        "density",
    ],
    "prediction",
)
123
fixed_acidity
Numeric(8)
123
volatile_acidity
Numeric(9)
123
citric_acid
Numeric(8)
123
residual_sugar
Numeric(9)
123
chlorides
Float(22)
123
free_sulfur_dioxide
Numeric(9)
123
total_sulfur_dioxide
Numeric(9)
123
density
Float(22)
123
pH
Numeric(8)
123
sulphates
Numeric(8)
123
alcohol
Float(22)
123
quality
Integer
123
good
Integer
Abc
color
Varchar(20)
123
prediction
Float(22)
15.10.140.250.70.03915.089.00.99193.220.439.260white5.86329239646642
25.10.330.221.60.02718.089.00.98933.510.3812.571white6.1484843454582
35.20.310.22.40.02727.0117.00.988863.560.4513.071white6.28138792486973
45.20.320.251.80.10313.050.00.99573.380.559.250red5.24221955837967
55.20.340.376.20.03142.0133.00.990763.250.4112.560white6.12789772149205
65.30.160.391.00.02840.0101.00.991563.570.5910.660white5.91836708324547
75.50.160.311.20.02631.068.00.98983.330.4411.6560white6.22586695414424
85.50.160.311.20.02631.068.00.98983.330.4411.633333333333360white6.22586695414424
95.50.3750.381.70.03617.098.00.991423.290.3910.560white5.84353944111143
105.60.150.265.550.05151.0139.00.993363.470.511.060white5.93469230809893
115.60.260.265.70.03112.080.00.99233.250.3810.850white6.01518634254788
125.60.260.511.40.02925.093.00.994283.230.4910.560white5.9471381812331
135.60.350.145.00.04648.0198.00.99373.30.7110.350white5.73260241911947
145.70.150.4711.40.03549.0128.00.994563.030.3410.581white6.00641707985341
155.70.180.262.20.02321.095.00.98933.070.5412.360white6.36658187013205
165.70.220.216.00.04441.0113.00.998623.220.468.960white5.61568022587085
175.70.220.216.00.04441.0113.00.998623.220.468.960white5.61568022587085
185.70.220.216.00.04441.0113.00.998623.220.468.960white5.61568022587085
195.70.250.2612.50.04952.5120.00.996913.080.459.460white5.67425557779697
205.80.170.341.80.04596.0170.00.990353.380.911.881white6.20452513845089
215.80.220.31.10.04736.0131.00.9923.260.4510.450white5.90195549836881
225.80.320.384.750.03323.094.00.9913.420.4211.871white6.1273053354185
235.80.320.384.750.03323.094.00.9913.420.4211.871white6.1273053354185
245.80.360.380.90.0373.075.00.99043.280.3411.440white6.01046511465628
255.90.140.254.50.02734.0140.00.99343.490.5110.860white5.93355639291735
265.90.190.370.80.0273.021.00.98973.090.3110.850white6.24877077286391
275.90.210.237.90.03322.0130.00.99443.380.5910.960white5.89419182777584
285.90.230.243.80.03861.0152.00.991393.310.511.371white6.13033510016896
295.90.240.342.00.03740.0108.00.989483.190.512.360white6.30354720671801
305.90.330.328.10.0389.034.00.99113.220.3612.771white6.28181470981406
315.90.460.142.70.04227.0160.00.99313.460.5110.671white5.6783962817974
326.00.260.341.30.0466.029.00.99243.290.6310.450white5.84604053629431
336.00.270.191.70.0224.0110.00.98983.320.4712.671white6.25975191720616
346.00.280.2212.150.04842.0163.00.99573.20.4610.150white5.86270835879006
356.00.330.389.70.0429.0124.00.99543.470.4811.060white5.7327081031043
366.00.370.321.00.05331.0218.50.99243.290.729.860white5.75493793586597
376.00.390.262.70.03839.0187.00.993253.410.510.860white5.70316757731666
386.00.410.211.90.0529.0122.00.99283.420.5210.560white5.72580760091128
396.10.1050.311.30.03755.0145.00.99123.410.4111.171white6.15397358751454
406.10.220.233.10.05215.0104.00.99483.140.428.750white5.6395858065388
416.10.220.41.850.03125.0111.00.989663.030.311.871white6.3045841530633
426.10.220.491.50.05118.087.00.99283.30.469.650white5.81668804921736
436.10.280.3512.80.04863.0229.00.99753.080.48.950white5.62357961101279
446.10.30.32.10.03150.0163.00.98953.390.4312.771white6.29659917758786
456.10.30.471.40.04950.0187.00.99273.190.459.550white5.77121397925359
466.10.370.364.70.03536.0116.00.9913.310.6212.660white6.13516335631044
476.10.450.270.80.03913.082.00.99273.230.329.550white5.6658964289951
486.150.210.373.20.02120.080.00.990763.390.4712.050white6.22496597395624
496.20.150.271.40.04151.0117.00.99093.280.3811.260white6.19019392923198
506.20.180.381.50.02836.0117.00.9933.470.549.760white5.84893401506523
516.20.220.312.40.054108.0152.00.997283.10.479.560white5.70407623872066
526.20.320.322.20.03615.070.00.98993.160.4812.760white6.23952066756999
536.20.340.287.50.03440.0197.00.994853.140.69.750white5.75062451873566
546.20.340.311.10.04728.0237.00.99813.180.498.750white5.43738976789899
556.20.570.12.10.0484.011.00.994483.440.7610.860red5.4193214861601
566.20.660.481.20.02929.075.00.98923.330.3912.881white6.02093213217671
576.30.170.235.70.04844.0147.00.993823.080.5410.050white5.96631590151162
586.30.170.324.20.0437.0117.00.991823.240.4311.360white6.17518251925387
596.30.230.215.10.03529.0142.00.99423.360.3310.171white5.8427728692786
606.30.280.229.50.0430.0111.00.993383.050.3110.840white6.12398567470078
616.30.290.2314.20.03724.099.00.995283.080.3810.660white6.0516878206995
626.30.290.293.30.03732.0140.00.98953.170.3612.871white6.38917406787388
636.30.30.918.20.03450.0199.00.993943.390.4911.760white5.85794230996922
646.30.390.355.90.0482.5260.00.99413.120.6610.150white5.75388207049485
656.30.40.3210.60.04938.0209.00.99813.470.599.360white5.38197909605603
666.30.550.4513.00.04733.0182.00.99743.20.469.260white5.46215616169306
676.30.760.02.90.07226.052.00.993793.510.611.560red5.44753091422021
686.40.160.328.750.03838.0118.00.994493.190.4110.750white6.01465480789375
696.40.170.279.90.04726.0101.00.995963.340.59.960white5.85338629041803
706.40.170.341.50.09142.0135.00.99383.250.499.671white5.77549043642605
716.40.180.484.00.18664.0150.00.99453.060.49.350white5.75780504887268
726.40.210.447.40.04547.0182.00.99573.240.469.150white5.72105033944086
736.40.220.389.10.04435.0127.00.993262.970.311.071white6.15622466115076
746.40.230.268.10.05447.0181.00.99543.120.499.450white5.810822938679
756.40.240.312.80.03841.0114.00.991553.370.6611.771white6.11567571920855
766.40.280.561.70.15649.0106.00.993543.10.379.260white5.70683921663462
776.40.310.46.20.0446.0169.00.99533.150.469.360white5.65782813415692
786.40.320.267.90.0553.0180.00.995143.140.59.650white5.77356976456264
796.40.370.125.90.0566.091.00.995363.060.468.440white5.63640551889148
806.40.40.193.20.03328.0124.00.99043.220.5412.771white6.20328291729089
816.40.440.262.00.05420.0180.00.99523.580.5710.050white5.4086682538011
826.50.210.372.50.04870.0138.00.99173.330.7511.471white6.1071592574994
836.50.220.458.00.05352.0196.00.99593.230.489.160white5.72480252276233
846.50.230.2517.30.04615.0110.00.998283.150.429.260white5.82524019388066
856.50.250.21.40.02429.0101.00.99163.240.5410.860white6.06952225127438
866.50.280.2820.40.04140.0144.01.00023.140.388.750white5.64474687267415
876.50.280.292.70.03826.0107.00.99123.320.4111.671white6.15053506763567
886.50.30.397.80.03861.0219.00.99593.190.59.450white5.66655167085841
896.50.320.238.50.05120.0138.00.99433.030.4210.750white5.94261956011272
906.50.360.321.10.03113.066.00.99163.10.4610.650white5.95597205944895
916.50.410.224.80.05249.0142.00.99463.140.629.250white5.66631642985902
926.60.160.361.10.03127.093.00.988843.230.3413.281white6.5131258537748
936.60.210.392.30.04131.0102.00.992213.220.5810.971white6.03502444235178
946.60.220.2317.30.04737.0118.00.999063.080.468.860white5.73663535453863
956.60.220.2317.30.04737.0118.00.999063.080.468.860white5.73663535453863
966.60.220.581.10.13352.0136.00.99323.10.39.150white5.7988899403002
976.60.230.314.90.05133.0118.00.998353.040.549.060white5.71251265081742
986.60.230.314.90.05133.0118.00.998353.040.549.060white5.71251265081742
996.60.230.314.90.05133.0118.00.998353.040.549.060white5.71251265081742
1006.60.240.2715.80.03546.0188.00.99823.240.519.250white5.77266231423891
Rows: 1-100 | Columns: 15

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.