vastorbit.machine_learning.vast.svm.LinearSVC¶
- class vastorbit.machine_learning.vast.svm.LinearSVC(name: str = None, overwrite_model: bool = False, **kwargs)¶
Creates an
LinearSVCobject 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.Model Initialization¶
First we import the
LinearSVCmodel: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
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.6955280685061823 prc_auc 0.3106813995161213 accuracy 0.7978642257818459 log_loss 0.5347809560170647 precision 0.0 recall 0.0 f1_score 0.0 mcc 0.0 informedness 0.0 markedness -0.2021357742181541 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.6747408175355465 prc_auc 0.795930129113751 accuracy 0.19374523264683446 log_loss 0.5521818379311714 precision 0.18754803996925443 recall 1.0 f1_score 0.31585760517799355 mcc 0.04192509498158747 informedness 0.009372071227741419 markedness 0.1875480399692544 csi 0.18754803996925443 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.8 0.37 0.51 11.8 0.044 62.0 163.0 0.9976 3.19 0.44 8.8 5 0 white 0.05 0 2 7.2 0.25 0.39 18.95 0.038 42.0 155.0 0.9999 2.97 0.47 9.0 6 0 white 0.05 0 3 7.3 0.28 0.36 12.7 0.04 38.0 140.0 0.998 3.3 0.79 9.6 6 0 white 0.11 0 4 7.0 0.21 0.28 8.7 0.045 37.0 222.0 0.9954 3.25 0.54 10.4 6 0 white 0.08 0 5 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.15 0 6 6.8 0.29 0.5 13.3 0.053 48.0 194.0 0.9974 3.09 0.45 9.4 5 0 white 0.18 0 7 6.1 0.28 0.32 2.5 0.042 23.0 218.5 0.9935 3.27 0.6 9.8 5 0 white 0.15 0 8 7.4 0.155 0.34 2.3 0.045 73.5 214.0 0.9934 3.18 0.61 9.9 7 1 white 0.1 0 9 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.02 0 10 6.9 0.24 0.36 20.8 0.031 40.0 139.0 0.9975 3.2 0.33 11.0 6 0 white 0.01 0 11 5.9 0.46 0.14 2.7 0.042 27.0 160.0 0.9931 3.46 0.51 10.6 7 1 white 0.04 0 12 6.0 0.27 0.27 1.6 0.046 32.0 113.0 0.9924 3.41 0.51 10.5 7 1 white 0.1 0 13 6.1 0.43 0.35 9.1 0.059 83.0 249.0 0.9971 3.37 0.5 8.5 5 0 white 0.14 0 14 6.8 0.32 0.21 2.2 0.044 15.0 68.0 0.9932 3.17 0.39 9.4 6 0 white 0.05 0 15 6.6 0.24 0.29 2.0 0.023 19.0 86.0 0.99 3.25 0.45 12.5 6 0 white 0.17 0 16 6.3 0.22 0.33 1.7 0.041 67.0 164.0 0.9928 3.32 0.56 10.4 6 0 white 0.06 0 17 7.1 0.23 0.39 1.6 0.032 12.0 65.0 0.9898 3.25 0.4 12.7 7 1 white 0.12 0 18 6.8 0.19 0.58 14.2 0.038 51.0 164.0 0.9975 3.12 0.48 9.6 6 0 white 0.0 0 19 7.8 0.18 0.31 12.2 0.053 46.0 140.0 0.998 3.06 0.53 8.9 6 0 white 0.12 0 20 7.8 0.34 0.35 1.8 0.042 8.0 167.0 0.9908 3.11 0.41 12.1 6 0 white 0.11 0 21 7.8 0.28 0.32 9.0 0.036 34.0 115.0 0.9952 3.17 0.39 10.3 7 1 white 0.18 0 22 5.9 0.13 0.28 1.9 0.05 20.0 78.0 0.9918 3.43 0.64 10.8 6 0 white 0.1 0 23 7.9 0.19 0.26 2.1 0.039 8.0 143.0 0.9942 3.05 0.74 9.8 5 0 white 0.13 0 24 6.9 0.25 0.4 1.3 0.038 22.0 101.0 0.9901 3.03 0.39 11.4 6 0 white 0.12 0 25 7.2 0.31 0.46 5.0 0.04 3.0 29.0 0.9906 3.04 0.53 12.5 4 0 white 0.16 0 26 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.17 0 27 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.06 0 28 7.2 0.46 0.65 10.4 0.05 76.0 192.0 0.9976 3.16 0.42 8.7 5 0 white 0.02 0 29 5.5 0.35 0.35 1.1 0.045 14.0 167.0 0.992 3.34 0.68 9.9 6 0 white 0.19 0 30 6.5 0.18 0.31 1.7 0.044 30.0 127.0 0.9928 3.49 0.5 10.2 7 1 white 0.01 0 31 9.2 0.25 0.34 1.2 0.026 31.0 93.0 0.9916 2.93 0.37 11.3 7 1 white 0.08 0 32 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.08 0 33 6.7 0.21 0.42 9.1 0.049 31.0 150.0 0.9953 3.12 0.74 9.9 7 1 white 0.08 0 34 8.2 0.22 0.3 1.8 0.047 47.0 185.0 0.9933 3.13 0.5 10.2 6 0 white 0.19 0 35 6.5 0.28 0.29 2.7 0.038 26.0 107.0 0.9912 3.32 0.41 11.6 7 1 white 0.17 0 36 7.3 0.3 0.22 6.4 0.056 44.0 168.0 0.9947 3.13 0.35 10.1 6 0 white 0.03 0 37 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.01 0 38 6.9 0.41 0.33 10.1 0.043 28.0 152.0 0.9968 3.2 0.52 9.4 5 0 white 0.0 0 39 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.05 0 40 6.9 0.41 0.33 10.1 0.043 28.0 152.0 0.9968 3.2 0.52 9.4 5 0 white 0.14 0 41 7.2 0.24 0.4 1.4 0.045 31.0 106.0 0.9914 2.88 0.38 10.8 6 0 white 0.14 0 42 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.02 0 43 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.0 0 44 7.8 0.32 0.33 2.4 0.037 18.0 101.0 0.9912 3.21 0.65 11.7 7 1 white 0.18 0 45 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.18 0 46 7.4 0.19 0.3 1.4 0.057 33.0 135.0 0.993 3.12 0.5 9.6 6 0 white 0.02 0 47 7.0 0.23 0.42 18.05 0.05 35.0 144.0 0.9999 3.22 0.42 8.8 5 0 white 0.11 0 48 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.13 0 49 5.9 0.24 0.26 12.3 0.053 34.0 134.0 0.9972 3.34 0.45 9.5 6 0 white 0.09 0 50 6.6 0.27 0.25 3.1 0.052 41.0 188.0 0.9915 3.24 0.4 11.3 5 0 white 0.11 0 51 7.1 0.17 0.38 7.4 0.052 49.0 182.0 0.9958 3.35 0.52 9.6 6 0 white 0.03 0 52 6.2 0.36 0.26 13.2 0.051 54.0 201.0 0.9976 3.25 0.46 9.0 5 0 white 0.05 0 53 7.5 0.31 0.51 14.8 0.039 62.0 204.0 0.9982 3.06 0.6 9.5 5 0 white 0.15 0 54 6.2 0.31 0.21 6.3 0.041 50.0 218.0 0.9941 3.15 0.6 10.0 5 0 white 0.08 0 55 7.2 0.18 0.45 4.4 0.046 57.0 166.0 0.9943 3.13 0.62 11.2 6 0 white 0.07 0 56 8.2 0.27 0.43 1.6 0.035 31.0 128.0 0.9916 3.1 0.5 12.3 6 0 white 0.14 0 57 7.7 0.42 0.31 9.2 0.048 22.0 221.0 0.9969 3.06 0.61 9.2 6 0 white 0.11 0 58 6.9 0.31 0.34 1.6 0.032 23.0 128.0 0.9917 3.37 0.47 11.7 6 0 white 0.1 0 59 6.6 0.33 0.31 1.3 0.02 29.0 89.0 0.99035 3.26 0.44 12.4 8 1 white 0.0 0 60 7.8 0.3 0.4 1.8 0.028 23.0 122.0 0.9914 3.14 0.39 10.9 7 1 white 0.12 0 61 6.4 0.24 0.31 2.8 0.038 41.0 114.0 0.99155 3.37 0.66 11.7 7 1 white 0.14 0 62 7.0 0.21 0.34 8.0 0.057 19.0 101.0 0.9954 2.99 0.59 9.4 5 0 white 0.19 0 63 6.4 0.16 0.31 5.3 0.043 42.0 157.0 0.99455 3.35 0.47 10.5 5 0 white 0.01 0 64 8.8 0.28 0.45 6.0 0.022 14.0 49.0 0.9934 3.01 0.33 11.1 7 1 white 0.07 0 65 6.9 0.39 0.4 4.6 0.022 5.0 19.0 0.9915 3.31 0.37 12.6 3 0 white 0.16 0 66 7.4 0.38 0.27 7.5 0.041 24.0 160.0 0.99535 3.17 0.43 10.0 5 0 white 0.1 0 67 7.0 0.21 0.34 8.5 0.033 31.0 253.0 0.9953 3.22 0.56 10.5 6 0 white 0.0 0 68 5.8 0.25 0.28 11.1 0.056 45.0 175.0 0.99755 3.42 0.43 9.5 5 0 white 0.02 0 69 7.1 0.13 0.4 1.2 0.047 54.0 134.0 0.9932 3.3 0.97 9.8 7 1 white 0.06 0 70 6.7 0.11 0.34 8.8 0.043 41.0 113.0 0.9962 3.42 0.4 9.3 7 1 white 0.01 0 71 8.1 0.17 0.44 14.1 0.053 43.0 145.0 1.0006 3.28 0.75 8.8 8 1 white 0.01 0 72 7.2 0.23 0.19 13.7 0.052 47.0 197.0 0.99865 3.12 0.53 9.0 5 0 white 0.0 0 73 7.7 0.34 0.28 11.0 0.04 31.0 117.0 0.99815 3.27 0.29 9.2 6 0 white 0.18 0 74 5.9 0.24 0.3 2.0 0.033 28.0 92.0 0.99225 3.39 0.69 10.9 7 1 white 0.03 0 75 7.2 0.31 0.26 7.3 0.05 37.0 157.0 0.99625 3.09 0.43 9.0 5 0 white 0.19 0 76 7.8 0.42 0.23 8.8 0.054 42.0 215.0 0.9971 3.02 0.58 9.2 6 0 white 0.17 0 77 6.0 0.18 0.31 1.4 0.036 14.0 75.0 0.99085 3.34 0.58 11.1 8 1 white 0.08 0 78 7.8 0.27 0.58 11.2 0.036 44.0 161.0 0.9977 3.06 0.41 8.9 6 0 white 0.05 0 79 6.2 0.29 0.26 13.1 0.046 55.0 204.0 0.99745 3.16 0.41 9.6 6 0 white 0.12 0 80 6.0 0.39 0.17 12.0 0.046 65.0 246.0 0.9976 3.15 0.38 9.0 6 0 white 0.16 0 81 6.2 0.3 0.26 13.4 0.046 57.0 206.0 0.99775 3.17 0.43 9.5 6 0 white 0.18 0 82 6.2 0.3 0.17 2.8 0.04 24.0 125.0 0.9939 3.01 0.46 9.0 5 0 white 0.15 0 83 6.2 0.3 0.17 2.8 0.04 24.0 125.0 0.9939 3.01 0.46 9.0 5 0 white 0.18 0 84 7.3 0.655 0.2 10.2 0.071 28.0 212.0 0.9971 2.96 0.58 9.2 6 0 white 0.0 0 85 6.9 0.25 0.34 1.3 0.035 27.0 82.0 0.99045 3.18 0.44 12.2 6 0 white 0.12 0 86 7.5 0.42 0.34 4.3 0.04 34.0 108.0 0.99155 3.14 0.45 12.8 8 1 white 0.07 0 87 7.3 0.25 0.36 2.1 0.034 30.0 177.0 0.99085 3.25 0.4 11.9 8 1 white 0.03 0 88 8.7 0.23 0.32 13.4 0.044 35.0 169.0 0.99975 3.12 0.47 8.8 7 1 white 0.04 0 89 6.6 0.22 0.37 15.4 0.035 62.0 153.0 0.99845 3.02 0.4 9.3 5 0 white 0.15 0 90 6.9 0.18 0.36 1.3 0.036 40.0 117.0 0.9934 3.27 0.95 9.5 7 1 white 0.18 0 91 6.2 0.28 0.33 1.7 0.029 24.0 111.0 0.99 3.24 0.5 12.1 6 0 white 0.08 0 92 4.8 0.33 0.0 6.5 0.028 34.0 163.0 0.9937 3.35 0.61 9.9 5 0 white 0.16 0 93 6.1 0.27 0.33 2.2 0.021 26.0 117.0 0.9886 3.12 0.3 12.5 6 0 white 0.11 0 94 10.3 0.17 0.47 1.4 0.037 5.0 33.0 0.9939 2.89 0.28 9.6 3 0 white 0.05 0 95 8.8 0.36 0.44 1.9 0.04 9.0 121.0 0.9953 3.19 0.48 9.9 6 0 white 0.08 0 96 7.3 0.26 0.31 1.6 0.04 39.0 173.0 0.9918 3.19 0.51 11.4 6 0 white 0.12 0 97 5.6 0.19 0.39 1.1 0.043 17.0 67.0 0.9918 3.23 0.53 10.3 6 0 white 0.02 0 98 6.8 0.18 0.28 8.7 0.047 52.0 242.0 0.9952 3.22 0.53 10.5 6 0 white 0.08 0 99 6.6 0.26 0.29 1.4 0.039 13.0 67.0 0.9915 3.05 0.49 10.9 6 0 white 0.04 0 100 6.6 0.2 0.38 7.9 0.052 30.0 145.0 0.9947 3.32 0.56 11.0 7 1 white 0.09 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.05 0 0.7058984705130045 0.29410152948699547 2 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 0.05 0 0.6210228745525588 0.3789771254474413 3 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 0.11 0 0.6098904641167214 0.39010953588327857 4 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.08 0 0.610357558370861 0.38964244162913897 5 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 0.15 0 0.5778433904991147 0.42215660950088524 6 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.18 0 0.6307144791424906 0.3692855208575095 7 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.15 0 0.7028741561698378 0.29712584383016216 8 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 0.1 0 0.631476271357604 0.368523728642396 9 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 0.02 0 0.638423039918479 0.36157696008152096 10 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 0.01 0 0.6595368337547927 0.3404631662452073 11 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 0.04 0 0.6595368337547927 0.3404631662452073 12 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.1 0 0.6749895707853908 0.3250104292146092 13 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 0.14 0 0.6020843238723768 0.39791567612762324 14 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.05 0 0.5919172078689977 0.4080827921310023 15 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 0.17 0 0.6042293653085853 0.3957706346914147 16 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 0.06 0 0.6065774693132939 0.3934225306867061 17 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.12 0 0.5794665884660001 0.4205334115339999 18 8.3 0.2 0.49 1.7 0.04 34.0 169.0 0.9938 3.05 0.37 10.1 5 0 white 0.0 0 0.5912432081389749 0.40875679186102515 19 9.2 0.18 0.49 1.5 0.041 39.0 130.0 0.9945 3.04 0.49 9.8 7 1 white 0.12 0 0.5883549332592528 0.4116450667407472 20 8.8 0.23 0.74 3.2 0.042 15.0 126.0 0.9934 3.02 0.51 11.2 6 0 white 0.11 0 0.5931651647434732 0.40683483525652675 21 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 0.18 0 0.6126267275823272 0.3873732724176729 22 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.1 0 0.6154706098271538 0.38452939017284615 23 8.3 0.2 0.49 1.7 0.038 38.0 167.0 0.9939 3.05 0.37 10.1 6 0 white 0.13 0 0.5890000271449743 0.41099997285502565 24 6.9 0.21 0.49 1.4 0.041 15.0 164.0 0.9927 3.25 0.63 11.0 5 0 white 0.12 0 0.5933669886645752 0.4066330113354248 25 14.2 0.27 0.49 1.1 0.037 33.0 156.0 0.992 3.15 0.54 11.1 6 0 white 0.16 0 0.587474433043416 0.41252556695658404 26 7.5 0.23 0.49 7.7 0.049 61.0 209.0 0.9941 3.14 0.3 11.1 7 1 white 0.17 0 0.6314988678703851 0.3685011321296149 27 7.3 0.26 0.49 5.0 0.028 32.0 107.0 0.9936 3.24 0.54 10.8 6 0 white 0.06 0 0.6003021442735257 0.39969785572647437 28 7.1 0.53 0.24 0.8 0.029 29.0 86.0 0.993 3.16 0.32 9.1 4 0 white 0.02 0 0.6257247786838867 0.37427522131611335 29 7.2 0.16 0.49 1.3 0.037 27.0 104.0 0.9924 3.23 0.57 10.6 6 0 white 0.19 0 0.5818491736485247 0.4181508263514752 30 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.6043981760981878 0.3956018239018122 31 6.6 0.19 0.99 1.2 0.122 45.0 129.0 0.9936 3.09 0.31 8.7 6 0 white 0.08 0 0.6601890385283788 0.33981096147162115 32 7.3 0.21 0.49 1.8 0.038 44.0 152.0 0.9912 3.32 0.44 12.6 7 1 white 0.08 0 0.5908993470424897 0.40910065295751025 33 7.8 0.3 0.74 1.8 0.033 33.0 156.0 0.991 3.29 0.52 12.8 6 0 white 0.08 0 0.5857316055846882 0.4142683944153118 34 6.8 0.17 0.74 2.4 0.053 61.0 182.0 0.9953 3.63 0.76 10.5 6 0 white 0.19 0 0.5972824597244237 0.4027175402755762 35 6.4 0.18 0.74 11.9 0.046 54.0 168.0 0.9978 3.58 0.68 10.1 5 0 white 0.17 0 0.6324180913344973 0.36758190866550267 36 8.4 0.24 0.49 7.4 0.039 46.0 108.0 0.9934 3.03 0.33 11.9 7 1 white 0.03 0 0.6193700240982719 0.3806299759017281 37 7.9 0.14 0.74 1.2 0.028 30.0 165.0 0.991 3.08 0.82 12.3 6 0 white 0.01 0 0.5573511919223473 0.4426488080776527 38 6.8 0.21 0.74 1.2 0.047 25.0 111.0 0.9916 3.13 0.41 10.7 6 0 white 0.0 0 0.5891197404894752 0.4108802595105248 39 8.6 0.16 0.49 7.3 0.043 9.0 63.0 0.9953 3.13 0.59 10.5 6 0 white 0.05 0 0.6141097790709811 0.3858902209290189 40 6.6 0.55 0.01 2.7 0.034 56.0 122.0 0.9906 3.15 0.3 11.9 5 0 white 0.14 0 0.6500196171707981 0.3499803828292019 41 8.2 0.34 0.49 8.0 0.046 55.0 223.0 0.996 3.08 0.52 10.7 6 0 white 0.14 0 0.6422516624905759 0.3577483375094241 42 5.6 0.39 0.24 4.7 0.034 27.0 77.0 0.9906 3.28 0.36 12.7 5 0 white 0.02 0 0.6318574558103611 0.36814254418963893 43 8.0 0.14 0.49 1.5 0.035 42.0 120.0 0.9928 3.26 0.4 10.6 7 1 white 0.0 0 0.5772853595634873 0.4227146404365127 44 6.9 0.34 0.49 7.3 0.045 61.0 206.0 0.9957 3.09 0.4 9.0 6 0 white 0.18 0 0.6394009509171754 0.36059904908282453 45 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.18 0 0.6208427379550461 0.3791572620449539 46 6.2 0.22 0.49 6.0 0.029 31.0 128.0 0.9928 3.41 0.36 11.3 8 1 white 0.02 0 0.6017502657618697 0.39824973423813026 47 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.11 0 0.6232537549480187 0.3767462450519813 48 7.8 0.49 0.49 7.0 0.043 29.0 149.0 0.9952 3.21 0.33 10.0 5 0 white 0.13 0 0.6524503251530149 0.347549674846985 49 7.9 0.33 0.28 31.6 0.053 35.0 176.0 1.0103 3.15 0.38 8.8 6 0 white 0.09 0 0.7487417800116152 0.2512582199883848 50 6.6 0.31 0.49 7.7 0.05 52.0 220.0 0.9964 3.12 0.45 8.8 5 0 white 0.11 0 0.6434284990269306 0.35657150097306944 51 8.8 0.39 0.34 5.9 0.055 33.0 128.0 0.9927 2.95 0.51 11.8 6 0 white 0.03 0 0.6532423587711758 0.34675764122882424 52 7.2 0.25 0.28 14.4 0.055 55.0 205.0 0.9986 3.12 0.38 9.0 7 1 white 0.05 0 0.6768119192004892 0.3231880807995108 53 6.9 0.18 0.3 2.0 0.038 39.0 190.0 0.9914 3.32 0.37 12.2 6 0 white 0.15 0 0.5961144641946772 0.4038855358053228 54 6.4 0.24 0.22 1.5 0.038 38.0 157.0 0.9934 3.41 0.55 9.9 6 0 white 0.08 0 0.6054600277362545 0.3945399722637455 55 6.8 0.26 0.29 16.95 0.056 48.0 179.0 0.9998 3.45 0.4 9.6 5 0 white 0.07 0 0.6892015450645357 0.3107984549354643 56 7.9 0.18 0.37 3.0 0.061 25.0 178.0 0.995 3.22 0.51 10.0 6 0 white 0.14 0 0.6233683256256746 0.3766316743743255 57 7.0 0.21 0.31 6.0 0.046 29.0 108.0 0.9939 3.26 0.5 10.8 6 0 white 0.11 0 0.6260275549175909 0.3739724450824092 58 7.5 0.4 1.0 19.5 0.041 33.0 148.0 0.9977 3.24 0.38 12.0 6 0 white 0.1 0 0.6727467686543156 0.3272532313456844 59 6.5 0.18 0.34 1.6 0.04 43.0 148.0 0.9912 3.32 0.59 11.5 8 1 white 0.0 0 0.5953821009060227 0.4046178990939772 60 7.0 0.13 0.3 5.0 0.056 31.0 122.0 0.9945 3.47 0.42 10.5 6 0 white 0.12 0 0.6238273685025757 0.3761726314974243 61 7.0 0.3 0.32 6.4 0.034 28.0 97.0 0.9924 3.23 0.44 11.8 6 0 white 0.14 0 0.6244315570248313 0.3755684429751687 62 7.6 0.445 0.44 14.5 0.045 68.0 212.0 0.9986 3.48 0.36 10.0 6 0 white 0.19 0 0.6824252480437994 0.31757475195620055 63 6.8 0.3 0.24 6.6 0.123 35.0 116.0 0.9953 3.07 0.48 9.4 5 0 white 0.01 0 0.7205540587109842 0.27944594128901573 64 6.6 0.545 0.04 2.5 0.031 48.0 111.0 0.9906 3.14 0.32 11.9 5 0 white 0.07 0 0.6442678807165142 0.3557321192834858 65 6.6 0.37 0.47 6.5 0.061 23.0 150.0 0.9954 3.14 0.45 9.6 6 0 white 0.16 0 0.6576468086085813 0.34235319139141873 66 6.6 0.22 0.58 1.1 0.133 52.0 136.0 0.9932 3.1 0.3 9.1 5 0 white 0.1 0 0.6892064841781455 0.31079351582185455 67 7.4 0.23 0.25 1.4 0.049 43.0 141.0 0.9934 3.42 0.54 10.2 7 1 white 0.0 0 0.613960676170751 0.386039323829249 68 6.7 0.27 0.25 8.0 0.053 54.0 202.0 0.9961 3.22 0.43 9.3 5 0 white 0.02 0 0.6521139362443469 0.3478860637556531 69 6.6 0.62 0.2 8.7 0.046 81.0 224.0 0.99605 3.17 0.44 9.3 5 0 white 0.06 0 0.6887681680272848 0.31123183197271514 70 7.7 0.43 0.28 4.5 0.046 33.0 102.0 0.9918 3.16 0.56 12.2 7 1 white 0.01 0 0.6455239699882309 0.354476030011769 71 6.4 0.15 0.36 1.8 0.034 43.0 150.0 0.9922 3.42 0.69 11.0 8 1 white 0.01 0 0.5853420783226412 0.4146579216773588 72 6.7 0.24 0.29 6.8 0.038 54.0 127.0 0.9932 3.33 0.46 11.6 7 1 white 0.0 0 0.625054808125646 0.37494519187435404 73 7.2 0.26 0.3 2.1 0.033 50.0 158.0 0.9909 3.33 0.43 12.1 7 1 white 0.18 0 0.600232559039267 0.399767440960733 74 7.4 0.35 0.31 17.95 0.062 42.0 187.0 1.0002 3.27 0.64 9.1 5 0 white 0.03 0 0.7074474317824935 0.29255256821750647 75 6.7 0.37 0.41 6.3 0.061 22.0 149.0 0.9953 3.16 0.47 9.6 6 0 white 0.19 0 0.6589436376000469 0.3410563623999531 76 7.1 0.37 0.32 1.4 0.037 27.0 126.0 0.9918 3.19 0.62 12.0 5 0 white 0.17 0 0.6145623962636145 0.38543760373638547 77 6.4 0.26 0.21 7.1 0.04 35.0 162.0 0.9956 3.39 0.58 9.9 6 0 white 0.08 0 0.634882520042594 0.36511747995740595 78 7.6 0.3 0.22 10.2 0.049 57.0 191.0 0.9966 3.08 0.4 9.3 6 0 white 0.05 0 0.6606991219435596 0.33930087805644044 79 8.8 0.2 0.43 15.0 0.053 60.0 184.0 1.0008 3.28 0.79 8.8 6 0 white 0.12 0 0.6651843171502521 0.33481568284974794 80 7.5 0.33 0.39 12.4 0.065 29.0 119.0 0.9974 3.16 0.39 9.4 5 0 white 0.16 0 0.6834750993723369 0.3165249006276631 81 8.8 0.2 0.43 15.0 0.053 60.0 184.0 1.0008 3.28 0.79 8.8 6 0 white 0.18 0 0.6651843171502521 0.33481568284974794 82 6.8 0.3 0.35 2.8 0.038 10.0 164.0 0.9912 3.09 0.53 12.0 6 0 white 0.15 0 0.6122042545859976 0.3877957454140024 83 6.0 0.26 0.29 1.0 0.032 27.0 96.0 0.9896 3.38 0.44 12.3 6 0 white 0.18 0 0.5955379506783745 0.4044620493216256 84 7.4 0.29 0.31 1.7 0.035 23.0 110.0 0.9926 3.07 0.38 10.9 5 0 white 0.0 0 0.6042755790072197 0.39572442099278027 85 7.4 0.49 0.24 15.1 0.03 34.0 153.0 0.9953 3.13 0.51 12.0 7 1 white 0.12 0 0.6809684478169479 0.3190315521830521 86 8.0 0.55 0.42 12.6 0.211 37.0 213.0 0.9988 2.99 0.56 9.3 5 0 white 0.07 0 0.82708429605226 0.17291570394773997 87 6.5 0.34 0.36 11.0 0.052 53.0 247.0 0.9984 3.44 0.55 9.3 6 0 white 0.03 0 0.6679028607227369 0.3320971392772632 88 7.2 0.24 0.29 2.2 0.037 37.0 102.0 0.992 3.27 0.64 11.0 7 1 white 0.04 0 0.6034329987246496 0.39656700127535033 89 7.6 0.26 0.58 7.9 0.041 62.0 180.0 0.9966 3.07 0.38 9.0 5 0 white 0.15 0 0.6242330959455642 0.3757669040544358 90 6.4 0.18 0.31 1.6 0.049 36.0 127.0 0.9934 3.6 0.67 10.4 7 1 white 0.18 0 0.6074034514103513 0.39259654858964865 91 6.6 0.28 0.3 7.8 0.049 57.0 202.0 0.9958 3.24 0.39 9.5 5 0 white 0.08 0 0.6463044873270407 0.35369551267295923 92 7.1 0.25 0.3 2.4 0.042 25.0 122.0 0.994 3.43 0.61 10.5 6 0 white 0.16 0 0.6113566916726006 0.38864330832739935 93 7.6 0.36 0.44 8.3 0.255 28.0 142.0 0.9958 3.12 0.43 10.2 6 0 white 0.11 0 0.8309517484933275 0.1690482515066725 94 5.8 0.33 0.2 16.05 0.047 26.0 166.0 0.9976 3.09 0.46 8.9 5 0 white 0.05 0 0.6877874800587385 0.31221251994126153 95 7.2 0.2 0.61 16.2 0.043 14.0 103.0 0.9987 3.06 0.36 9.2 6 0 white 0.08 0 0.6537642390430078 0.3462357609569922 96 7.2 0.24 0.4 17.85 0.049 50.0 185.0 1.0 3.34 0.42 9.6 5 0 white 0.12 0 0.6791970575425514 0.3208029424574485 97 7.9 0.26 0.33 10.3 0.039 73.0 212.0 0.9969 2.93 0.49 9.5 6 0 white 0.02 0 0.6415125795266023 0.35848742047339766 98 7.5 0.29 0.67 8.1 0.037 53.0 166.0 0.9966 2.9 0.41 8.9 6 0 white 0.08 0 0.6208526340390316 0.37914736596096843 99 7.2 0.31 0.41 8.6 0.053 15.0 89.0 0.9976 3.29 0.64 9.9 6 0 white 0.04 0 0.6531168493521193 0.3468831506478806 100 10.0 0.23 0.27 14.1 0.033 45.0 166.0 0.9988 2.72 0.43 9.7 6 0 white 0.09 0 0.6481119942128899 0.35188800578711005 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