vastorbit.machine_learning.vast.linear_model.Ridge¶
- class vastorbit.machine_learning.vast.linear_model.Ridge(name: str = None, overwrite_model: bool = False, **kwargs)¶
Creates a
Ridgeobject 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.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
Ridgemodel:from vastorbit.machine_learning.vast import Ridge
Then we can create the model:
model = Ridge( tol = 1e-6, alpha = 0.5, max_iter = 100, solver = 'cholesky', )
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", ], "quality", 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 explained_variance 0.09853742657372833 max_error 2.787660357774259 median_absolute_error 0.5982438991489742 mean_absolute_error 0.6427562812466034 mean_squared_error 73.28304611353323 root_mean_squared_error 0.8292957156719737 r2 0.09253555929188284 r2_adj 0.08828514036584945 aic 5545.260184986937 bic 5581.222043833587 Rows: 1-10 | 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 = ["mse", "r2"]).For
LinearModel, we can easily get the ANOVA table using:model.report(metrics = "anova")
Df SS MS F p_value Regression 6 78.50255328080179 13.083758880133631 0.17754701171463996 0.9829655225407988 Residual 1281 94399.19581631111 73.69180001273311 Total 1287 1074.583850931679 Rows: 1-3 | Columns: 6You can also use the
LinearModel.scorefunction to compute the R-squared value: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)123predictionDouble1 8.8 0.27 0.25 5.0 0.024 52.0 99.0 0.9925 2.87 0.49 11.4 5 0 white 0.16 5.969065989519746 2 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.18 5.869497132644156 3 6.2 0.23 0.35 0.7 0.051 24.0 111.0 0.9916 3.37 0.43 11.0 3 0 white 0.1 6.0546598056992345 4 6.8 0.24 0.29 9.5 0.042 56.0 157.0 0.99586 3.11 0.51 10.1 6 0 white 0.11 5.889013809440309 5 7.1 0.17 0.4 14.55 0.047 47.0 156.0 0.99945 3.34 0.78 9.1 6 0 white 0.17 5.869709495051355 6 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.07 5.910452804536682 7 8.2 0.34 0.29 5.2 0.076 19.0 92.0 0.99138 2.95 0.39 12.5 6 0 white 0.19 5.756630016284401 8 6.9 0.24 0.23 7.1 0.041 20.0 97.0 0.99246 3.1 0.85 11.4 6 0 white 0.06 5.937257349367567 9 6.0 0.16 0.22 1.6 0.042 36.0 106.0 0.9905 3.24 0.32 11.4 6 0 white 0.0 6.137378096606 10 5.8 0.32 0.2 2.6 0.027 17.0 123.0 0.98936 3.36 0.78 13.9 7 1 white 0.06 5.973684685542979 11 6.6 0.24 0.27 10.3 0.047 54.0 219.0 0.99742 3.04 0.45 8.8 5 0 white 0.16 5.855663573907519 12 6.6 0.16 0.36 1.1 0.031 27.0 93.0 0.98884 3.23 0.34 13.2 8 1 white 0.13 6.192519115360003 13 6.8 0.19 0.4 9.85 0.055 41.0 103.0 0.99532 2.98 0.56 10.5 6 0 white 0.07 5.922305634976469 14 5.9 0.32 0.28 4.7 0.039 34.0 94.0 0.98964 3.22 0.57 13.1 7 1 white 0.19 5.912968398449511 15 8.0 0.2 0.44 1.0 0.057 24.0 111.0 0.99158 3.09 0.32 11.2 6 0 white 0.08 6.064277434568909 16 6.7 0.24 0.36 8.4 0.042 42.0 123.0 0.99473 3.34 0.52 10.9 6 0 white 0.17 5.920848487282326 17 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.16 5.940308443690418 18 6.7 0.24 0.36 8.4 0.042 42.0 123.0 0.99473 3.34 0.52 10.9 6 0 white 0.12 5.920848487282326 19 6.9 0.33 0.31 4.2 0.04 21.0 93.0 0.9896 3.18 0.48 13.4 7 1 white 0.05 5.902033899769618 20 7.1 0.36 0.28 2.4 0.036 35.0 115.0 0.98936 3.19 0.44 13.5 7 1 white 0.04 5.903542091648358 21 6.8 0.19 0.33 1.3 0.031 22.0 87.0 0.98987 3.08 0.62 12.3 7 1 white 0.16 6.144506874497989 22 5.9 0.23 0.24 3.8 0.038 61.0 152.0 0.99139 3.31 0.5 11.3 7 1 white 0.16 6.0271557718630735 23 6.4 0.28 0.44 7.1 0.048 49.0 179.0 0.99528 3.15 0.48 9.2 5 0 white 0.09 5.889182518360972 24 7.2 0.27 0.31 1.2 0.031 27.0 80.0 0.98892 3.03 0.33 12.7 6 0 white 0.19 6.0487597383182035 25 8.1 0.26 0.27 4.3 0.03 43.0 123.0 0.99212 3.16 0.33 11.2 6 0 white 0.12 5.986476156456159 26 6.6 0.23 0.37 8.5 0.036 46.0 153.0 0.99576 3.2 0.48 9.4 6 0 white 0.01 5.945409711375209 27 8.1 0.2 0.28 0.9 0.023 49.0 87.0 0.99062 2.92 0.36 11.1 6 0 white 0.12 6.141352813227952 28 6.6 0.64 0.28 4.4 0.032 19.0 78.0 0.99036 3.11 0.62 12.9 6 0 white 0.04 5.547576801641213 29 7.0 0.48 0.12 4.5 0.05 23.0 86.0 0.99398 2.86 0.35 9.0 5 0 white 0.05 5.652936644865338 30 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.13 6.0473036990486655 31 7.4 0.25 0.28 7.25 0.028 14.0 78.0 0.99238 2.94 0.37 11.5 7 1 white 0.13 5.959485164425461 32 7.4 0.25 0.28 7.25 0.028 14.0 78.0 0.99238 2.94 0.37 11.5 7 1 white 0.07 5.959485164425461 33 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.02 5.947992407736924 34 6.8 0.19 0.71 17.5 0.042 21.0 114.0 0.99784 2.85 0.5 9.5 6 0 white 0.0 5.85310149236515 35 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.16 6.128314313416718 36 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.01 6.001622279957975 37 6.3 0.2 0.26 4.7 0.04 108.0 168.0 0.99278 3.07 0.75 10.7 7 1 white 0.18 6.035969416964183 38 6.5 0.21 0.51 17.6 0.045 34.0 125.0 0.99966 3.2 0.47 8.8 6 0 white 0.17 5.792401761461086 39 6.4 0.24 0.23 2.0 0.046 30.0 133.0 0.9908 3.12 0.54 11.4 7 1 white 0.06 6.021288934790709 40 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.19 5.971589261391889 41 6.3 0.32 0.17 17.75 0.06 51.0 190.0 0.99916 3.13 0.48 8.8 6 0 white 0.17 5.582950863003239 42 6.8 0.52 0.26 5.7 0.038 27.0 130.0 0.99 3.11 0.27 13.0 7 1 white 0.16 5.649324260494895 43 6.1 0.35 0.07 1.4 0.069 22.0 108.0 0.9934 3.23 0.52 9.2 5 0 white 0.02 5.813607603272651 44 6.3 0.14 0.39 1.2 0.044 26.0 116.0 0.992 3.26 0.53 10.3 6 0 white 0.11 6.174296350244182 45 8.2 0.28 0.42 1.8 0.031 30.0 93.0 0.9917 3.09 0.39 11.4 5 0 white 0.03 6.020730067401803 46 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.04 5.719824904389421 47 7.4 0.31 0.28 1.6 0.05 33.0 137.0 0.9929 3.31 0.56 10.5 6 0 white 0.07 5.923765305826235 48 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 5.929142638935156 49 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.15 5.930851989079272 50 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.19 5.929142638935156 51 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.06 5.753735786989681 52 6.6 0.52 0.44 12.2 0.048 54.0 245.0 0.9975 3.26 0.54 9.3 6 0 white 0.02 5.50670928640562 53 7.1 0.21 0.27 8.6 0.056 26.0 111.0 0.9956 2.95 0.52 9.5 5 0 white 0.14 5.898607844630894 54 7.2 0.39 0.62 11.0 0.047 66.0 178.0 0.9976 3.16 0.5 8.7 5 0 white 0.17 5.6999032063682975 55 7.0 0.14 0.32 9.0 0.039 54.0 141.0 0.9956 3.22 0.43 9.4 6 0 white 0.19 6.027294671543225 56 5.5 0.16 0.22 4.5 0.03 30.0 102.0 0.9938 3.24 0.36 9.4 6 0 white 0.11 6.1123023277718485 57 6.7 0.47 0.34 8.9 0.043 31.0 172.0 0.9964 3.22 0.6 9.2 5 0 white 0.04 5.627604727814193 58 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.13 4.976202418533086 59 7.4 0.26 0.31 7.6 0.047 52.0 177.0 0.9962 3.13 0.45 8.9 6 0 white 0.07 5.880252529656076 60 5.7 0.44 0.13 7.0 0.025 28.0 173.0 0.9913 3.33 0.48 12.5 6 0 white 0.11 5.7467995053809755 61 7.2 0.28 0.54 16.7 0.045 54.0 200.0 0.999 3.08 0.49 9.5 6 0 white 0.02 5.724399562064983 62 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.11 5.906455978084731 63 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.07 5.87078197366891 64 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.01 5.572701498917045 65 7.4 0.15 0.42 1.7 0.045 49.0 154.0 0.992 3.0 0.6 10.4 6 0 white 0.08 6.14527233599026 66 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.11 6.1495521844248024 67 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.04 6.076231235992088 68 5.6 0.19 0.47 4.5 0.03 19.0 112.0 0.9922 3.56 0.45 11.2 6 0 white 0.1 6.11043513524874 69 7.9 0.345 0.51 15.3 0.047 54.0 171.0 0.9987 3.09 0.51 9.1 5 0 white 0.15 5.65729134662698 70 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.07 5.809447268347852 71 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.15 5.622290272020756 72 7.7 0.22 0.42 1.9 0.052 10.0 87.0 0.9922 3.3 0.49 11.8 6 0 white 0.17 6.036508943141876 73 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.06 5.622290272020756 74 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.09 5.743487266810968 75 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.03 6.062704688923436 76 8.4 0.35 0.71 12.2 0.046 22.0 160.0 0.9982 2.98 0.65 9.4 5 0 white 0.07 5.727675970504558 77 6.1 0.41 0.24 1.6 0.049 16.0 137.0 0.993 3.32 0.5 10.4 6 0 white 0.06 5.813549719736441 78 5.9 0.37 0.1 1.6 0.057 39.0 128.0 0.9924 3.24 0.48 10.1 5 0 white 0.11 5.827380202846137 79 6.0 0.26 0.5 2.2 0.048 59.0 153.0 0.9928 3.08 0.61 9.8 5 0 white 0.1 6.016057651947962 80 7.2 0.2 0.34 2.7 0.032 49.0 151.0 0.99 3.16 0.39 12.7 7 1 white 0.09 6.103274868734337 81 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.07 6.02952973941054 82 8.2 0.23 0.29 1.8 0.047 47.0 187.0 0.9933 3.13 0.5 10.2 6 0 white 0.09 6.016476555241702 83 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.13 5.987826866279626 84 5.7 0.18 0.22 4.2 0.042 25.0 111.0 0.994 3.35 0.39 9.4 5 0 white 0.11 6.059011450272631 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.18 5.868240900252858 86 6.1 0.32 0.25 1.7 0.034 37.0 136.0 0.992 3.47 0.5 10.8 7 1 white 0.07 5.963945569690523 87 6.9 0.28 0.27 2.1 0.036 42.0 121.0 0.9926 3.42 0.49 10.8 7 1 white 0.03 5.992661822073934 88 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.07 5.812347599886957 89 7.0 0.29 0.37 4.9 0.034 26.0 127.0 0.9928 3.17 0.44 10.8 6 0 white 0.03 5.94824469742974 90 6.7 0.3 0.35 1.4 0.18 36.0 160.0 0.9937 3.11 0.54 9.4 6 0 white 0.12 5.6014353348413195 91 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.16 5.812347599886957 92 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.07 5.885947489637097 93 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.15 5.885947489637097 94 6.5 0.36 0.28 3.2 0.037 29.0 119.0 0.9908 3.25 0.65 12.4 8 1 white 0.08 5.887073522849356 95 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.15 5.971246726226131 96 7.0 0.32 0.24 6.2 0.048 31.0 228.0 0.9957 3.23 0.62 9.4 6 0 white 0.1 5.8272419933444635 97 5.8 0.31 0.33 1.2 0.036 23.0 99.0 0.9916 3.18 0.6 10.5 6 0 white 0.14 5.992268598946566 98 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.0 5.731976614707593 99 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.12 5.731976614707593 100 5.8 0.335 0.14 5.8 0.046 49.0 197.0 0.9937 3.3 0.71 10.3 5 0 white 0.19 5.827505497022953 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.Plots¶
If the model allows, you can also generate relevant plots. For example, regression plots can be found in the Machine Learning - Regression 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])contour([nbins, chart])Draws the model's contour plot.
deploySQL([X])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.
plot([max_nb_points, chart])Draws the model.
predict(vdf[, X, name, inplace])Predicts using the input relation.
regression_report([metrics])Computes a regression report using multiple metrics to evaluate the model (
r2,mse,max error...).report([metrics])Computes a regression report using multiple metrics to evaluate the model (
r2,mse,max error...).score([metric])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