vastorbit.machine_learning.vast.linear_model.LogisticRegression¶
- class vastorbit.machine_learning.vast.linear_model.LogisticRegression(name: str = None, overwrite_model: bool = False, **kwargs)¶
Creates a
LogisticRegressionobject usingscikit-learnfor 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-learnmodel 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 fromvastorbitare 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()
123fixed_acidityDecimal(6, 3)123volatile_acidityDecimal(7, 4)123citric_acidDecimal(6, 3)123residual_sugarDecimal(7, 3)123chloridesDouble123free_sulfur_dioxideDecimal(7, 2)123total_sulfur_dioxideDecimal(7, 2)123densityDouble123phDecimal(6, 3)123sulphatesDecimal(6, 3)123alcoholDouble123qualityInteger123goodIntegerAbccolorVarchar(20)1 6.3 0.67 0.48 12.6 0.052 57.0 222.0 0.9979 3.17 0.52 9.3 6 0 white 2 7.4 0.4 0.29 5.4 0.044 31.0 122.0 0.994 3.3 0.5 11.1 8 1 white 3 7.1 0.26 0.31 2.2 0.044 29.0 128.0 0.9937 3.34 0.64 10.9 8 1 white 4 9.0 0.31 0.48 6.6 0.043 11.0 73.0 0.9938 2.9 0.38 11.6 5 0 white 5 6.3 0.39 0.24 6.9 0.069 9.0 117.0 0.9942 3.15 0.35 10.2 4 0 white 6 8.2 0.22 0.36 6.8 0.034 12.0 90.0 0.9944 3.01 0.38 10.5 8 1 white 7 7.1 0.19 0.28 3.6 0.033 16.0 78.0 0.993 2.91 0.78 11.4 6 0 white 8 7.3 0.25 0.36 13.1 0.05 35.0 200.0 0.9986 3.04 0.46 8.9 7 1 white 9 7.9 0.2 0.34 1.2 0.04 29.0 118.0 0.9932 3.14 0.41 10.6 6 0 white 10 7.1 0.26 0.32 5.9 0.037 39.0 97.0 0.9934 3.31 0.4 11.6 6 0 white 11 7.0 0.2 0.34 5.7 0.035 32.0 83.0 0.9928 3.19 0.46 11.5 6 0 white 12 6.9 0.3 0.33 4.1 0.035 26.0 155.0 0.9925 3.25 0.79 12.3 8 1 white 13 8.1 0.29 0.49 7.1 0.042 22.0 124.0 0.9944 3.14 0.41 10.8 6 0 white 14 5.8 0.17 0.3 1.4 0.037 55.0 130.0 0.9909 3.29 0.38 11.3 6 0 white 15 5.9 0.415 0.02 0.8 0.038 22.0 63.0 0.9932 3.36 0.36 9.3 5 0 white 16 6.6 0.23 0.26 1.3 0.045 16.0 128.0 0.9934 3.36 0.6 10.0 6 0 white 17 8.6 0.55 0.35 15.55 0.057 35.5 366.5 1.0001 3.04 0.63 11.0 3 0 white 18 6.9 0.35 0.74 1.0 0.044 18.0 132.0 0.992 3.13 0.55 10.2 5 0 white 19 7.6 0.14 0.74 1.6 0.04 27.0 103.0 0.9916 3.07 0.4 10.8 7 1 white 20 9.2 0.28 0.49 11.8 0.042 29.0 137.0 0.998 3.1 0.34 10.1 4 0 white 21 6.2 0.18 0.49 4.5 0.047 17.0 90.0 0.9919 3.27 0.37 11.6 6 0 white 22 5.3 0.165 0.24 1.1 0.051 25.0 105.0 0.9925 3.32 0.47 9.1 5 0 white 23 9.8 0.25 0.74 10.0 0.056 36.0 225.0 0.9977 3.06 0.43 10.0 4 0 white 24 8.1 0.29 0.49 7.1 0.042 22.0 124.0 0.9944 3.14 0.41 10.8 6 0 white 25 6.8 0.22 0.49 0.9 0.052 26.0 128.0 0.991 3.25 0.35 11.4 6 0 white 26 7.2 0.22 0.49 1.0 0.045 34.0 140.0 0.99 3.05 0.34 12.7 6 0 white 27 7.4 0.25 0.49 1.1 0.042 35.0 156.0 0.9917 3.13 0.55 11.3 5 0 white 28 8.2 0.18 0.49 1.1 0.033 28.0 81.0 0.9923 3.0 0.68 10.4 7 1 white 29 6.1 0.22 0.49 1.5 0.051 18.0 87.0 0.9928 3.3 0.46 9.6 5 0 white 30 7.0 0.39 0.24 1.0 0.048 8.0 119.0 0.9923 3.0 0.31 10.1 4 0 white 31 6.1 0.22 0.49 1.5 0.051 18.0 87.0 0.9928 3.3 0.46 9.6 5 0 white 32 6.5 0.36 0.49 2.9 0.03 16.0 94.0 0.9902 3.1 0.49 12.1 7 1 white 33 7.1 0.29 0.49 1.2 0.031 32.0 99.0 0.9893 3.07 0.33 12.2 6 0 white 34 7.4 0.25 0.49 1.1 0.042 35.0 156.0 0.9917 3.13 0.55 11.3 5 0 white 35 6.9 0.23 0.24 14.2 0.053 19.0 94.0 0.9982 3.17 0.5 9.6 5 0 white 36 8.5 0.56 0.74 17.85 0.051 51.0 243.0 1.0005 2.99 0.7 9.2 5 0 white 37 8.2 0.18 0.49 1.1 0.033 28.0 81.0 0.9923 3.0 0.68 10.4 7 1 white 38 6.3 0.23 0.49 7.1 0.05 67.0 210.0 0.9951 3.23 0.34 9.5 5 0 white 39 6.1 0.25 0.49 7.6 0.052 67.0 226.0 0.9956 3.16 0.47 8.9 5 0 white 40 7.2 0.26 0.74 13.6 0.05 56.0 162.0 0.998 3.03 0.44 8.8 5 0 white 41 7.2 0.31 0.24 1.4 0.057 17.0 117.0 0.9928 3.16 0.35 10.5 5 0 white 42 8.0 0.25 0.49 1.2 0.061 27.0 117.0 0.9938 3.08 0.34 9.4 5 0 white 43 7.0 0.18 0.49 5.3 0.04 34.0 125.0 0.9914 3.24 0.4 12.2 6 0 white 44 7.8 0.43 0.49 13.0 0.033 37.0 158.0 0.9955 3.14 0.35 11.3 6 0 white 45 8.3 0.2 0.74 4.45 0.044 33.0 130.0 0.9924 3.25 0.42 12.2 6 0 white 46 6.3 0.27 0.49 1.2 0.063 35.0 92.0 0.9911 3.38 0.42 12.2 6 0 white 47 7.4 0.16 0.49 1.2 0.055 18.0 150.0 0.9917 3.23 0.47 11.2 6 0 white 48 7.4 0.16 0.49 1.2 0.055 18.0 150.0 0.9917 3.23 0.47 11.2 6 0 white 49 6.9 0.19 0.49 6.6 0.036 49.0 172.0 0.9932 3.2 0.27 11.5 6 0 white 50 7.8 0.43 0.49 13.0 0.033 37.0 158.0 0.9955 3.14 0.35 11.3 6 0 white 51 7.2 0.4 0.49 1.1 0.048 11.0 138.0 0.9929 3.01 0.42 9.3 5 0 white 52 7.8 0.43 0.49 13.0 0.033 37.0 158.0 0.9955 3.14 0.35 11.3 6 0 white 53 7.6 0.52 0.49 14.0 0.034 37.0 156.0 0.9958 3.14 0.38 11.8 7 1 white 54 8.3 0.21 0.49 19.8 0.054 50.0 231.0 1.0012 2.99 0.54 9.2 5 0 white 55 6.9 0.34 0.74 11.2 0.069 44.0 150.0 0.9968 3.0 0.81 9.2 5 0 white 56 6.3 0.27 0.49 1.2 0.063 35.0 92.0 0.9911 3.38 0.42 12.2 6 0 white 57 8.3 0.2 0.74 4.45 0.044 33.0 130.0 0.9924 3.25 0.42 12.2 6 0 white 58 7.1 0.22 0.74 2.7 0.044 42.0 144.0 0.991 3.31 0.41 12.2 6 0 white 59 7.9 0.11 0.49 4.5 0.048 27.0 133.0 0.9946 3.24 0.42 10.6 6 0 white 60 8.5 0.17 0.74 3.6 0.05 29.0 128.0 0.9928 3.28 0.4 12.4 6 0 white 61 6.4 0.145 0.49 5.4 0.048 54.0 164.0 0.9946 3.56 0.44 10.8 6 0 white 62 7.4 0.16 0.49 1.2 0.055 18.0 150.0 0.9917 3.23 0.47 11.2 6 0 white 63 8.3 0.19 0.49 1.2 0.051 11.0 137.0 0.9918 3.06 0.46 11.0 6 0 white 64 8.0 0.44 0.49 9.1 0.031 46.0 151.0 0.9926 3.16 0.27 12.7 8 1 white 65 7.0 0.2 0.74 0.8 0.044 19.0 163.0 0.9931 3.46 0.53 10.2 5 0 white 66 6.9 0.19 0.49 6.6 0.036 49.0 172.0 0.9932 3.2 0.27 11.5 6 0 white 67 7.1 0.25 0.49 3.0 0.03 30.0 96.0 0.9903 3.13 0.39 12.3 7 1 white 68 6.5 0.24 0.24 1.6 0.046 15.0 60.0 0.9928 3.19 0.39 9.8 5 0 white 69 7.2 0.4 0.49 1.1 0.048 11.0 138.0 0.9929 3.01 0.42 9.3 5 0 white 70 7.6 0.52 0.49 14.0 0.034 37.0 156.0 0.9958 3.14 0.38 11.8 7 1 white 71 7.8 0.43 0.49 13.0 0.033 37.0 158.0 0.9955 3.14 0.35 11.3 6 0 white 72 7.8 0.21 0.49 1.35 0.052 6.0 48.0 0.9911 3.15 0.28 11.4 5 0 white 73 7.0 0.2 0.49 5.9 0.038 39.0 128.0 0.9938 3.21 0.48 10.8 6 0 white 74 6.9 0.25 0.24 3.6 0.057 13.0 85.0 0.9942 2.99 0.48 9.5 4 0 white 75 7.2 0.08 0.49 1.3 0.05 18.0 148.0 0.9945 3.46 0.44 10.2 6 0 white 76 7.1 0.85 0.49 8.7 0.028 40.0 184.0 0.9962 3.22 0.36 10.7 5 0 white 77 7.6 0.51 0.24 1.2 0.04 10.0 104.0 0.992 3.05 0.29 10.8 6 0 white 78 7.9 0.22 0.24 4.6 0.044 39.0 159.0 0.9927 2.99 0.28 11.5 6 0 white 79 7.7 0.16 0.49 2.0 0.056 20.0 124.0 0.9948 3.32 0.49 10.7 6 0 white 80 7.2 0.08 0.49 1.3 0.05 18.0 148.0 0.9945 3.46 0.44 10.2 6 0 white 81 6.6 0.25 0.24 1.7 0.048 26.0 124.0 0.9942 3.37 0.6 10.1 6 0 white 82 6.7 0.16 0.49 2.4 0.046 57.0 187.0 0.9952 3.62 0.81 10.4 6 0 white 83 6.9 0.25 0.24 3.6 0.057 13.0 85.0 0.9942 2.99 0.48 9.5 4 0 white 84 7.5 0.32 0.24 4.6 0.053 8.0 134.0 0.9958 3.14 0.5 9.1 3 0 white 85 7.4 0.28 0.49 1.5 0.034 20.0 126.0 0.9918 2.98 0.39 10.6 6 0 white 86 6.2 0.15 0.49 0.9 0.033 17.0 51.0 0.9932 3.3 0.7 9.4 6 0 white 87 6.7 0.25 0.74 19.4 0.054 44.0 169.0 1.0004 3.51 0.45 9.8 6 0 white 88 6.5 0.26 0.74 13.3 0.044 68.0 224.0 0.9972 3.18 0.54 9.5 6 0 white 89 7.9 0.16 0.74 17.85 0.037 52.0 187.0 0.9998 2.99 0.41 9.3 5 0 white 90 5.6 0.185 0.49 1.1 0.03 28.0 117.0 0.9918 3.55 0.45 10.3 6 0 white 91 7.5 0.2 0.49 1.3 0.031 8.0 97.0 0.9918 3.06 0.62 11.1 5 0 white 92 8.0 0.3 0.49 9.4 0.046 47.0 188.0 0.9964 3.14 0.48 10.0 5 0 white 93 8.0 0.34 0.49 9.0 0.033 39.0 180.0 0.9936 3.13 0.38 12.3 8 1 white 94 7.7 0.35 0.49 8.65 0.033 42.0 186.0 0.9931 3.14 0.38 12.4 8 1 white 95 7.6 0.29 0.49 9.6 0.03 45.0 197.0 0.9938 3.13 0.38 12.3 7 1 white 96 6.7 0.62 0.24 1.1 0.039 6.0 62.0 0.9934 3.41 0.32 10.4 5 0 white 97 6.8 0.27 0.49 1.2 0.044 35.0 126.0 0.99 3.13 0.48 12.1 7 1 white 98 7.7 0.27 0.49 1.8 0.041 23.0 86.0 0.9914 3.16 0.42 12.5 6 0 white 99 6.7 0.51 0.24 2.1 0.043 14.0 155.0 0.9904 3.22 0.6 13.0 6 0 white 100 7.4 0.19 0.49 9.3 0.03 26.0 132.0 0.994 2.99 0.32 11.0 7 1 white Rows: 1-100 | Columns: 14Note
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 intotablesortemporary 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 thepreprocessingmodule. 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’sbalance()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
LogisticRegressionmodel:from vastorbit.machine_learning.vast import LogisticRegression
Then we can create the model:
model = LogisticRegression( tol = 1e-6, max_iter = 100, solver = 'newton-cg', fit_intercept = True, )
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
VastFrameor the name of the relation stored in the database. The test set is optional and is only used to compute the test metrics. Invastorbit, we don’t work usingXmatrices andyvectors. 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 auc 0.6670646766169173 prc_auc 0.8024514098720474 accuracy 0.7905511811023622 log_loss 0.4588865938418838 precision 0.0 recall 0.0 f1_score 0.0 mcc 0.0 informedness 0.0 markedness -0.20944881889763778 csi 0.0 Rows: 1-11 | Columns: 2Important
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
cutoffto observe the effect on different metrics:model.report(cutoff = 0.2)
value auc 0.6491468392234953 prc_auc 0.8073252152046401 accuracy 0.5921259842519685 log_loss 0.4969701130957392 precision 0.24150268336314848 recall 0.5895196506550219 f1_score 0.34263959390862947 mcc 0.14112241786423338 informedness 0.18221897822466637 markedness 0.10929452583853516 csi 0.20673813169984687 Rows: 1-11 | Columns: 2You can also use the
LinearModel.scorefunction 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", )
123fixed_acidityDecimal(6, 3)123volatile_acidityDecimal(7, 4)123citric_acidDecimal(6, 3)123residual_sugarDecimal(7, 3)123chloridesDouble123free_sulfur_dioxideDecimal(7, 2)123total_sulfur_dioxideDecimal(7, 2)123densityDouble123phDecimal(6, 3)123sulphatesDecimal(6, 3)123alcoholDouble123qualityInteger123goodIntegerAbccolorVarchar(20)123seedrandDecimal(26, 6)123predictionInteger1 6.3 0.67 0.48 12.6 0.052 57.0 222.0 0.9979 3.17 0.52 9.3 6 0 white 0.17 0 2 7.1 0.26 0.31 2.2 0.044 29.0 128.0 0.9937 3.34 0.64 10.9 8 1 white 0.15 0 3 6.3 0.39 0.24 6.9 0.069 9.0 117.0 0.9942 3.15 0.35 10.2 4 0 white 0.05 0 4 8.2 0.22 0.36 6.8 0.034 12.0 90.0 0.9944 3.01 0.38 10.5 8 1 white 0.02 0 5 7.1 0.19 0.28 3.6 0.033 16.0 78.0 0.993 2.91 0.78 11.4 6 0 white 0.09 0 6 7.3 0.25 0.36 13.1 0.05 35.0 200.0 0.9986 3.04 0.46 8.9 7 1 white 0.14 0 7 5.9 0.415 0.02 0.8 0.038 22.0 63.0 0.9932 3.36 0.36 9.3 5 0 white 0.1 0 8 6.6 0.23 0.26 1.3 0.045 16.0 128.0 0.9934 3.36 0.6 10.0 6 0 white 0.17 0 9 6.2 0.18 0.49 4.5 0.047 17.0 90.0 0.9919 3.27 0.37 11.6 6 0 white 0.13 0 10 5.3 0.165 0.24 1.1 0.051 25.0 105.0 0.9925 3.32 0.47 9.1 5 0 white 0.0 0 11 7.2 0.22 0.49 1.0 0.045 34.0 140.0 0.99 3.05 0.34 12.7 6 0 white 0.12 0 12 7.0 0.39 0.24 1.0 0.048 8.0 119.0 0.9923 3.0 0.31 10.1 4 0 white 0.0 0 13 7.1 0.29 0.49 1.2 0.031 32.0 99.0 0.9893 3.07 0.33 12.2 6 0 white 0.1 0 14 6.9 0.23 0.24 14.2 0.053 19.0 94.0 0.9982 3.17 0.5 9.6 5 0 white 0.07 0 15 8.5 0.56 0.74 17.85 0.051 51.0 243.0 1.0005 2.99 0.7 9.2 5 0 white 0.17 0 16 7.2 0.4 0.49 1.1 0.048 11.0 138.0 0.9929 3.01 0.42 9.3 5 0 white 0.11 0 17 8.3 0.2 0.74 4.45 0.044 33.0 130.0 0.9924 3.25 0.42 12.2 6 0 white 0.05 0 18 7.1 0.22 0.74 2.7 0.044 42.0 144.0 0.991 3.31 0.41 12.2 6 0 white 0.06 0 19 6.9 0.19 0.49 6.6 0.036 49.0 172.0 0.9932 3.2 0.27 11.5 6 0 white 0.07 0 20 7.1 0.25 0.49 3.0 0.03 30.0 96.0 0.9903 3.13 0.39 12.3 7 1 white 0.0 0 21 7.6 0.52 0.49 14.0 0.034 37.0 156.0 0.9958 3.14 0.38 11.8 7 1 white 0.15 0 22 7.9 0.22 0.24 4.6 0.044 39.0 159.0 0.9927 2.99 0.28 11.5 6 0 white 0.17 0 23 7.2 0.08 0.49 1.3 0.05 18.0 148.0 0.9945 3.46 0.44 10.2 6 0 white 0.02 0 24 6.9 0.25 0.24 3.6 0.057 13.0 85.0 0.9942 2.99 0.48 9.5 4 0 white 0.01 0 25 7.5 0.2 0.49 1.3 0.031 8.0 97.0 0.9918 3.06 0.62 11.1 5 0 white 0.1 0 26 8.0 0.34 0.49 9.0 0.033 39.0 180.0 0.9936 3.13 0.38 12.3 8 1 white 0.0 0 27 7.6 0.29 0.49 9.6 0.03 45.0 197.0 0.9938 3.13 0.38 12.3 7 1 white 0.06 0 28 7.7 0.27 0.49 1.8 0.041 23.0 86.0 0.9914 3.16 0.42 12.5 6 0 white 0.09 0 29 6.7 0.51 0.24 2.1 0.043 14.0 155.0 0.9904 3.22 0.6 13.0 6 0 white 0.13 0 30 8.1 0.2 0.49 8.1 0.051 51.0 205.0 0.9954 3.1 0.52 11.0 6 0 white 0.16 0 31 7.3 0.155 0.49 1.3 0.039 34.0 136.0 0.9926 3.14 0.77 10.5 6 0 white 0.13 0 32 8.4 0.23 0.49 7.8 0.035 22.0 95.0 0.9935 3.04 0.34 12.0 6 0 white 0.12 0 33 7.1 0.18 0.74 15.6 0.044 44.0 176.0 0.9996 3.38 0.67 9.0 6 0 white 0.02 0 34 7.3 0.14 0.49 1.1 0.038 28.0 99.0 0.9928 3.2 0.72 10.6 6 0 white 0.15 0 35 6.7 0.29 0.49 4.7 0.034 35.0 156.0 0.9945 3.13 0.45 9.9 6 0 white 0.09 0 36 7.1 0.36 0.24 1.8 0.025 32.0 102.0 0.9903 3.34 0.59 12.8 6 0 white 0.01 0 37 7.9 0.18 0.49 5.2 0.051 36.0 157.0 0.9953 3.18 0.48 10.6 6 0 white 0.05 0 38 8.5 0.17 0.49 8.8 0.048 23.0 108.0 0.9947 2.88 0.34 10.5 4 0 white 0.15 0 39 9.0 0.3 0.49 7.2 0.039 32.0 84.0 0.9938 2.94 0.32 11.5 6 0 white 0.12 0 40 6.4 0.25 0.74 7.8 0.045 52.0 209.0 0.9956 3.21 0.42 9.2 6 0 white 0.07 0 41 9.3 0.31 0.49 1.3 0.042 34.0 147.0 0.9948 3.11 0.46 9.8 5 0 white 0.02 0 42 6.4 0.27 0.49 7.3 0.046 53.0 206.0 0.9956 3.24 0.43 9.2 6 0 white 0.14 0 43 8.2 0.26 0.49 5.2 0.04 19.0 100.0 0.9941 3.12 0.34 10.1 6 0 white 0.07 0 44 8.0 0.29 0.49 11.7 0.035 40.0 131.0 0.9958 3.14 0.34 10.8 5 0 white 0.11 0 45 7.5 0.19 0.49 1.6 0.047 42.0 140.0 0.9932 3.4 0.47 10.7 6 0 white 0.07 0 46 6.2 0.2 0.49 1.6 0.065 17.0 143.0 0.9937 3.22 0.52 9.2 6 0 white 0.11 0 47 6.4 0.37 0.49 13.3 0.045 53.0 243.0 0.9982 3.14 0.48 8.5 6 0 white 0.15 0 48 9.0 0.17 0.49 1.0 0.039 46.0 131.0 0.993 3.09 0.51 10.5 7 1 white 0.15 0 49 6.4 0.26 0.49 6.4 0.037 37.0 161.0 0.9954 3.38 0.53 9.7 6 0 white 0.18 0 50 8.2 0.2 0.49 3.5 0.057 14.0 108.0 0.9928 3.19 0.35 11.5 6 0 white 0.07 0 51 6.9 0.25 0.24 1.8 0.053 6.0 121.0 0.993 3.23 0.7 11.4 5 0 white 0.16 0 52 8.2 0.2 0.49 3.5 0.057 14.0 108.0 0.9928 3.19 0.35 11.5 6 0 white 0.06 0 53 7.6 0.47 0.49 13.0 0.239 42.0 220.0 0.9988 2.96 0.51 9.2 5 0 white 0.1 0 54 6.4 0.22 0.49 7.5 0.054 42.0 151.0 0.9948 3.27 0.52 10.1 6 0 white 0.18 0 55 8.1 0.3 0.49 12.3 0.049 50.0 144.0 0.9971 3.09 0.57 10.2 7 1 white 0.02 0 56 7.3 0.19 0.49 15.55 0.058 50.0 134.0 0.9998 3.42 0.36 9.1 7 1 white 0.06 0 57 6.6 0.46 0.49 7.4 0.052 19.0 184.0 0.9956 3.11 0.38 9.0 5 0 white 0.12 0 58 5.8 0.28 0.34 4.0 0.031 40.0 99.0 0.9896 3.39 0.39 12.8 7 1 white 0.09 0 59 7.4 0.21 0.27 1.2 0.041 27.0 99.0 0.9927 3.19 0.33 9.8 6 0 white 0.18 0 60 7.0 0.21 0.28 8.6 0.045 37.0 221.0 0.9954 3.25 0.54 10.4 6 0 white 0.04 0 61 7.8 0.21 0.27 1.2 0.051 20.0 89.0 0.9936 3.06 0.46 9.1 5 0 white 0.0 0 62 6.2 0.35 0.04 1.2 0.06 23.0 108.0 0.9934 3.26 0.54 9.2 5 0 white 0.11 0 63 7.1 0.32 0.32 11.0 0.038 16.0 66.0 0.9937 3.24 0.4 11.5 3 0 white 0.0 0 64 6.1 0.2 0.25 1.2 0.038 34.0 128.0 0.9921 3.24 0.44 10.1 5 0 white 0.06 0 65 7.2 0.29 0.53 18.15 0.047 59.0 182.0 0.9992 3.09 0.52 9.6 5 0 white 0.1 0 66 7.0 0.17 0.31 4.8 0.034 34.0 132.0 0.9944 3.36 0.48 9.6 7 1 white 0.06 0 67 7.4 0.28 0.36 1.1 0.028 42.0 105.0 0.9893 2.99 0.39 12.4 7 1 white 0.16 0 68 7.1 0.55 0.13 1.7 0.073 21.0 165.0 0.994 2.97 0.58 9.2 6 0 white 0.08 0 69 6.2 0.37 0.3 6.6 0.346 79.0 200.0 0.9954 3.29 0.58 9.6 5 0 white 0.11 0 70 7.2 0.4 0.62 10.8 0.041 70.0 189.0 0.9976 3.08 0.49 8.6 4 0 white 0.04 0 71 5.9 0.62 0.28 3.5 0.039 55.0 152.0 0.9907 3.44 0.44 12.0 6 0 white 0.06 0 72 7.4 0.36 0.33 1.4 0.025 27.0 55.0 0.9915 3.21 0.33 11.2 6 0 white 0.17 0 73 5.8 0.36 0.32 1.7 0.033 22.0 96.0 0.9898 3.03 0.38 11.2 6 0 white 0.13 0 74 5.6 0.35 0.37 1.0 0.038 6.0 72.0 0.9902 3.37 0.34 11.4 5 0 white 0.11 0 75 5.9 0.32 0.39 3.3 0.114 24.0 140.0 0.9934 3.09 0.45 9.2 6 0 white 0.02 0 76 7.4 0.25 0.36 13.2 0.067 53.0 178.0 0.9976 3.01 0.48 9.0 6 0 white 0.09 0 77 7.4 0.25 0.36 13.2 0.067 53.0 178.0 0.9976 3.01 0.48 9.0 6 0 white 0.05 0 78 6.7 0.31 0.31 9.9 0.04 10.0 175.0 0.9953 3.46 0.55 11.4 4 0 white 0.09 0 79 6.4 0.16 0.22 1.4 0.04 41.0 149.0 0.9933 3.49 0.58 10.0 6 0 white 0.06 0 80 7.0 0.3 0.51 13.6 0.05 40.0 168.0 0.9976 3.07 0.52 9.6 7 1 white 0.16 0 81 7.8 0.28 0.34 1.6 0.028 32.0 118.0 0.9901 3.0 0.38 12.1 7 1 white 0.09 0 82 7.7 0.34 0.27 8.8 0.063 39.0 184.0 0.9969 3.09 0.63 9.2 6 0 white 0.11 0 83 6.5 0.28 0.27 5.2 0.04 44.0 179.0 0.9948 3.19 0.69 9.4 6 0 white 0.14 0 84 7.1 0.22 0.33 2.8 0.033 48.0 153.0 0.9899 3.15 0.38 12.7 7 1 white 0.1 0 85 7.4 0.26 0.3 7.9 0.049 38.0 157.0 0.9963 3.13 0.48 8.9 6 0 white 0.13 0 86 7.1 0.31 0.5 14.5 0.059 6.0 148.0 0.9983 2.94 0.44 9.1 5 0 white 0.03 0 87 6.4 0.45 0.07 1.1 0.03 10.0 131.0 0.9905 2.97 0.28 10.8 5 0 white 0.13 0 88 6.4 0.475 0.06 1.0 0.03 9.0 131.0 0.9904 2.97 0.29 10.8 5 0 white 0.07 0 89 6.3 0.26 0.49 1.5 0.052 34.0 134.0 0.9924 2.99 0.61 9.8 6 0 white 0.03 0 90 7.3 0.25 0.29 7.5 0.049 38.0 158.0 0.9965 3.43 0.38 9.6 5 0 white 0.12 0 91 6.1 0.28 0.25 17.75 0.044 48.0 161.0 0.9993 3.34 0.48 9.5 5 0 white 0.14 0 92 7.5 0.23 0.68 11.0 0.047 37.0 133.0 0.9978 2.99 0.38 8.8 5 0 white 0.05 0 93 7.5 0.21 0.68 10.9 0.045 38.0 133.0 0.9978 3.0 0.36 8.7 5 0 white 0.17 0 94 7.8 0.26 0.27 1.9 0.051 52.0 195.0 0.9928 3.23 0.5 10.9 6 0 white 0.05 0 95 6.0 0.36 0.06 1.4 0.066 27.0 128.0 0.9934 3.26 0.55 9.3 5 0 white 0.01 0 96 6.2 0.17 0.28 4.7 0.037 39.0 133.0 0.9931 3.41 0.46 10.8 7 1 white 0.0 0 97 7.4 0.105 0.34 12.2 0.05 57.0 146.0 0.9973 3.16 0.37 9.0 6 0 white 0.05 0 98 7.1 0.26 0.34 14.4 0.067 35.0 189.0 0.9986 3.07 0.53 9.1 7 1 white 0.03 0 99 6.7 0.26 0.49 8.3 0.047 54.0 191.0 0.9954 3.23 0.4 10.3 6 0 white 0.16 0 100 6.2 0.27 0.32 8.8 0.047 65.0 224.0 0.9961 3.17 0.47 8.9 5 0 white 0.06 0 Rows: 1-100 | Columns: 16Note
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
VastFrameto thepredict()function, but in this case, it’s essential that the column names of theVastFramematch 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", )
123fixed_acidityDecimal(6, 3)123volatile_acidityDecimal(7, 4)123citric_acidDecimal(6, 3)123residual_sugarDecimal(7, 3)123chloridesDouble123free_sulfur_dioxideDecimal(7, 2)123total_sulfur_dioxideDecimal(7, 2)123densityDouble123phDecimal(6, 3)123sulphatesDecimal(6, 3)123alcoholDouble123qualityInteger123goodIntegerAbccolorVarchar(20)123seedrandDecimal(26, 6)123predictionInteger123prediction_0Double123prediction_1Double1 6.3 0.67 0.48 12.6 0.052 57.0 222.0 0.9979 3.17 0.52 9.3 6 0 white 0.17 0 0.925067006160138 0.07493299383986202 2 7.1 0.26 0.31 2.2 0.044 29.0 128.0 0.9937 3.34 0.64 10.9 8 1 white 0.15 0 0.7405609859764279 0.259439014023572 3 6.3 0.39 0.24 6.9 0.069 9.0 117.0 0.9942 3.15 0.35 10.2 4 0 white 0.05 0 0.8550916211318254 0.1449083788681747 4 8.2 0.22 0.36 6.8 0.034 12.0 90.0 0.9944 3.01 0.38 10.5 8 1 white 0.02 0 0.7708653981246472 0.2291346018753528 5 7.1 0.19 0.28 3.6 0.033 16.0 78.0 0.993 2.91 0.78 11.4 6 0 white 0.09 0 0.7195667162520554 0.2804332837479447 6 7.3 0.25 0.36 13.1 0.05 35.0 200.0 0.9986 3.04 0.46 8.9 7 1 white 0.14 0 0.8495062129946531 0.15049378700534685 7 5.9 0.415 0.02 0.8 0.038 22.0 63.0 0.9932 3.36 0.36 9.3 5 0 white 0.1 0 0.8009155065217811 0.19908449347821885 8 6.6 0.23 0.26 1.3 0.045 16.0 128.0 0.9934 3.36 0.6 10.0 6 0 white 0.17 0 0.7193984964184351 0.2806015035815649 9 6.2 0.18 0.49 4.5 0.047 17.0 90.0 0.9919 3.27 0.37 11.6 6 0 white 0.13 0 0.7086342357782163 0.29136576422178373 10 5.3 0.165 0.24 1.1 0.051 25.0 105.0 0.9925 3.32 0.47 9.1 5 0 white 0.0 0 0.6851852285077069 0.31481477149229303 11 7.2 0.22 0.49 1.0 0.045 34.0 140.0 0.99 3.05 0.34 12.7 6 0 white 0.12 0 0.686335148491818 0.313664851508182 12 7.0 0.39 0.24 1.0 0.048 8.0 119.0 0.9923 3.0 0.31 10.1 4 0 white 0.0 0 0.7884131799945143 0.21158682000548568 13 7.1 0.29 0.49 1.2 0.031 32.0 99.0 0.9893 3.07 0.33 12.2 6 0 white 0.1 0 0.7043192821169058 0.2956807178830942 14 6.9 0.23 0.24 14.2 0.053 19.0 94.0 0.9982 3.17 0.5 9.6 5 0 white 0.07 0 0.8615829329086182 0.13841706709138174 15 8.5 0.56 0.74 17.85 0.051 51.0 243.0 1.0005 2.99 0.7 9.2 5 0 white 0.17 0 0.9265237915618592 0.07347620843814089 16 7.2 0.4 0.49 1.1 0.048 11.0 138.0 0.9929 3.01 0.42 9.3 5 0 white 0.11 0 0.7687847141185151 0.23121528588148488 17 8.3 0.2 0.74 4.45 0.044 33.0 130.0 0.9924 3.25 0.42 12.2 6 0 white 0.05 0 0.7001800885733984 0.2998199114266016 18 7.1 0.22 0.74 2.7 0.044 42.0 144.0 0.991 3.31 0.41 12.2 6 0 white 0.06 0 0.6750476351507433 0.32495236484925677 19 6.9 0.19 0.49 6.6 0.036 49.0 172.0 0.9932 3.2 0.27 11.5 6 0 white 0.07 0 0.7336881244004434 0.26631187559955655 20 7.1 0.25 0.49 3.0 0.03 30.0 96.0 0.9903 3.13 0.39 12.3 7 1 white 0.0 0 0.7088617752434043 0.2911382247565957 21 7.6 0.52 0.49 14.0 0.034 37.0 156.0 0.9958 3.14 0.38 11.8 7 1 white 0.15 0 0.9021646841652253 0.09783531583477473 22 7.9 0.22 0.24 4.6 0.044 39.0 159.0 0.9927 2.99 0.28 11.5 6 0 white 0.17 0 0.7661894809958854 0.2338105190041146 23 7.2 0.08 0.49 1.3 0.05 18.0 148.0 0.9945 3.46 0.44 10.2 6 0 white 0.02 0 0.6289678361098032 0.3710321638901967 24 6.9 0.25 0.24 3.6 0.057 13.0 85.0 0.9942 2.99 0.48 9.5 4 0 white 0.01 0 0.7721411720820243 0.2278588279179757 25 7.5 0.2 0.49 1.3 0.031 8.0 97.0 0.9918 3.06 0.62 11.1 5 0 white 0.1 0 0.6674074147696039 0.33259258523039614 26 8.0 0.34 0.49 9.0 0.033 39.0 180.0 0.9936 3.13 0.38 12.3 8 1 white 0.0 0 0.8207460474289746 0.17925395257102536 27 7.6 0.29 0.49 9.6 0.03 45.0 197.0 0.9938 3.13 0.38 12.3 7 1 white 0.06 0 0.8049949111179757 0.19500508888202422 28 7.7 0.27 0.49 1.8 0.041 23.0 86.0 0.9914 3.16 0.42 12.5 6 0 white 0.09 0 0.7196637386404617 0.28033626135953826 29 6.7 0.51 0.24 2.1 0.043 14.0 155.0 0.9904 3.22 0.6 13.0 6 0 white 0.13 0 0.8328177762557853 0.16718222374421463 30 8.1 0.2 0.49 8.1 0.051 51.0 205.0 0.9954 3.1 0.52 11.0 6 0 white 0.16 0 0.7794022330382359 0.22059776696176417 31 7.3 0.155 0.49 1.3 0.039 34.0 136.0 0.9926 3.14 0.77 10.5 6 0 white 0.13 0 0.6534395926948668 0.34656040730513316 32 8.4 0.23 0.49 7.8 0.035 22.0 95.0 0.9935 3.04 0.34 12.0 6 0 white 0.12 0 0.7742469721272782 0.22575302787272183 33 7.1 0.18 0.74 15.6 0.044 44.0 176.0 0.9996 3.38 0.67 9.0 6 0 white 0.02 0 0.8125893663761938 0.1874106336238062 34 7.3 0.14 0.49 1.1 0.038 28.0 99.0 0.9928 3.2 0.72 10.6 6 0 white 0.15 0 0.6418933270491416 0.3581066729508584 35 6.7 0.29 0.49 4.7 0.034 35.0 156.0 0.9945 3.13 0.45 9.9 6 0 white 0.09 0 0.7491470455518884 0.2508529544481116 36 7.1 0.36 0.24 1.8 0.025 32.0 102.0 0.9903 3.34 0.59 12.8 6 0 white 0.01 0 0.7645840846579658 0.23541591534203424 37 7.9 0.18 0.49 5.2 0.051 36.0 157.0 0.9953 3.18 0.48 10.6 6 0 white 0.05 0 0.7363584491681201 0.26364155083187996 38 8.5 0.17 0.49 8.8 0.048 23.0 108.0 0.9947 2.88 0.34 10.5 4 0 white 0.15 0 0.7756052659181399 0.22439473408186006 39 9.0 0.3 0.49 7.2 0.039 32.0 84.0 0.9938 2.94 0.32 11.5 6 0 white 0.12 0 0.8011917975247753 0.19880820247522474 40 6.4 0.25 0.74 7.8 0.045 52.0 209.0 0.9956 3.21 0.42 9.2 6 0 white 0.07 0 0.7502887436018149 0.24971125639818512 41 9.3 0.31 0.49 1.3 0.042 34.0 147.0 0.9948 3.11 0.46 9.8 5 0 white 0.02 0 0.7450524355610979 0.2549475644389021 42 6.4 0.27 0.49 7.3 0.046 53.0 206.0 0.9956 3.24 0.43 9.2 6 0 white 0.14 0 0.7804786844454522 0.2195213155545478 43 8.2 0.26 0.49 5.2 0.04 19.0 100.0 0.9941 3.12 0.34 10.1 6 0 white 0.07 0 0.7601074151215768 0.2398925848784233 44 8.0 0.29 0.49 11.7 0.035 40.0 131.0 0.9958 3.14 0.34 10.8 5 0 white 0.11 0 0.8314233509901761 0.168576649009824 45 7.5 0.19 0.49 1.6 0.047 42.0 140.0 0.9932 3.4 0.47 10.7 6 0 white 0.07 0 0.6860256351340668 0.3139743648659332 46 6.2 0.2 0.49 1.6 0.065 17.0 143.0 0.9937 3.22 0.52 9.2 6 0 white 0.11 0 0.7002530130180978 0.29974698698190216 47 6.4 0.37 0.49 13.3 0.045 53.0 243.0 0.9982 3.14 0.48 8.5 6 0 white 0.15 0 0.8656320856772401 0.1343679143227598 48 9.0 0.17 0.49 1.0 0.039 46.0 131.0 0.993 3.09 0.51 10.5 7 1 white 0.15 0 0.6720682652888317 0.3279317347111683 49 6.4 0.26 0.49 6.4 0.037 37.0 161.0 0.9954 3.38 0.53 9.7 6 0 white 0.18 0 0.7578362716475279 0.24216372835247216 50 8.2 0.2 0.49 3.5 0.057 14.0 108.0 0.9928 3.19 0.35 11.5 6 0 white 0.07 0 0.7321723203176699 0.2678276796823301 51 6.9 0.25 0.24 1.8 0.053 6.0 121.0 0.993 3.23 0.7 11.4 5 0 white 0.16 0 0.7472356562200424 0.2527643437799576 52 8.2 0.2 0.49 3.5 0.057 14.0 108.0 0.9928 3.19 0.35 11.5 6 0 white 0.06 0 0.7321723203176699 0.2678276796823301 53 7.6 0.47 0.49 13.0 0.239 42.0 220.0 0.9988 2.96 0.51 9.2 5 0 white 0.1 0 0.9593848347180274 0.04061516528197258 54 6.4 0.22 0.49 7.5 0.054 42.0 151.0 0.9948 3.27 0.52 10.1 6 0 white 0.18 0 0.7710857028162902 0.2289142971837098 55 8.1 0.3 0.49 12.3 0.049 50.0 144.0 0.9971 3.09 0.57 10.2 7 1 white 0.02 0 0.8502580851457582 0.14974191485424185 56 7.3 0.19 0.49 15.55 0.058 50.0 134.0 0.9998 3.42 0.36 9.1 7 1 white 0.06 0 0.8481984455236817 0.1518015544763183 57 6.6 0.46 0.49 7.4 0.052 19.0 184.0 0.9956 3.11 0.38 9.0 5 0 white 0.12 0 0.849444691735979 0.150555308264021 58 5.6 0.32 0.33 7.4 0.037 25.0 95.0 0.99268 3.25 0.49 11.1 6 0 white 0.09 0 0.8015984472015294 0.19840155279847066 59 7.2 0.37 0.4 11.6 0.032 34.0 214.0 0.9963 3.1 0.51 9.8 6 0 white 0.18 0 0.8544692735563304 0.14553072644366966 60 7.1 0.18 0.39 14.5 0.051 48.0 156.0 0.99947 3.35 0.78 9.1 5 0 white 0.04 0 0.8383967732538583 0.16160322674614166 61 6.4 0.32 0.27 4.9 0.034 18.0 122.0 0.9916 3.36 0.71 12.5 6 0 white 0.0 0 0.784123380153061 0.21587661984693893 62 6.7 0.4 0.22 8.8 0.052 24.0 113.0 0.99576 3.22 0.45 9.4 5 0 white 0.11 0 0.8646845426701415 0.13531545732985856 63 6.6 0.15 0.32 6.0 0.033 59.0 128.0 0.99192 3.19 0.71 12.1 8 1 white 0.0 0 0.72332678377212 0.27667321622787994 64 6.6 0.21 0.29 5.35 0.029 43.0 106.0 0.99112 2.93 0.43 11.5 7 1 white 0.06 0 0.7401274116999939 0.2598725883000061 65 7.6 0.22 0.28 12.0 0.056 68.0 143.0 0.9983 2.99 0.3 9.2 6 0 white 0.1 0 0.8440154425849795 0.15598455741502049 66 6.5 0.3 0.27 4.0 0.038 37.0 97.0 0.99026 3.2 0.6 12.6 8 1 white 0.06 0 0.7709641712322165 0.2290358287677835 67 6.2 0.37 0.24 6.1 0.032 19.0 86.0 0.98934 3.04 0.26 13.4 8 1 white 0.16 0 0.8133208349289004 0.18667916507109963 68 6.2 0.36 0.45 10.4 0.06 22.0 184.0 0.99711 3.31 0.56 9.8 6 0 white 0.08 0 0.8524606759169375 0.14753932408306242 69 6.2 0.37 0.24 6.1 0.032 19.0 86.0 0.98934 3.04 0.26 13.4 8 1 white 0.11 0 0.8133208349289004 0.18667916507109963 70 6.1 0.33 0.3 3.0 0.036 30.0 124.0 0.98922 3.31 0.4 13.1 7 1 white 0.04 0 0.76312519004226 0.23687480995774007 71 6.7 0.29 0.45 14.3 0.054 30.0 181.0 0.99869 3.14 0.57 9.1 5 0 white 0.06 0 0.8625825496414713 0.13741745035852868 72 7.9 0.35 0.28 12.9 0.032 13.0 63.0 0.9932 2.99 0.43 13.0 6 0 white 0.17 0 0.8706090519210457 0.1293909480789543 73 6.0 0.23 0.15 9.7 0.048 101.0 207.0 0.99571 3.05 0.3 9.1 5 0 white 0.13 0 0.8223644411388416 0.17763555886115845 74 5.3 0.36 0.27 6.3 0.028 40.0 132.0 0.99186 3.37 0.4 11.6 6 0 white 0.11 0 0.8003733065794396 0.19962669342056036 75 5.3 0.36 0.27 6.3 0.028 40.0 132.0 0.99186 3.37 0.4 11.6 6 0 white 0.02 0 0.8003733065794396 0.19962669342056036 76 7.2 0.23 0.46 6.4 0.036 17.0 85.0 0.99279 3.1 0.78 11.7 6 0 white 0.09 0 0.753621589115617 0.2463784108843829 77 7.2 0.31 0.35 7.2 0.046 45.0 178.0 0.9955 3.14 0.53 9.7 5 0 white 0.05 0 0.8125062777206113 0.18749372227938865 78 7.8 0.28 0.25 3.4 0.024 27.0 99.0 0.98959 2.98 0.37 13.0 6 0 white 0.09 0 0.7541170440785165 0.2458829559214835 79 7.3 0.2 0.29 19.5 0.039 69.0 237.0 1.00037 3.1 0.48 9.2 6 0 white 0.06 0 0.8818601189648697 0.11813988103513026 80 7.2 0.14 0.32 1.1 0.022 48.0 116.0 0.99218 3.04 0.67 10.0 6 0 white 0.16 0 0.6444709858663717 0.3555290141336282 81 5.7 0.22 0.22 16.65 0.044 39.0 110.0 0.99855 3.24 0.48 9.0 6 0 white 0.09 0 0.8671800806369114 0.13281991936308854 82 7.6 0.37 0.34 3.2 0.028 42.0 162.0 0.9903 3.01 0.33 12.4 6 0 white 0.11 0 0.7797996964553179 0.2202003035446821 83 8.0 0.25 0.27 9.7 0.036 15.0 85.0 0.99406 2.99 0.36 11.2 6 0 white 0.14 0 0.8203190373408136 0.17968096265918643 84 7.3 0.23 0.27 2.6 0.035 39.0 120.0 0.99138 3.04 0.59 11.3 7 1 white 0.1 0 0.729069064211219 0.270930935788781 85 5.8 0.28 0.28 4.2 0.044 52.0 158.0 0.992 3.35 0.44 10.7 7 1 white 0.13 0 0.7653805616009228 0.23461943839907717 86 6.6 0.19 0.35 1.5 0.037 37.0 107.0 0.99006 3.18 0.68 12.0 7 1 white 0.03 0 0.6826320472382832 0.31736795276171686 87 5.6 0.28 0.28 4.2 0.044 52.0 158.0 0.992 3.35 0.44 10.7 7 1 white 0.13 0 0.7639162081710693 0.23608379182893072 88 6.8 0.19 0.32 7.6 0.049 37.0 107.0 0.99332 3.12 0.44 10.7 7 1 white 0.07 0 0.7765300674829971 0.22346993251700292 89 7.4 0.36 0.23 1.9 0.017 31.0 69.0 0.9892 2.93 0.36 12.5 6 0 white 0.03 0 0.7609937211804052 0.2390062788195948 90 6.8 0.14 0.18 1.4 0.047 30.0 90.0 0.99164 3.27 0.54 11.2 6 0 white 0.12 0 0.6935532864266438 0.3064467135733562 91 7.0 0.16 0.25 14.3 0.044 27.0 149.0 0.998 2.91 0.46 9.2 6 0 white 0.14 0 0.8363179094342419 0.16368209056575808 92 6.8 0.16 0.18 1.8 0.046 31.0 114.0 0.99226 3.27 0.55 10.8 6 0 white 0.05 0 0.70701048333542 0.29298951666458 93 7.0 0.16 0.25 14.3 0.044 27.0 149.0 0.998 2.91 0.46 9.2 6 0 white 0.17 0 0.8363179094342419 0.16368209056575808 94 7.0 0.29 0.33 0.9 0.041 20.0 117.0 0.99048 3.21 0.5 11.4 5 0 white 0.05 0 0.7304195635367168 0.26958043646328317 95 6.6 0.36 0.28 6.1 0.029 12.0 93.0 0.99054 3.19 0.27 12.8 7 1 white 0.01 0 0.8064299735582661 0.1935700264417339 96 6.5 0.26 0.39 1.4 0.02 12.0 66.0 0.99089 3.25 0.75 11.3 7 1 white 0.0 0 0.688471846277156 0.3115281537228441 97 6.4 0.29 0.24 3.2 0.037 31.0 95.0 0.98942 2.9 0.66 12.6 7 1 white 0.05 0 0.7593634483463253 0.24063655165367473 98 6.9 0.19 0.6 4.0 0.037 6.0 122.0 0.99255 2.92 0.59 10.4 4 0 white 0.03 0 0.6873228209027888 0.3126771790972111 99 6.7 0.26 0.49 8.3 0.047 54.0 191.0 0.9954 3.23 0.4 10.3 6 0 white 0.16 0 0.7903779813470129 0.20962201865298713 100 6.2 0.27 0.32 8.8 0.047 65.0 224.0 0.9961 3.17 0.47 8.9 5 0 white 0.06 0 0.8120683032808763 0.1879316967191237 Rows: 1-100 | Columns: 18Note
Probabilities are added to the
VastFrame, and vastorbit uses the corresponding probability function in SQL behind the scenes. You can use thepos_labelparameter 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
cutoffis 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 thenbins, 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
MemModelobjects 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 ascikit-learnmodel.The following methods for exporting the model use
MemModel, and it is recommended to useMemModeldirectly.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.
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.
Summarizes the model.
to_binary(path)Exports the model to the VAST Binary format.
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