Loading...

vastorbit.machine_learning.vast.ensemble.GradientBoostingClassifier

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

Creates an GradientBoostingClassifier 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)

  • trees_ (list of BinaryTreeClassifier) – Tree models are instances of ` BinaryTreeClassifier, each possessing various attributes. For more detailed information, refer to the documentation for BinaryTreeClassifier.

  • feature_importances_ (numpy.array) – The importance of features. It is calculated using the average gain of each tree. To determine the final score, vastorbit sums the scores of each tree, normalizes them and applies an activation function to scale them. It is necessary to use the features_importance() method to compute it initially, and the computed values will be subsequently utilized for subsequent calls.

  • feature_importances_trees_ (dict of numpy.array) – Each element of the array represents the feature importance of tree i. The importance of features is calculated using the average gain of each tree. It is necessary to use the features_importance() method to compute it initially, and the computed values will be subsequently utilized for subsequent calls.

  • logodds_ (numpy.array) – The log-odds. It quantifies the logarithm of the odds ratio, providing a measure of the likelihood of an event occurring.

  • eta_ (float) – The learning rate, is a crucial hyperparameter in machine learning algorithms. It determines the step size at each iteration during the model training process. A well-chosen learning rate is essential for achieving optimal convergence and preventing overshooting or slow convergence in the training phase. Adjusting the learning rate is often necessary to strike a balance between model accuracy and computational efficiency.

  • n_estimators_ (int) – The number of model estimators.

  • 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.

Important

Many tree-based models inherit from the GradientBoosting base class, and it’s recommended to use it directly for access to a wider range of options.

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.

Balancing the Dataset

In vastorbit, balancing a dataset to address class imbalances is made straightforward through the balance() function within the preprocessing module. This function enables users to rectify skewed class distributions efficiently. By specifying the target variable and setting parameters like the method for balancing, users can effortlessly achieve a more equitable representation of classes in their dataset. Whether opting for over-sampling, under-sampling, or a combination of both, vastorbit’s balance() function streamlines the process, empowering users to enhance the performance and fairness of their machine learning models trained on imbalanced data.

To balance the dataset, use the following syntax.

from vastorbit.machine_learning.vast.preprocessing import balance

balanced_train = balance(
    name = "my_schema.train_balanced",
    input_relation = train,
    y = "good",
    method = "hybrid",
)

Note

With this code, a table named train_balanced is created in the my_schema schema. It can then be used to train the model. In the rest of the example, we will work with the full dataset.

Hint

Balancing the dataset is a crucial step in improving the accuracy of machine learning models, particularly when faced with imbalanced class distributions. By addressing disparities in the number of instances across different classes, the model becomes more adept at learning patterns from all classes rather than being biased towards the majority class. This, in turn, enhances the model’s ability to make accurate predictions for under-represented classes. The balanced dataset ensures that the model is not dominated by the majority class and, as a result, leads to more robust and unbiased model performance. Therefore, by employing techniques such as over-sampling, under-sampling, or a combination of both during dataset preparation, practitioners can significantly contribute to achieving higher accuracy and better generalization of their machine learning models.

Model Initialization

First we import the GradientBoostingClassifier model:

from vastorbit.machine_learning.vast import GradientBoostingClassifier

Then we can create the model:

model = GradientBoostingClassifier(
    n_estimators = 3,
    max_depth = 3,
    nbins = 6,
    split_proposal_method = 'global',
    tol = 0.001,
    learning_rate = 0.1,
    min_split_loss = 0,
    weight_reg = 0,
    sample = 0.7,
    col_sample_by_tree = 1,
    col_sample_by_node = 1,
)

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

In models such as GradientBoosting, feature importance is calculated using the average gain of each tree. To determine the final score, vastorbit sums the scores of each tree, normalizes them and applies an activation function to scale them.

Metrics

We can get the entire report using:

model.report()
value
auc0.0
prc_auc0.0
accuracy0.0
log_loss0.21525744989987353
precision0.0
recall0.0
f1_score0.0
mcc0.0
informedness-1.0
markedness-1.0
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.0
prc_auc0.0
accuracy0.0
log_loss0.21568009462021687
precision0.0
recall0.0
f1_score0.0
mcc0.0
informedness-1.0
markedness-1.0
csi0.0
Rows: 1-11 | Columns: 2

You can also use the 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
Decimal(11, 1)
16.80.370.5111.80.04462.0163.00.99763.190.448.850white0.121.0
27.20.250.3918.950.03842.0155.00.99992.970.479.060white0.11.0
37.30.280.3612.70.0438.0140.00.9983.30.799.660white0.071.0
47.00.220.312.70.0341.0136.00.98983.160.3712.771white0.041.0
57.00.210.288.60.04537.0221.00.99543.250.5410.460white0.131.0
66.90.20.376.20.02724.097.00.9923.380.4912.271white0.131.0
76.60.160.321.40.03549.0186.00.99063.350.6412.481white0.11.0
86.50.410.2414.00.04824.0113.00.99823.440.539.860white0.021.0
96.00.370.321.00.05331.0218.50.99243.290.729.860white0.021.0
107.10.210.278.60.05626.0111.00.99562.950.529.550white0.061.0
117.00.140.329.00.03954.0141.00.99563.220.439.460white0.121.0
127.00.220.281.50.03729.0115.00.99273.110.5510.560white0.161.0
137.10.550.131.70.07321.0165.00.9942.970.589.260white0.161.0
146.70.470.348.90.04331.0172.00.99643.220.69.250white0.071.0
156.20.370.36.60.34679.0200.00.99543.290.589.650white0.081.0
166.00.160.371.50.02543.0117.00.99283.460.519.760white0.071.0
177.00.280.361.00.0358.070.00.98993.090.4612.160white0.141.0
187.10.230.391.60.03212.065.00.98983.250.412.771white0.11.0
195.70.440.137.00.02528.0173.00.99133.330.4812.560white0.061.0
207.20.40.6210.80.04170.0189.00.99763.080.498.640white0.151.0
217.20.280.5416.70.04554.0200.00.9993.080.499.560white0.021.0
226.80.190.5814.20.03851.0164.00.99753.120.489.660white0.01.0
237.30.260.365.20.0431.0141.00.99313.160.5911.060white0.061.0
247.80.280.329.00.03634.0115.00.99523.170.3910.371white0.011.0
256.80.180.371.60.05547.0154.00.99343.080.459.150white0.121.0
267.40.150.421.70.04549.0154.00.9923.00.610.460white0.031.0
275.20.360.021.60.03124.0104.00.98963.440.3512.260white0.061.0
286.10.240.31.50.04522.061.00.9923.310.5410.450white0.171.0
296.80.250.244.550.05341.0211.00.99553.370.679.560white0.091.0
306.80.280.1713.90.04749.0162.00.99833.210.519.060white0.191.0
317.00.30.5113.60.0540.0168.00.99763.070.529.671white0.061.0
327.80.280.341.60.02832.0118.00.99013.00.3812.171white0.171.0
338.40.350.7112.20.04622.0160.00.99822.980.659.450white0.051.0
345.90.210.2412.10.04453.0165.00.99693.250.399.550white0.071.0
355.90.370.11.60.05739.0128.00.99243.240.4810.150white0.091.0
367.70.340.278.80.06339.0184.00.99693.090.639.260white0.171.0
377.20.350.3412.40.0516.037.00.99443.130.3911.560white0.181.0
386.10.320.251.70.03437.0136.00.9923.470.510.871white0.141.0
396.90.410.3310.10.04328.0152.00.99683.20.529.450white0.021.0
407.00.290.374.90.03426.0127.00.99283.170.4410.860white0.191.0
416.70.30.351.40.1836.0160.00.99373.110.549.460white0.081.0
426.30.260.491.50.05234.0134.00.99242.990.619.860white0.021.0
437.30.250.297.50.04938.0158.00.99653.430.389.650white0.051.0
447.30.250.297.50.04938.0158.00.99653.430.389.650white0.011.0
457.50.230.6811.00.04737.0133.00.99782.990.388.850white0.081.0
467.20.240.341.10.0453.064.00.99133.230.5111.450white0.081.0
475.80.310.331.20.03623.099.00.99163.180.610.560white0.071.0
487.40.280.2511.90.05325.0148.00.99763.10.629.250white0.121.0
495.90.240.2612.30.05334.0134.00.99723.340.459.560white0.051.0
507.70.270.355.30.0330.0117.00.9923.110.4212.260white0.031.0
519.00.310.486.60.04311.073.00.99382.90.3811.650white0.011.0
528.20.220.366.80.03412.090.00.99443.010.3810.581white0.151.0
535.80.170.31.40.03755.0130.00.99093.290.3811.360white0.151.0
548.60.550.3515.550.05735.5366.51.00013.040.6311.030white0.031.0
556.50.360.492.90.0316.094.00.99023.10.4912.171white0.011.0
567.10.290.491.20.03132.099.00.98933.070.3312.260white0.171.0
577.00.180.495.30.0434.0125.00.99143.240.412.260white0.021.0
587.80.430.4913.00.03337.0158.00.99553.140.3511.360white0.081.0
598.30.210.4919.80.05450.0231.01.00122.990.549.250white0.131.0
608.50.170.743.60.0529.0128.00.99283.280.412.460white0.091.0
618.00.440.499.10.03146.0151.00.99263.160.2712.781white0.181.0
627.10.850.498.70.02840.0184.00.99623.220.3610.750white0.11.0
636.20.150.490.90.03317.051.00.99323.30.79.460white0.021.0
648.00.30.499.40.04647.0188.00.99643.140.4810.050white0.061.0
657.60.290.499.60.0345.0197.00.99383.130.3812.371white0.161.0
667.40.190.499.30.0326.0132.00.9942.990.3211.071white0.071.0
678.30.20.491.70.03838.0167.00.99393.050.3710.160white0.01.0
6814.20.270.491.10.03733.0156.00.9923.150.5411.160white0.021.0
697.10.180.7415.60.04444.0176.00.99963.380.679.060white0.041.0
707.90.120.495.20.04933.0152.00.99523.180.4710.660white0.031.0
718.50.150.491.50.03117.0122.00.99323.030.410.360white0.031.0
727.30.210.491.80.03844.0152.00.99123.320.4412.671white0.111.0
736.90.30.497.60.05725.0156.00.99623.430.6311.071white0.191.0
747.80.30.741.80.03333.0156.00.9913.290.5212.860white0.181.0
759.10.280.492.00.05910.0112.00.99583.150.4610.150white0.041.0
767.50.190.491.80.05519.0110.00.99463.330.449.950white0.131.0
776.90.220.497.00.06350.0168.00.99573.540.510.360white0.031.0
789.00.30.497.20.03932.084.00.99382.940.3211.560white0.01.0
797.30.30.7413.50.03946.0165.00.99823.020.48.750white0.151.0
806.30.240.741.40.17224.0108.00.99323.270.399.960white0.111.0
816.70.330.491.60.16720.094.00.99143.110.511.460white0.111.0
825.60.390.244.70.03427.077.00.99063.280.3612.750white0.061.0
838.00.140.491.50.03542.0120.00.99283.260.410.671white0.161.0
846.40.370.4913.30.04553.0243.00.99823.140.488.560white0.171.0
856.40.260.496.40.03737.0161.00.99543.380.539.760white0.031.0
869.00.220.4910.40.04852.0195.00.99873.310.4410.260white0.161.0
878.30.250.4916.80.04850.0228.01.00013.030.529.260white0.131.0
886.40.220.497.50.05442.0151.00.99483.270.5210.160white0.131.0
897.10.30.491.60.04531.0100.00.99423.40.5910.250white0.091.0
907.60.310.493.950.04427.0131.00.99123.080.6712.871white0.071.0
916.40.420.7412.80.07648.0209.00.99783.120.589.060white0.041.0
927.90.330.2831.60.05335.0176.01.01033.150.388.860white0.131.0
939.60.50.362.80.115999999999999926.055.00.997223.180.6810.950red0.091.0
948.90.320.312.00.08812.019.00.99573.170.5510.460red0.01.0
957.71.0050.152.10.10211.032.00.996043.230.4810.050red0.111.0
9610.50.390.462.20.07514.027.00.995983.060.8411.460red0.181.0
977.00.50.141.80.07810.023.00.996363.530.6110.450red0.081.0
986.40.7950.02.20.06528.052.00.993783.490.5211.650red0.171.0
9910.10.370.342.40.0855.017.00.996833.170.6510.671red0.161.0
1007.30.910.11.80.07420.056.00.996723.350.569.250red0.121.0
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
Decimal(11, 1)
123
prediction_00
Double
123
prediction_10
Double
19.20.160.492.00.04418.0107.00.995143.10.5310.240white0.121.00.7896586364220220.789658636422022
27.00.160.267.30.04730.0220.00.996223.380.5810.160white0.11.00.83482995118021470.8348299511802147
38.20.240.32.30.0523.0106.00.993972.980.510.050white0.071.00.82116536852930180.8211653685293018
48.10.40.327.90.03123.0118.00.991763.050.4613.371white0.041.00.78845739462098720.7884573946209872
57.30.220.261.50.0432.0172.00.991943.270.4811.260white0.131.00.83038748727519960.8303874872751996
66.40.350.355.60.0349.0148.00.994413.170.59.840white0.131.00.82116536852930180.8211653685293018
78.00.260.284.80.0534.0150.00.994373.130.510.060white0.11.00.82116536852930180.8211653685293018
86.60.260.271.50.0419.0114.00.992953.360.6210.560white0.021.00.82116536852930180.8211653685293018
97.80.320.3310.40.03147.0194.00.996923.070.589.660white0.021.00.82906956944957480.8290695694495748
106.60.330.2416.050.04531.0147.00.998223.080.529.250white0.061.00.84550473687430450.8455047368743045
117.50.270.7911.950.0451.0159.00.998392.980.448.750white0.121.00.82906956944957480.8290695694495748
126.10.270.311.50.03517.083.00.990763.320.4411.171white0.161.00.75621383051324750.7562138305132475
136.30.270.377.90.04758.0215.00.995423.190.489.560white0.161.00.82906956944957480.8290695694495748
146.30.270.377.90.04758.0215.00.995423.190.489.560white0.071.00.82906956944957480.8290695694495748
156.40.30.167.50.0555.0191.00.99593.170.499.050white0.081.00.84550473687430450.8455047368743045
166.70.240.3210.30.07937.0122.00.996623.020.458.850white0.071.00.82906956944957480.8290695694495748
177.70.390.497.70.03611.0110.00.99663.330.7610.060white0.141.00.82906956944957480.8290695694495748
186.00.20.245.30.07549.0201.00.994663.210.439.550white0.11.00.83821222544432330.8382122254443233
196.30.180.221.50.04345.0155.00.992383.190.4810.250white0.061.00.83907435493880020.8390743549388002
208.60.230.2511.30.03113.096.00.996453.110.410.850white0.151.00.80980864920606730.8098086492060673
216.80.210.3618.10.04632.0133.01.03.270.488.850white0.021.00.82906956944957480.8290695694495748
226.40.310.46.40.03939.0191.00.995133.140.529.850white0.01.00.82116536852930180.8211653685293018
235.60.1750.290.80.04320.067.00.991123.280.489.960white0.061.00.75621383051324750.7562138305132475
246.90.340.34.70.02934.0148.00.991653.360.4912.371white0.011.00.70946654506154830.7094665450615483
257.10.320.294.00.03833.0170.00.994633.270.6410.260white0.121.00.82116536852930180.8211653685293018
267.30.510.2911.30.03461.0224.00.996833.140.569.560white0.031.00.82906956944957480.8290695694495748
276.40.160.371.50.03727.0109.00.993453.380.59.860white0.061.00.7896586364220220.789658636422022
285.90.280.148.60.03230.0142.00.995423.280.449.560white0.171.00.8315687737272220.831568773727222
296.20.270.181.50.02820.0111.00.992283.410.510.050white0.091.00.80224003710089280.8022400371008928
306.90.320.31.80.03628.0117.00.992693.240.4811.060white0.191.00.82116536852930180.8211653685293018
316.20.330.144.80.05227.0128.00.994753.210.489.450white0.061.00.83821222544432330.8382122254443233
326.40.150.441.20.04367.0150.00.99073.140.7311.271white0.171.00.75621383051324750.7562138305132475
337.60.230.6412.90.03354.0170.00.9983.00.538.850white0.051.00.82906956944957480.8290695694495748
346.30.130.421.10.04363.0146.00.990663.130.7211.271white0.071.00.75621383051324750.7562138305132475
356.90.280.2210.00.05236.0131.00.996963.080.469.650white0.091.00.84550473687430450.8455047368743045
366.90.320.262.30.0311.0103.00.991063.060.4211.160white0.171.00.70946654506154830.7094665450615483
376.90.210.241.80.02117.080.00.989923.150.4612.371white0.181.00.74206018445034840.7420601844503484
385.10.140.250.70.03915.089.00.99193.220.439.260white0.141.00.8196754776615960.819675477661596
397.30.320.291.50.03832.0144.00.992963.20.5510.850white0.021.00.82116536852930180.8211653685293018
406.40.220.341.40.02356.0115.00.989583.180.711.760white0.191.00.75621383051324750.7562138305132475
416.80.110.421.10.04251.0132.00.990593.180.7411.371white0.081.00.75621383051324750.7562138305132475
427.10.20.30.90.0194.028.00.989313.20.3612.060white0.021.00.75621383051324750.7562138305132475
437.20.20.362.50.02822.0157.00.99383.480.4910.660white0.051.00.79373736724075110.7937373672407511
448.90.260.338.10.02447.0202.00.995583.130.4610.860white0.011.00.82906956944957480.8290695694495748
456.70.30.292.80.02537.0107.00.991593.310.6311.371white0.081.00.70946654506154830.7094665450615483
466.50.180.4114.20.03947.0129.00.996783.280.7210.371white0.081.00.7896586364220220.789658636422022
475.80.60.01.30.04472.0197.00.992023.560.4310.950white0.071.00.83038748727519960.8303874872751996
488.70.310.7314.350.04427.0191.01.000132.960.888.750white0.121.00.82906956944957480.8290695694495748
496.40.280.2711.00.04245.0148.00.997863.140.468.750white0.051.00.82906956944957480.8290695694495748
506.80.190.235.10.03471.0204.00.99423.230.6910.150white0.031.00.8201359259316220.820135925931622
515.80.180.281.30.0349.094.00.990923.210.5211.260white0.011.00.75621383051324750.7562138305132475
525.60.320.337.40.03725.095.00.992683.250.4911.160white0.151.00.82116536852930180.8211653685293018
538.90.30.354.60.03232.0148.00.994583.150.4511.571white0.151.00.82116536852930180.8211653685293018
546.70.640.31.20.0318.076.00.98923.160.612.940white0.031.00.75621383051324750.7562138305132475
557.80.290.293.150.04441.0117.00.991533.240.3511.550white0.011.00.70946654506154830.7094665450615483
566.20.2550.271.30.03730.086.00.988343.050.5912.971white0.171.00.75621383051324750.7562138305132475
576.00.160.221.60.04236.0106.00.99053.240.3211.460white0.021.00.75621383051324750.7562138305132475
586.60.210.295.350.02943.0106.00.991122.930.4311.571white0.081.00.70946654506154830.7094665450615483
595.80.540.01.40.03340.0107.00.989183.260.3512.450white0.131.00.75621383051324750.7562138305132475
606.80.190.49.850.05541.0103.00.995322.980.5610.560white0.091.00.7896586364220220.789658636422022
616.90.290.417.80.04652.0171.00.995373.120.519.650white0.181.00.82906956944957480.8290695694495748
626.20.370.246.10.03219.086.00.989343.040.2613.481white0.11.00.70946654506154830.7094665450615483
636.90.280.331.20.03916.098.00.99043.070.3911.760white0.021.00.75621383051324750.7562138305132475
646.00.280.2715.50.03631.0134.00.994083.190.4413.071white0.061.00.82116536852930180.8211653685293018
656.30.220.282.40.04238.0102.00.989983.140.3711.671white0.161.00.70946654506154830.7094665450615483
666.00.280.2715.50.03631.0134.00.994083.190.4413.071white0.071.00.82116536852930180.8211653685293018
676.00.230.159.70.048101.0207.00.995713.050.39.150white0.01.00.84550473687430450.8455047368743045
688.90.270.280.80.02429.0128.00.989843.010.3512.460white0.021.00.75621383051324750.7562138305132475
697.20.310.357.20.04645.0178.00.99553.140.539.750white0.041.00.82906956944957480.8290695694495748
707.30.20.2919.50.03969.0237.01.000373.10.489.260white0.031.00.80256236737456170.8025623673745617
716.00.330.21.80.03149.0159.00.99193.410.5311.060white0.031.00.78891819827549850.7889181982754985
725.70.220.2216.650.04439.0110.00.998553.240.489.060white0.111.00.84550473687430450.8455047368743045
735.70.220.2216.650.04439.0110.00.998553.240.489.060white0.191.00.84550473687430450.8455047368743045
746.60.640.284.40.03219.078.00.990363.110.6212.960white0.181.00.70946654506154830.7094665450615483
757.00.480.124.50.0523.086.00.993982.860.359.050white0.041.00.83821222544432330.8382122254443233
766.90.260.274.20.03120.080.00.990893.120.3911.560white0.131.00.70946654506154830.7094665450615483
777.60.380.284.20.0297.0112.00.99063.00.4112.660white0.031.00.70946654506154830.7094665450615483
787.20.260.247.00.02319.0130.00.991763.140.4912.871white0.01.00.70946654506154830.7094665450615483
796.80.190.7117.50.04221.0114.00.997842.850.59.560white0.151.00.7896586364220220.789658636422022
805.80.20.241.40.03365.0169.00.990433.590.5612.371white0.111.00.75621383051324750.7562138305132475
816.60.390.389.70.05349.0226.00.997873.30.579.460white0.111.00.82906956944957480.8290695694495748
826.60.260.247.20.03828.0137.00.99523.350.610.460white0.061.00.83821222544432330.8382122254443233
837.00.160.2514.30.04427.0149.00.9982.910.469.260white0.161.00.80065613242671860.8006561324267186
847.10.270.2412.60.04448.0118.00.997263.040.5610.071white0.171.00.84550473687430450.8455047368743045
857.70.320.6111.80.04166.0188.00.997943.00.549.350white0.031.00.82906956944957480.8290695694495748
867.00.290.330.90.04120.0117.00.990483.210.511.450white0.161.00.75621383051324750.7562138305132475
877.60.310.278.80.02157.0156.00.994423.080.3811.071white0.131.00.82116536852930180.8211653685293018
886.00.250.45.70.05256.0152.00.993983.160.8810.560white0.131.00.82116536852930180.8211653685293018
897.30.310.256.650.03230.0138.00.992442.90.3711.150white0.091.00.82375557382230640.8237555738223064
906.90.190.64.00.0376.0122.00.992552.920.5910.440white0.071.00.7896586364220220.789658636422022
916.30.320.1717.750.0651.0190.00.999163.130.488.860white0.041.00.84550473687430450.8455047368743045
926.30.320.1717.750.0651.0190.00.999163.130.488.860white0.131.00.84550473687430450.8455047368743045
937.10.260.325.90.03739.097.00.99343.310.411.660white0.091.00.82116536852930180.8211653685293018
946.90.30.334.10.03526.0155.00.99253.250.7912.381white0.01.00.82116536852930180.8211653685293018
958.10.290.497.10.04222.0124.00.99443.140.4110.860white0.111.00.82116536852930180.8211653685293018
966.60.230.261.30.04516.0128.00.99343.360.610.060white0.181.00.83821222544432330.8382122254443233
979.20.280.4911.80.04229.0137.00.9983.10.3410.140white0.081.00.82906956944957480.8290695694495748
988.20.180.491.10.03328.081.00.99233.00.6810.471white0.171.00.79477846857744920.7947784685774492
998.50.560.7417.850.05151.0243.01.00052.990.79.250white0.161.00.82906956944957480.8290695694495748
1006.30.230.497.10.0567.0210.00.99513.230.349.550white0.121.00.82116536852930180.8211653685293018
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

Tree models can be visualized by drawing their tree plots. For more examples, check out Machine Learning - Tree Plots.

model.plot_tree()
../_images/machine_learning_VAST_tree_gb_classifier_.png

Note

The above example may not render properly in the doc because of the huge size of the tree. But it should render nicely in jupyter environment.

In order to plot graph using graphviz separately, you can extract the graphviz DOT file code as follows:

model.to_graphviz()

This string can then be copied into a DOT file which can beparsed by graphviz.

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({'max_depth': 5})

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 preceding methods for exporting the model use MemModel, and it is recommended to use MemModel directly.

To SQL

You can get the SQL query equivalent of the GradientBoosting model by:

model.to_sql()

Note

This SQL query can be directly used in any database.

Deploy SQL

To get the SQL query which uses VAST functions use below:

model.deploySQL()

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, ...])

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

confusion_matrix([pos_label, cutoff])

Computes the model confusion matrix.

contour([pos_label, nbins, chart])

Draws the model's contour plot.

cutoff_curve([pos_label, nbins, show, chart])

Draws the model Cutoff curve.

deploySQL([X, pos_label, cutoff, allSQL])

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([tree_id, 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.

get_tree([tree_id])

Returns a table with all the input tree information.

import_models(path[, schema, kind])

Imports machine learning models.

lift_chart([pos_label, nbins, show, chart])

Draws the model Lift Chart.

plot([max_nb_points, chart])

Draws the model.

plot_tree([tree_id, pic_path])

Draws the input tree.

prc_curve([pos_label, nbins, show, chart])

Draws the model PRC curve.

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

Predicts using the input relation.

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

Returns the model's probabilities using the input relation.

report([metrics, cutoff, labels, nbins])

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

roc_curve([pos_label, nbins, show, chart])

Draws the model ROC curve.

score([metric, average, pos_label, cutoff, ...])

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_graphviz([tree_id, classes_color, ...])

Returns the code for a Graphviz tree.

to_json([path])

Creates a Python GradientBoosting JSON file that can be imported into the Python GradientBoosting API.

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