Loading...

vastorbit.machine_learning.vast.svm.LinearSVC

class vastorbit.machine_learning.vast.svm.LinearSVC(name: str = None, overwrite_model: bool = False, **kwargs)

Creates an LinearSVC object using scikit-learn for training and the scalability of VAST DataBase for the inferences.

Parameters:
  • name (str, optional) – Name of the model. The model is stored in the database.

  • overwrite_model (bool, optional) – If set to True, training a model with the same name as an existing model overwrites the existing model.

  • **kwargs (scikit-learn model parameters.)

Variables:
  • created (Many attributes are)

  • phase. (during the fitting)

  • coef_ (numpy.array) – The regression coefficients. The order of coefficients is the same as the order of columns used during the fitting phase.

  • intercept_ (float) – The expected value of the dependent variable when all independent variables are zero, serving as the baseline or constant term in the model.

  • feature_importances_ (numpy.array) – The importance of features is computed through the model coefficients, which are normalized based on their range. Subsequently, an activation function calculates the final score. It is necessary to use the features_importance() method to compute it initially, and the computed values will be subsequently utilized for subsequent calls.

  • classes_ (numpy.array) – The classes labels.

  • note:: (..) – All attributes can be accessed using the get_attributes() method.

Examples

The following examples provide a basic understanding of usage. For more detailed examples, please refer to the Machine Learning or the Examples section on the website.

Load data for machine learning

We import vastorbit:

import vastorbit as vo

Hint

By assigning an alias to vastorbit, we mitigate the risk of code collisions with other libraries. This precaution is necessary because vastorbit uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions from vastorbit are used as intended without interfering with functions from other libraries.

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

Note

vastorbit offers a wide range of sample datasets that are ideal for training and testing purposes. You can explore the full list of available datasets in the Datasets, which provides detailed information on each dataset and how to use them effectively. These datasets are invaluable resources for honing your data analysis and machine learning skills within the vastorbit environment.

You can easily divide your dataset into training and testing subsets using the VastFrame.train_test_split() method. This is a crucial step when preparing your data for machine learning, as it allows you to evaluate the performance of your models accurately.

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

Warning

In this case, vastorbit utilizes seeded randomization to guarantee the reproducibility of your data split. However, please be aware that this approach may lead to reduced performance. For a more efficient data split, you can use the VastFrame.to_db() method to save your results into tables or temporary tables. This will help enhance the overall performance of the process.

Model Initialization

First we import the LinearSVC model:

from vastorbit.machine_learning.vast import LinearSVC

Then we can create the model:

model = LinearSVC(
    C = 1.0,
    intercept_scaling = 1.0,
    class_weight = [1, 1],
    max_iter = 1000,
)

Important

The model name is crucial for the model management system and versioning. It’s highly recommended to provide a name if you plan to reuse the model later.

Model Training

We can now fit the model:

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

Important

To train a model, you can directly use the VastFrame or the name of the relation stored in the database. The test set is optional and is only used to compute the test metrics. In vastorbit, we don’t work using X matrices and y vectors. Instead, we work directly with lists of predictors and the response name.

Features Importance

We can conveniently get the features importance:

result = model.features_importance()

Note

For LinearModel, feature importance is computed using the coefficients. These coefficients are then normalized using the feature distribution. An activation function is applied to get the final score.

Metrics

We can get the entire report using:

model.report()
value
auc0.6955280685061823
prc_auc0.3106813995161213
accuracy0.7978642257818459
log_loss0.5347809560170647
precision0.0
recall0.0
f1_score0.0
mcc0.0
informedness0.0
markedness-0.2021357742181541
csi0.0
Rows: 1-11 | Columns: 2

Important

Most metrics are computed using a single SQL query, but some of them might require multiple SQL queries. Selecting only the necessary metrics in the report can help optimize performance. E.g. model.report(metrics = ["auc", "accuracy"]).

For classification models, we can easily modify the cutoff to observe the effect on different metrics:

model.report(cutoff = 0.2)
value
auc0.6747408175355465
prc_auc0.795930129113751
accuracy0.19374523264683446
log_loss0.5521818379311714
precision0.18754803996925443
recall1.0
f1_score0.31585760517799355
mcc0.04192509498158747
informedness0.009372071227741419
markedness0.1875480399692544
csi0.18754803996925443
Rows: 1-11 | Columns: 2

You can also use the LinearModel.score function to compute any classification metric. The default metric is the accuracy:

model.score()

Prediction

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
Integer
16.80.370.5111.80.04462.0163.00.99763.190.448.850white0.050
27.20.250.3918.950.03842.0155.00.99992.970.479.060white0.050
37.30.280.3612.70.0438.0140.00.9983.30.799.660white0.110
47.00.210.288.70.04537.0222.00.99543.250.5410.460white0.080
57.80.210.271.20.05120.089.00.99363.060.469.150white0.150
66.80.290.513.30.05348.0194.00.99743.090.459.450white0.180
76.10.280.322.50.04223.0218.50.99353.270.69.850white0.150
87.40.1550.342.30.04573.5214.00.99343.180.619.971white0.10
96.20.350.041.20.0623.0108.00.99343.260.549.250white0.020
106.90.240.3620.80.03140.0139.00.99753.20.3311.060white0.010
115.90.460.142.70.04227.0160.00.99313.460.5110.671white0.040
126.00.270.271.60.04632.0113.00.99243.410.5110.571white0.10
136.10.430.359.10.05983.0249.00.99713.370.58.550white0.140
146.80.320.212.20.04415.068.00.99323.170.399.460white0.050
156.60.240.292.00.02319.086.00.993.250.4512.560white0.170
166.30.220.331.70.04167.0164.00.99283.320.5610.460white0.060
177.10.230.391.60.03212.065.00.98983.250.412.771white0.120
186.80.190.5814.20.03851.0164.00.99753.120.489.660white0.00
197.80.180.3112.20.05346.0140.00.9983.060.538.960white0.120
207.80.340.351.80.0428.0167.00.99083.110.4112.160white0.110
217.80.280.329.00.03634.0115.00.99523.170.3910.371white0.180
225.90.130.281.90.0520.078.00.99183.430.6410.860white0.10
237.90.190.262.10.0398.0143.00.99423.050.749.850white0.130
246.90.250.41.30.03822.0101.00.99013.030.3911.460white0.120
257.20.310.465.00.043.029.00.99063.040.5312.540white0.160
267.40.250.3613.20.06753.0178.00.99763.010.489.060white0.170
277.40.250.3613.20.06753.0178.00.99763.010.489.060white0.060
287.20.460.6510.40.0576.0192.00.99763.160.428.750white0.020
295.50.350.351.10.04514.0167.00.9923.340.689.960white0.190
306.50.180.311.70.04430.0127.00.99283.490.510.271white0.010
319.20.250.341.20.02631.093.00.99162.930.3711.371white0.080
327.80.280.341.60.02832.0118.00.99013.00.3812.171white0.080
336.70.210.429.10.04931.0150.00.99533.120.749.971white0.080
348.20.220.31.80.04747.0185.00.99333.130.510.260white0.190
356.50.280.292.70.03826.0107.00.99123.320.4111.671white0.170
367.30.30.226.40.05644.0168.00.99473.130.3510.160white0.030
377.10.310.514.50.0596.0148.00.99832.940.449.150white0.010
386.90.410.3310.10.04328.0152.00.99683.20.529.450white0.00
396.40.450.071.10.0310.0131.00.99052.970.2810.850white0.050
406.90.410.3310.10.04328.0152.00.99683.20.529.450white0.140
417.20.240.41.40.04531.0106.00.99142.880.3810.860white0.140
426.40.450.071.10.0310.0131.00.99052.970.2810.850white0.020
437.50.210.6810.90.04538.0133.00.99783.00.368.750white0.00
447.80.320.332.40.03718.0101.00.99123.210.6511.771white0.180
457.80.260.271.90.05152.0195.00.99283.230.510.960white0.180
467.40.190.31.40.05733.0135.00.9933.120.59.660white0.020
477.00.230.4218.050.0535.0144.00.99993.220.428.850white0.110
486.20.170.284.70.03739.0133.00.99313.410.4610.871white0.130
495.90.240.2612.30.05334.0134.00.99723.340.459.560white0.090
506.60.270.253.10.05241.0188.00.99153.240.411.350white0.110
517.10.170.387.40.05249.0182.00.99583.350.529.660white0.030
526.20.360.2613.20.05154.0201.00.99763.250.469.050white0.050
537.50.310.5114.80.03962.0204.00.99823.060.69.550white0.150
546.20.310.216.30.04150.0218.00.99413.150.610.050white0.080
557.20.180.454.40.04657.0166.00.99433.130.6211.260white0.070
568.20.270.431.60.03531.0128.00.99163.10.512.360white0.140
577.70.420.319.20.04822.0221.00.99693.060.619.260white0.110
586.90.310.341.60.03223.0128.00.99173.370.4711.760white0.10
596.60.330.311.30.0229.089.00.990353.260.4412.481white0.00
607.80.30.41.80.02823.0122.00.99143.140.3910.971white0.120
616.40.240.312.80.03841.0114.00.991553.370.6611.771white0.140
627.00.210.348.00.05719.0101.00.99542.990.599.450white0.190
636.40.160.315.30.04342.0157.00.994553.350.4710.550white0.010
648.80.280.456.00.02214.049.00.99343.010.3311.171white0.070
656.90.390.44.60.0225.019.00.99153.310.3712.630white0.160
667.40.380.277.50.04124.0160.00.995353.170.4310.050white0.10
677.00.210.348.50.03331.0253.00.99533.220.5610.560white0.00
685.80.250.2811.10.05645.0175.00.997553.420.439.550white0.020
697.10.130.41.20.04754.0134.00.99323.30.979.871white0.060
706.70.110.348.80.04341.0113.00.99623.420.49.371white0.010
718.10.170.4414.10.05343.0145.01.00063.280.758.881white0.010
727.20.230.1913.70.05247.0197.00.998653.120.539.050white0.00
737.70.340.2811.00.0431.0117.00.998153.270.299.260white0.180
745.90.240.32.00.03328.092.00.992253.390.6910.971white0.030
757.20.310.267.30.0537.0157.00.996253.090.439.050white0.190
767.80.420.238.80.05442.0215.00.99713.020.589.260white0.170
776.00.180.311.40.03614.075.00.990853.340.5811.181white0.080
787.80.270.5811.20.03644.0161.00.99773.060.418.960white0.050
796.20.290.2613.10.04655.0204.00.997453.160.419.660white0.120
806.00.390.1712.00.04665.0246.00.99763.150.389.060white0.160
816.20.30.2613.40.04657.0206.00.997753.170.439.560white0.180
826.20.30.172.80.0424.0125.00.99393.010.469.050white0.150
836.20.30.172.80.0424.0125.00.99393.010.469.050white0.180
847.30.6550.210.20.07128.0212.00.99712.960.589.260white0.00
856.90.250.341.30.03527.082.00.990453.180.4412.260white0.120
867.50.420.344.30.0434.0108.00.991553.140.4512.881white0.070
877.30.250.362.10.03430.0177.00.990853.250.411.981white0.030
888.70.230.3213.40.04435.0169.00.999753.120.478.871white0.040
896.60.220.3715.40.03562.0153.00.998453.020.49.350white0.150
906.90.180.361.30.03640.0117.00.99343.270.959.571white0.180
916.20.280.331.70.02924.0111.00.993.240.512.160white0.080
924.80.330.06.50.02834.0163.00.99373.350.619.950white0.160
936.10.270.332.20.02126.0117.00.98863.120.312.560white0.110
9410.30.170.471.40.0375.033.00.99392.890.289.630white0.050
958.80.360.441.90.049.0121.00.99533.190.489.960white0.080
967.30.260.311.60.0439.0173.00.99183.190.5111.460white0.120
975.60.190.391.10.04317.067.00.99183.230.5310.360white0.020
986.80.180.288.70.04752.0242.00.99523.220.5310.560white0.080
996.60.260.291.40.03913.067.00.99153.050.4910.960white0.040
1006.60.20.387.90.05230.0145.00.99473.320.5611.071white0.090
Rows: 1-100 | Columns: 16

Note

Predictions can be made automatically using the test set, in which case you don’t need to specify the predictors. Alternatively, you can pass only the VastFrame to the predict() function, but in this case, it’s essential that the column names of the VastFrame match the predictors and response name in the model.

Probabilities

It is also easy to get the model’s probabilities:

model.predict_proba(
    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
Integer
123
prediction_0
Double
123
prediction_1
Double
16.30.670.4812.60.05257.0222.00.99793.170.529.360white0.0500.70589847051300450.29410152948699547
27.10.260.325.90.03739.097.00.99343.310.411.660white0.0500.62102287455255880.3789771254474413
37.00.20.345.70.03532.083.00.99283.190.4611.560white0.1100.60989046411672140.39010953588327857
46.20.180.494.50.04717.090.00.99193.270.3711.660white0.0800.6103575583708610.38964244162913897
58.20.180.491.10.03328.081.00.99233.00.6810.471white0.1500.57784339049911470.42215660950088524
67.00.390.241.00.0488.0119.00.99233.00.3110.140white0.1800.63071447914249060.3692855208575095
78.50.560.7417.850.05151.0243.01.00052.990.79.250white0.1500.70287415616983780.29712584383016216
86.30.230.497.10.0567.0210.00.99513.230.349.550white0.100.6314762713576040.368523728642396
96.10.250.497.60.05267.0226.00.99563.160.478.950white0.0200.6384230399184790.36157696008152096
107.80.430.4913.00.03337.0158.00.99553.140.3511.360white0.0100.65953683375479270.3404631662452073
117.80.430.4913.00.03337.0158.00.99553.140.3511.360white0.0400.65953683375479270.3404631662452073
127.60.520.4914.00.03437.0156.00.99583.140.3811.871white0.100.67498957078539080.3250104292146092
137.90.110.494.50.04827.0133.00.99463.240.4210.660white0.1400.60208432387237680.39791567612762324
147.10.250.493.00.0330.096.00.99033.130.3912.371white0.0500.59191720786899770.4080827921310023
157.80.210.491.350.0526.048.00.99113.150.2811.450white0.1700.60422936530858530.3957706346914147
167.70.160.492.00.05620.0124.00.99483.320.4910.760white0.0600.60657746931329390.3934225306867061
177.50.20.491.30.0318.097.00.99183.060.6211.150white0.1200.57946658846600010.4205334115339999
188.30.20.491.70.0434.0169.00.99383.050.3710.150white0.000.59124320813897490.40875679186102515
199.20.180.491.50.04139.0130.00.99453.040.499.871white0.1200.58835493325925280.4116450667407472
208.80.230.743.20.04215.0126.00.99343.020.5111.260white0.1100.59316516474347320.40683483525652675
217.40.190.499.30.0326.0132.00.9942.990.3211.071white0.1800.61262672758232720.3873732724176729
228.40.230.497.80.03522.095.00.99353.040.3412.060white0.100.61547060982715380.38452939017284615
238.30.20.491.70.03838.0167.00.99393.050.3710.160white0.1300.58900002714497430.41099997285502565
246.90.210.491.40.04115.0164.00.99273.250.6311.050white0.1200.59336698866457520.4066330113354248
2514.20.270.491.10.03733.0156.00.9923.150.5411.160white0.1600.5874744330434160.41252556695658404
267.50.230.497.70.04961.0209.00.99413.140.311.171white0.1700.63149886787038510.3685011321296149
277.30.260.495.00.02832.0107.00.99363.240.5410.860white0.0600.60030214427352570.39969785572647437
287.10.530.240.80.02929.086.00.9933.160.329.140white0.0200.62572477868388670.37427522131611335
297.20.160.491.30.03727.0104.00.99243.230.5710.660white0.1900.58184917364852470.4181508263514752
307.10.360.241.80.02532.0102.00.99033.340.5912.860white0.0100.60439817609818780.3956018239018122
316.60.190.991.20.12245.0129.00.99363.090.318.760white0.0800.66018903852837880.33981096147162115
327.30.210.491.80.03844.0152.00.99123.320.4412.671white0.0800.59089934704248970.40910065295751025
337.80.30.741.80.03333.0156.00.9913.290.5212.860white0.0800.58573160558468820.4142683944153118
346.80.170.742.40.05361.0182.00.99533.630.7610.560white0.1900.59728245972442370.4027175402755762
356.40.180.7411.90.04654.0168.00.99783.580.6810.150white0.1700.63241809133449730.36758190866550267
368.40.240.497.40.03946.0108.00.99343.030.3311.971white0.0300.61937002409827190.3806299759017281
377.90.140.741.20.02830.0165.00.9913.080.8212.360white0.0100.55735119192234730.4426488080776527
386.80.210.741.20.04725.0111.00.99163.130.4110.760white0.000.58911974048947520.4108802595105248
398.60.160.497.30.0439.063.00.99533.130.5910.560white0.0500.61410977907098110.3858902209290189
406.60.550.012.70.03456.0122.00.99063.150.311.950white0.1400.65001961717079810.3499803828292019
418.20.340.498.00.04655.0223.00.9963.080.5210.760white0.1400.64225166249057590.3577483375094241
425.60.390.244.70.03427.077.00.99063.280.3612.750white0.0200.63185745581036110.36814254418963893
438.00.140.491.50.03542.0120.00.99283.260.410.671white0.000.57728535956348730.4227146404365127
446.90.340.497.30.04561.0206.00.99573.090.49.060white0.1800.63940095091717540.36059904908282453
456.20.20.491.60.06517.0143.00.99373.220.529.260white0.1800.62084273795504610.3791572620449539
466.20.220.496.00.02931.0128.00.99283.410.3611.381white0.0200.60175026576186970.39824973423813026
476.90.250.241.80.0536.0121.00.9933.230.711.450white0.1100.62325375494801870.3767462450519813
487.80.490.497.00.04329.0149.00.99523.210.3310.050white0.1300.65245032515301490.347549674846985
497.90.330.2831.60.05335.0176.01.01033.150.388.860white0.0900.74874178001161520.2512582199883848
506.60.310.497.70.0552.0220.00.99643.120.458.850white0.1100.64342849902693060.35657150097306944
518.80.390.345.90.05533.0128.00.99272.950.5111.860white0.0300.65324235877117580.34675764122882424
527.20.250.2814.40.05555.0205.00.99863.120.389.071white0.0500.67681191920048920.3231880807995108
536.90.180.32.00.03839.0190.00.99143.320.3712.260white0.1500.59611446419467720.4038855358053228
546.40.240.221.50.03838.0157.00.99343.410.559.960white0.0800.60546002773625450.3945399722637455
556.80.260.2916.950.05648.0179.00.99983.450.49.650white0.0700.68920154506453570.3107984549354643
567.90.180.373.00.06125.0178.00.9953.220.5110.060white0.1400.62336832562567460.3766316743743255
577.00.210.316.00.04629.0108.00.99393.260.510.860white0.1100.62602755491759090.3739724450824092
587.50.41.019.50.04133.0148.00.99773.240.3812.060white0.100.67274676865431560.3272532313456844
596.50.180.341.60.0443.0148.00.99123.320.5911.581white0.000.59538210090602270.4046178990939772
607.00.130.35.00.05631.0122.00.99453.470.4210.560white0.1200.62382736850257570.3761726314974243
617.00.30.326.40.03428.097.00.99243.230.4411.860white0.1400.62443155702483130.3755684429751687
627.60.4450.4414.50.04568.0212.00.99863.480.3610.060white0.1900.68242524804379940.31757475195620055
636.80.30.246.60.12335.0116.00.99533.070.489.450white0.0100.72055405871098420.27944594128901573
646.60.5450.042.50.03148.0111.00.99063.140.3211.950white0.0700.64426788071651420.3557321192834858
656.60.370.476.50.06123.0150.00.99543.140.459.660white0.1600.65764680860858130.34235319139141873
666.60.220.581.10.13352.0136.00.99323.10.39.150white0.100.68920648417814550.31079351582185455
677.40.230.251.40.04943.0141.00.99343.420.5410.271white0.000.6139606761707510.386039323829249
686.70.270.258.00.05354.0202.00.99613.220.439.350white0.0200.65211393624434690.3478860637556531
696.60.620.28.70.04681.0224.00.996053.170.449.350white0.0600.68876816802728480.31123183197271514
707.70.430.284.50.04633.0102.00.99183.160.5612.271white0.0100.64552396998823090.354476030011769
716.40.150.361.80.03443.0150.00.99223.420.6911.081white0.0100.58534207832264120.4146579216773588
726.70.240.296.80.03854.0127.00.99323.330.4611.671white0.000.6250548081256460.37494519187435404
737.20.260.32.10.03350.0158.00.99093.330.4312.171white0.1800.6002325590392670.399767440960733
747.40.350.3117.950.06242.0187.01.00023.270.649.150white0.0300.70744743178249350.29255256821750647
756.70.370.416.30.06122.0149.00.99533.160.479.660white0.1900.65894363760004690.3410563623999531
767.10.370.321.40.03727.0126.00.99183.190.6212.050white0.1700.61456239626361450.38543760373638547
776.40.260.217.10.0435.0162.00.99563.390.589.960white0.0800.6348825200425940.36511747995740595
787.60.30.2210.20.04957.0191.00.99663.080.49.360white0.0500.66069912194355960.33930087805644044
798.80.20.4315.00.05360.0184.01.00083.280.798.860white0.1200.66518431715025210.33481568284974794
807.50.330.3912.40.06529.0119.00.99743.160.399.450white0.1600.68347509937233690.3165249006276631
818.80.20.4315.00.05360.0184.01.00083.280.798.860white0.1800.66518431715025210.33481568284974794
826.80.30.352.80.03810.0164.00.99123.090.5312.060white0.1500.61220425458599760.3877957454140024
836.00.260.291.00.03227.096.00.98963.380.4412.360white0.1800.59553795067837450.4044620493216256
847.40.290.311.70.03523.0110.00.99263.070.3810.950white0.000.60427557900721970.39572442099278027
857.40.490.2415.10.0334.0153.00.99533.130.5112.071white0.1200.68096844781694790.3190315521830521
868.00.550.4212.60.21137.0213.00.99882.990.569.350white0.0700.827084296052260.17291570394773997
876.50.340.3611.00.05253.0247.00.99843.440.559.360white0.0300.66790286072273690.3320971392772632
887.20.240.292.20.03737.0102.00.9923.270.6411.071white0.0400.60343299872464960.39656700127535033
897.60.260.587.90.04162.0180.00.99663.070.389.050white0.1500.62423309594556420.3757669040544358
906.40.180.311.60.04936.0127.00.99343.60.6710.471white0.1800.60740345141035130.39259654858964865
916.60.280.37.80.04957.0202.00.99583.240.399.550white0.0800.64630448732704070.35369551267295923
927.10.250.32.40.04225.0122.00.9943.430.6110.560white0.1600.61135669167260060.38864330832739935
937.60.360.448.30.25528.0142.00.99583.120.4310.260white0.1100.83095174849332750.1690482515066725
945.80.330.216.050.04726.0166.00.99763.090.468.950white0.0500.68778748005873850.31221251994126153
957.20.20.6116.20.04314.0103.00.99873.060.369.260white0.0800.65376423904300780.3462357609569922
967.20.240.417.850.04950.0185.01.03.340.429.650white0.1200.67919705754255140.3208029424574485
977.90.260.3310.30.03973.0212.00.99692.930.499.560white0.0200.64151257952660230.35848742047339766
987.50.290.678.10.03753.0166.00.99662.90.418.960white0.0800.62085263403903160.37914736596096843
997.20.310.418.60.05315.089.00.99763.290.649.960white0.0400.65311684935211930.3468831506478806
10010.00.230.2714.10.03345.0166.00.99882.720.439.760white0.0900.64811199421288990.35188800578711005
Rows: 1-100 | Columns: 18

Note

Probabilities are added to the VastFrame, and vastorbit uses the corresponding probability function in SQL behind the scenes. You can use the pos_label parameter to add only the probability of the selected category.

Confusion Matrix

You can obtain the confusion matrix of your choice by specifying the desired cutoff.

model.confusion_matrix(cutoff = 0.5)

Note

In classification, the cutoff is a threshold value used to determine class assignment based on predicted probabilities or scores from a classification model. In binary classification, if the predicted probability for a specific class is greater than or equal to the cutoff, the instance is assigned to the positive class; otherwise, it is assigned to the negative class. Adjusting the cutoff allows for trade-offs between true positives and false positives, enabling the model to be optimized for specific objectives or to consider the relative costs of different classification errors. The choice of cutoff is critical for tailoring the model’s performance to meet specific needs.

Main Plots (Classification Curves)

Classification models allow for the creation of various plots that are very helpful in understanding the model, such as the ROC Curve, PRC Curve, Cutoff Curve, Gain Curve, and more.

Most of the classification curves can be found in the Machine Learning - Classification Curve.

For example, let’s draw the model’s ROC curve.

model.roc_curve()

Important

Most of the curves have a parameter called nbins, which is essential for estimating metrics. The larger the nbins, the more precise the estimation, but it can significantly impact performance. Exercise caution when increasing this parameter excessively.

Hint

In binary classification, various curves can be easily plotted. However, in multi-class classification, it’s important to select the pos_label, representing the class to be treated as positive when drawing the curve.

Other Plots

If the model allows, you can also generate relevant plots. For example, classification plots can be found in the Machine Learning - Classification Plots.

model.plot()

Important

The plotting feature is typically suitable for models with fewer than three predictors.

Contour plot is another useful plot that can be produced for models with two predictors.

model.contour()

Important

Machine learning models with two predictors can usually benefit from their own contour plot. This visual representation aids in exploring predictions and gaining a deeper understanding of how these models perform in different scenarios. Please refer to Contour Plot for more examples.

Parameter Modification

In order to see the parameters:

model.get_params()

And to manually change some of the parameters:

model.set_params({'tol': 0.001})

Model Exporting

To Memmodel

model.to_memmodel()

Note

MemModel objects serve as in-memory representations of machine learning models. They can be used for both in-database and in-memory prediction tasks. These objects can be pickled in the same way that you would pickle a scikit-learn model.

The following methods for exporting the model use MemModel, and it is recommended to use MemModel directly.

To SQL

You can get the SQL code by:

model.to_sql()

To Python

To obtain the prediction function in Python syntax, use the following code:

X = [[4.2, 0.17, 0.36, 1.8, 0.029, 0.9899]]
model.to_python()(X)

Hint

The to_python() method is used to retrieve predictions, probabilities, or cluster distances. For specific details on how to use this method for different model types, refer to the relevant documentation for each model.

__init__(name: str = None, overwrite_model: bool = False, **kwargs) None

Methods

__init__([name, overwrite_model])

classification_report([metrics, cutoff, nbins])

Computes a classification report using multiple model evaluation metrics (auc, accuracy, f1...).

confusion_matrix([cutoff])

Computes the model confusion matrix.

contour([nbins, chart])

Draws the model's contour plot.

cutoff_curve([nbins, show, chart])

Draws the model Cutoff curve.

deploySQL([X, cutoff])

Returns the SQL code needed to deploy the model.

drop()

Drops the model from the VAST DataBase.

export_models(name, path[, kind])

Exports machine learning models.

features_importance([show, chart])

Computes the model's features importance.

fit(input_relation, X, y[, test_relation, ...])

Trains the model.

get_attributes([attr_name])

Returns the model attributes.

get_match_index(x, col_list[, str_check])

Returns the matching index.

get_params()

Returns the parameters of the model.

get_plotting_lib([class_name, chart, ...])

Returns the first available library (Plotly, Matplotlib) to draw a specific graphic.

import_models(path[, schema, kind])

Imports machine learning models.

lift_chart([nbins, show, chart])

Draws the model Lift Chart.

plot([max_nb_points, chart])

Draws the model.

prc_curve([nbins, show, chart])

Draws the model PRC curve.

predict(vdf[, X, name, cutoff, inplace])

Makes predictions on the input relation.

predict_proba(vdf[, X, name, pos_label, inplace])

Returns the model's probabilities using the input relation.

report([metrics, cutoff, nbins])

Computes a classification report using multiple model evaluation metrics (auc, accuracy, f1...).

roc_curve([nbins, show, chart])

Draws the model ROC curve.

score([metric, cutoff, nbins])

Computes the model score.

set_params([parameters])

Sets the parameters of the model.

summarize()

Summarizes the model.

to_binary(path)

Exports the model to the VAST Binary format.

to_memmodel()

Converts the model to an InMemory object that can be used for different types of predictions.

to_python([return_proba, ...])

Returns the Python function needed for in-memory scoring without using built-in VAST functions.

to_sql([X, return_proba, ...])

Returns the SQL code needed to deploy the model without using built-in VAST functions.

Attributes