Loading...

vastorbit.machine_learning.vast.linear_model.LinearRegression.predict

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

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`VastColumn`. If empty, a name is generated.

  • inplace (bool, optional) – If set to True, the prediction is added to the :py:class`VastFrame`.

Returns:

the input object.

Return type:

VastFrame

Examples

We import vastorbit:

import vastorbit as vo

For this example, we will use the winequality dataset.

import vastorbit.datasets as vod

data = vod.load_winequality()
123
fixed_acidity
Decimal(6, 3)
123
volatile_acidity
Decimal(7, 4)
123
citric_acid
Decimal(6, 3)
123
residual_sugar
Decimal(7, 3)
123
chlorides
Double
123
free_sulfur_dioxide
Decimal(7, 2)
123
total_sulfur_dioxide
Decimal(7, 2)
123
density
Double
123
ph
Decimal(6, 3)
123
sulphates
Decimal(6, 3)
123
alcohol
Double
123
quality
Integer
123
good
Integer
Abc
color
Varchar(20)
16.30.670.4812.60.05257.0222.00.99793.170.529.360white
27.40.40.295.40.04431.0122.00.9943.30.511.181white
37.10.260.312.20.04429.0128.00.99373.340.6410.981white
49.00.310.486.60.04311.073.00.99382.90.3811.650white
56.30.390.246.90.0699.0117.00.99423.150.3510.240white
68.20.220.366.80.03412.090.00.99443.010.3810.581white
77.10.190.283.60.03316.078.00.9932.910.7811.460white
87.30.250.3613.10.0535.0200.00.99863.040.468.971white
97.90.20.341.20.0429.0118.00.99323.140.4110.660white
107.10.260.325.90.03739.097.00.99343.310.411.660white
117.00.20.345.70.03532.083.00.99283.190.4611.560white
126.90.30.334.10.03526.0155.00.99253.250.7912.381white
138.10.290.497.10.04222.0124.00.99443.140.4110.860white
145.80.170.31.40.03755.0130.00.99093.290.3811.360white
155.90.4150.020.80.03822.063.00.99323.360.369.350white
166.60.230.261.30.04516.0128.00.99343.360.610.060white
178.60.550.3515.550.05735.5366.51.00013.040.6311.030white
186.90.350.741.00.04418.0132.00.9923.130.5510.250white
197.60.140.741.60.0427.0103.00.99163.070.410.871white
209.20.280.4911.80.04229.0137.00.9983.10.3410.140white
216.20.180.494.50.04717.090.00.99193.270.3711.660white
225.30.1650.241.10.05125.0105.00.99253.320.479.150white
239.80.250.7410.00.05636.0225.00.99773.060.4310.040white
248.10.290.497.10.04222.0124.00.99443.140.4110.860white
256.80.220.490.90.05226.0128.00.9913.250.3511.460white
267.20.220.491.00.04534.0140.00.993.050.3412.760white
277.40.250.491.10.04235.0156.00.99173.130.5511.350white
288.20.180.491.10.03328.081.00.99233.00.6810.471white
296.10.220.491.50.05118.087.00.99283.30.469.650white
307.00.390.241.00.0488.0119.00.99233.00.3110.140white
316.10.220.491.50.05118.087.00.99283.30.469.650white
326.50.360.492.90.0316.094.00.99023.10.4912.171white
337.10.290.491.20.03132.099.00.98933.070.3312.260white
347.40.250.491.10.04235.0156.00.99173.130.5511.350white
356.90.230.2414.20.05319.094.00.99823.170.59.650white
368.50.560.7417.850.05151.0243.01.00052.990.79.250white
378.20.180.491.10.03328.081.00.99233.00.6810.471white
386.30.230.497.10.0567.0210.00.99513.230.349.550white
396.10.250.497.60.05267.0226.00.99563.160.478.950white
407.20.260.7413.60.0556.0162.00.9983.030.448.850white
417.20.310.241.40.05717.0117.00.99283.160.3510.550white
428.00.250.491.20.06127.0117.00.99383.080.349.450white
437.00.180.495.30.0434.0125.00.99143.240.412.260white
447.80.430.4913.00.03337.0158.00.99553.140.3511.360white
458.30.20.744.450.04433.0130.00.99243.250.4212.260white
466.30.270.491.20.06335.092.00.99113.380.4212.260white
477.40.160.491.20.05518.0150.00.99173.230.4711.260white
487.40.160.491.20.05518.0150.00.99173.230.4711.260white
496.90.190.496.60.03649.0172.00.99323.20.2711.560white
507.80.430.4913.00.03337.0158.00.99553.140.3511.360white
517.20.40.491.10.04811.0138.00.99293.010.429.350white
527.80.430.4913.00.03337.0158.00.99553.140.3511.360white
537.60.520.4914.00.03437.0156.00.99583.140.3811.871white
548.30.210.4919.80.05450.0231.01.00122.990.549.250white
556.90.340.7411.20.06944.0150.00.99683.00.819.250white
566.30.270.491.20.06335.092.00.99113.380.4212.260white
578.30.20.744.450.04433.0130.00.99243.250.4212.260white
587.10.220.742.70.04442.0144.00.9913.310.4112.260white
597.90.110.494.50.04827.0133.00.99463.240.4210.660white
608.50.170.743.60.0529.0128.00.99283.280.412.460white
616.40.1450.495.40.04854.0164.00.99463.560.4410.860white
627.40.160.491.20.05518.0150.00.99173.230.4711.260white
638.30.190.491.20.05111.0137.00.99183.060.4611.060white
648.00.440.499.10.03146.0151.00.99263.160.2712.781white
657.00.20.740.80.04419.0163.00.99313.460.5310.250white
666.90.190.496.60.03649.0172.00.99323.20.2711.560white
677.10.250.493.00.0330.096.00.99033.130.3912.371white
686.50.240.241.60.04615.060.00.99283.190.399.850white
697.20.40.491.10.04811.0138.00.99293.010.429.350white
707.60.520.4914.00.03437.0156.00.99583.140.3811.871white
717.80.430.4913.00.03337.0158.00.99553.140.3511.360white
727.80.210.491.350.0526.048.00.99113.150.2811.450white
737.00.20.495.90.03839.0128.00.99383.210.4810.860white
746.90.250.243.60.05713.085.00.99422.990.489.540white
757.20.080.491.30.0518.0148.00.99453.460.4410.260white
767.10.850.498.70.02840.0184.00.99623.220.3610.750white
777.60.510.241.20.0410.0104.00.9923.050.2910.860white
787.90.220.244.60.04439.0159.00.99272.990.2811.560white
797.70.160.492.00.05620.0124.00.99483.320.4910.760white
807.20.080.491.30.0518.0148.00.99453.460.4410.260white
816.60.250.241.70.04826.0124.00.99423.370.610.160white
826.70.160.492.40.04657.0187.00.99523.620.8110.460white
836.90.250.243.60.05713.085.00.99422.990.489.540white
847.50.320.244.60.0538.0134.00.99583.140.59.130white
857.40.280.491.50.03420.0126.00.99182.980.3910.660white
866.20.150.490.90.03317.051.00.99323.30.79.460white
876.70.250.7419.40.05444.0169.01.00043.510.459.860white
886.50.260.7413.30.04468.0224.00.99723.180.549.560white
897.90.160.7417.850.03752.0187.00.99982.990.419.350white
905.60.1850.491.10.0328.0117.00.99183.550.4510.360white
917.50.20.491.30.0318.097.00.99183.060.6211.150white
928.00.30.499.40.04647.0188.00.99643.140.4810.050white
938.00.340.499.00.03339.0180.00.99363.130.3812.381white
947.70.350.498.650.03342.0186.00.99313.140.3812.481white
957.60.290.499.60.0345.0197.00.99383.130.3812.371white
966.70.620.241.10.0396.062.00.99343.410.3210.450white
976.80.270.491.20.04435.0126.00.993.130.4812.171white
987.70.270.491.80.04123.086.00.99143.160.4212.560white
996.70.510.242.10.04314.0155.00.99043.220.613.060white
1007.40.190.499.30.0326.0132.00.9942.990.3211.071white
Rows: 1-100 | Columns: 14

Divide your dataset into training and testing subsets.

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

Let’s import the model:

from vastorbit.machine_learning.vast import LinearRegression

Then we can create the model:

model = LinearRegression(
    tol = 1e-6,
    fit_intercept = True,
)

We can now fit the model:

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

Prediction is straight-forward:

model.predict(
    test,
    [
        "fixed_acidity",
        "volatile_acidity",
        "citric_acid",
        "residual_sugar",
        "chlorides",
        "density",
    ],
    "prediction",
)
123
fixed_acidity
Decimal(6, 3)
123
volatile_acidity
Decimal(7, 4)
123
citric_acid
Decimal(6, 3)
123
residual_sugar
Decimal(7, 3)
123
chlorides
Double
123
free_sulfur_dioxide
Decimal(7, 2)
123
total_sulfur_dioxide
Decimal(7, 2)
123
density
Double
123
ph
Decimal(6, 3)
123
sulphates
Decimal(6, 3)
123
alcohol
Double
123
quality
Integer
123
good
Integer
Abc
color
Varchar(20)
123
seedrand
Decimal(26, 6)
123
prediction
Double
17.10.270.3118.20.04655.0252.01.03.070.568.750white0.075.627027081137584
26.80.270.121.30.0487.0168.00.9923.180.4110.050white0.046.057549067663302
36.90.490.241.20.04913.0125.00.99323.170.519.450white0.135.712338038706378
46.30.140.391.20.04426.0116.00.9923.260.5310.360white0.16.03172262072917
57.40.210.271.20.04127.099.00.99273.190.339.860white0.176.0566398818722575
67.00.210.288.60.04537.0221.00.99543.250.5410.460white0.155.921392425670604
76.90.230.388.30.04747.0162.00.99543.340.5210.571white0.065.862833192459988
87.00.210.288.60.04537.0221.00.99543.250.5410.460white0.015.921392425670604
96.70.220.371.60.02824.0102.00.99133.290.5911.671white0.126.149577466890662
106.00.270.271.60.04632.0113.00.99243.410.5110.571white0.175.872313841110241
117.00.140.329.00.03954.0141.00.99563.220.439.460white0.065.952576208344482
126.60.240.292.00.02319.086.00.993.250.4512.560white0.136.339868322875077
135.50.160.224.50.0330.0102.00.99383.240.369.460white0.195.805496828840035
147.10.550.131.70.07321.0165.00.9942.970.589.260white0.025.626325499747651
155.90.360.411.30.04745.0104.00.99173.330.5110.660white0.155.8574692473173116
166.20.370.36.60.34679.0200.00.99543.290.589.650white0.075.673138403865096
177.40.290.291.60.04553.0180.00.99363.340.6810.560white0.125.881049066937891
187.00.280.361.00.0358.070.00.98993.090.4612.160white0.16.331006952330057
196.30.190.281.80.02228.0158.00.99073.20.6411.460white0.096.223879853853589
207.20.40.6210.80.04170.0189.00.99763.080.498.640white0.125.524774714222531
216.80.230.321.60.02643.0147.00.99043.290.5412.560white0.06.2961703865057075
225.70.3350.341.00.0413.0174.00.9923.270.6610.050white0.085.800402656790936
237.20.40.6210.80.04170.0189.00.99763.080.498.640white0.145.524774714222531
246.80.190.5814.20.03851.0164.00.99753.120.489.660white0.15.788135549870674
257.80.180.3112.20.05346.0140.00.9983.060.538.960white0.095.830744592684368
266.00.240.271.90.04840.0170.00.99383.640.5410.071white0.165.703226966466673
277.40.360.331.40.02527.055.00.99153.210.3311.260white0.086.116016384477604
287.80.280.329.00.03634.0115.00.99523.170.3910.371white0.086.022923033889072
296.10.310.262.20.05128.0167.00.99263.370.4710.460white0.145.856819257862355
307.20.340.3412.60.0487.041.00.99423.190.411.750white0.176.192277707466559
317.90.190.262.10.0398.0143.00.99423.050.749.850white0.055.964351969004497
326.10.280.221.80.03432.0116.00.98983.360.4412.660white0.156.27339126218223
335.60.190.474.50.0319.0112.00.99223.560.4511.260white0.035.989148797041992
347.90.3450.5115.30.04754.0171.00.99873.090.519.150white0.175.719160807328876
357.40.250.3613.20.06753.0178.00.99763.010.489.060white0.185.817746500692863
366.70.310.319.90.0410.0175.00.99533.460.5511.440white0.15.868530845794709
375.50.350.351.10.04514.0167.00.9923.340.689.960white0.195.764279012924561
387.70.220.421.90.05210.087.00.99223.30.4911.860white0.156.172991242881125
397.20.460.6510.40.0576.0192.00.99763.160.428.750white0.085.460574103277423
409.20.250.341.20.02631.093.00.99162.930.3711.371white0.046.432560649887165
417.70.340.278.80.06339.0184.00.99693.090.639.260white0.145.722531059755198
426.00.260.52.20.04859.0153.00.99283.080.619.850white0.165.808400902227788
436.50.280.275.20.0444.0179.00.99483.190.699.460white0.015.739713686292646
447.20.20.342.70.03249.0151.00.993.160.3912.771white0.066.479839078442581
456.00.380.266.00.03442.0134.00.99123.380.3812.371white0.076.154363778052982
467.40.240.2210.70.04226.081.00.99542.860.369.760white0.016.056783144525866
476.60.250.31.60.04632.0134.00.9933.420.5110.171white0.125.881022852325742
486.90.280.272.10.03642.0121.00.99263.420.4910.871white0.075.984859167739728
497.30.20.371.20.03748.0119.00.9923.320.4910.960white0.16.133824353185275
506.40.4750.061.00.039.0131.00.99042.970.2910.850white0.136.0774683911393765
515.90.270.2911.40.03631.0115.00.99493.350.4810.581white0.155.907559040053343
526.50.360.283.20.03729.0119.00.99083.250.6512.481white0.116.176919749561108
536.50.260.438.90.08350.0171.00.99652.850.59.050white0.185.648383428804067
547.00.320.246.20.04831.0228.00.99573.230.629.460white0.05.701100747622235
557.00.320.246.20.04831.0228.00.99573.230.629.460white0.15.701100747622235
567.00.230.4218.050.0535.0144.00.99993.220.428.850white0.065.632464720274186
577.00.230.4218.050.0535.0144.00.99993.220.428.850white0.125.632464720274186
586.50.210.372.50.04870.0138.00.99173.330.7511.471white0.076.113171978855604
597.80.40.497.80.0634.0162.00.99663.260.5811.360white0.145.655594116200035
606.60.3250.497.70.04953.0217.00.9963.160.49.350white0.135.617926979775575
617.10.310.381.20.03610.0124.00.99243.140.449.960white0.175.963577725009429
627.00.350.36.50.02827.087.00.99363.40.4211.471white0.095.983573337610551
636.30.310.310.00.04649.0212.00.99623.740.5511.960white0.065.686685052707816
647.20.250.2814.40.05555.0205.00.99863.120.389.071white0.05.704889229149558
657.30.260.3317.850.04941.5195.01.03.060.449.171white0.15.645615584045515
667.00.240.34.20.0441.0213.00.99273.280.4911.860white0.096.100208416231084
676.70.2650.228.60.04854.0198.00.99553.250.4110.250white0.195.833875112155567
688.50.320.3614.90.04147.0190.00.99823.080.3110.060white0.175.904191165055238
697.00.240.34.20.0441.0213.00.99273.280.4911.860white0.086.100208416231084
706.40.240.221.50.03838.0157.00.99343.410.559.960white0.125.8083491974390995
719.30.20.331.70.0528.0178.00.99543.160.439.040white0.05.95773846427943
728.20.150.482.70.05224.0190.00.9953.50.4510.971white0.165.91186959143937
737.50.41.019.50.04133.0148.00.99773.240.3812.060white0.15.86254384170698
746.50.180.341.60.0443.0148.00.99123.320.5911.581white0.026.172770568512249
757.00.130.35.00.05631.0122.00.99453.470.4210.560white0.045.956482002194207
767.00.30.326.40.03428.097.00.99243.230.4411.860white0.196.1894753088339485
778.70.340.4613.80.05568.0198.00.99883.360.379.560white0.095.7699618878136505
786.60.5450.042.50.03148.0111.00.99063.140.3211.950white0.136.09371445121684
796.90.160.39.60.05750.0185.00.99783.390.389.660white0.075.635597061994645
807.50.220.294.80.0533.087.00.9943.140.429.950white0.076.027225346273269
816.70.160.282.50.04640.0153.00.99213.380.5111.471white0.026.135243284680314
829.60.210.281.20.03812.053.00.99262.80.4610.650white0.176.386893752303621
838.00.30.285.70.04431.0124.00.99483.160.5110.260white0.015.96263326666795
847.70.430.284.50.04633.0102.00.99183.160.5612.271white0.016.210861284165333
856.50.180.261.40.04140.0141.00.99413.340.729.560white0.035.7543381021827145
866.40.150.361.80.03443.0150.00.99223.420.6911.081white0.06.03799348334482
878.50.210.269.250.03473.0142.00.99453.050.3711.460white0.16.298349263966173
889.40.160.31.40.04226.0176.00.99543.150.469.150white0.175.991868977030862
897.80.220.361.40.05621.0153.00.9933.20.5310.460white0.046.06028624953214
907.40.350.3117.950.06242.0187.01.00023.270.649.150white0.045.575535876996952
916.60.370.242.00.06423.0120.00.99463.320.549.450white0.05.59078730691175
927.10.370.321.40.03727.0126.00.99183.190.6212.050white0.026.02611974919833
936.40.260.217.10.0435.0162.00.99563.390.589.960white0.075.714878646080535
946.40.260.217.10.0435.0162.00.99563.390.589.960white0.195.714878646080535
957.60.30.2210.20.04957.0191.00.99663.080.49.360white0.195.846490209308541
968.80.20.4315.00.05360.0184.01.00083.280.798.860white0.055.651373730232223
977.60.380.23.40.0469.0116.00.99443.150.419.450white0.015.819698152522449
986.80.30.352.80.03810.0164.00.99123.090.5312.060white0.156.177179588784952
996.80.330.281.20.03238.0131.00.98893.190.4113.060white0.096.4328404636031
1007.30.190.246.30.05434.0231.00.99643.360.5410.060white0.125.743644267808804
Rows: 1-100 | Columns: 16

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.