vastorbit.machine_learning.vast.linear_model.LinearRegression¶
- class vastorbit.machine_learning.vast.linear_model.LinearRegression(name: str = None, overwrite_model: bool = False, **kwargs)¶
Creates a
LinearRegressionobject 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
LinearRegressionmodel:from vastorbit.machine_learning.vast import LinearRegression
Then we can create the model:
model = LinearRegression( 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", ], "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:
result = model.report()
value explained_variance 0.16505489958831387 max_error 3.298639757725084 median_absolute_error 0.5454115376987031 mean_absolute_error 0.6173154087221755 mean_squared_error 80008.70770108665 root_mean_squared_error 0.7909656083643224 r2 0.16452323562841564 r2_adj 0.16070245774256997 aic 14905.526087587452 bic 14941.658308590111 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:result = model.report(metrics = "anova")
Df SS MS F p_value Regression 6 161.27763098619997 26.879605164366662 0.00033414982750402624 0.9999999998314684 Residual 1312 105539608.50159091 80441.77477255404 Total 1318 1019.9029567854415 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 7.1 0.27 0.31 18.2 0.046 55.0 252.0 1.0 3.07 0.56 8.7 5 0 white 0.07 5.627027081137584 2 6.8 0.27 0.12 1.3 0.04 87.0 168.0 0.992 3.18 0.41 10.0 5 0 white 0.04 6.057549067663302 3 6.9 0.49 0.24 1.2 0.049 13.0 125.0 0.9932 3.17 0.51 9.4 5 0 white 0.13 5.712338038706378 4 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.1 6.03172262072917 5 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.17 6.0566398818722575 6 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.921392425670604 7 6.9 0.23 0.38 8.3 0.047 47.0 162.0 0.9954 3.34 0.52 10.5 7 1 white 0.06 5.862833192459988 8 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.01 5.921392425670604 9 6.7 0.22 0.37 1.6 0.028 24.0 102.0 0.9913 3.29 0.59 11.6 7 1 white 0.12 6.149577466890662 10 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.17 5.872313841110241 11 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.06 5.952576208344482 12 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.13 6.339868322875077 13 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.19 5.805496828840035 14 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.02 5.626325499747651 15 5.9 0.36 0.41 1.3 0.047 45.0 104.0 0.9917 3.33 0.51 10.6 6 0 white 0.15 5.8574692473173116 16 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.07 5.673138403865096 17 7.4 0.29 0.29 1.6 0.045 53.0 180.0 0.9936 3.34 0.68 10.5 6 0 white 0.12 5.881049066937891 18 7.0 0.28 0.36 1.0 0.035 8.0 70.0 0.9899 3.09 0.46 12.1 6 0 white 0.1 6.331006952330057 19 6.3 0.19 0.28 1.8 0.022 28.0 158.0 0.9907 3.2 0.64 11.4 6 0 white 0.09 6.223879853853589 20 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.12 5.524774714222531 21 6.8 0.23 0.32 1.6 0.026 43.0 147.0 0.9904 3.29 0.54 12.5 6 0 white 0.0 6.2961703865057075 22 5.7 0.335 0.34 1.0 0.04 13.0 174.0 0.992 3.27 0.66 10.0 5 0 white 0.08 5.800402656790936 23 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.14 5.524774714222531 24 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.1 5.788135549870674 25 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.09 5.830744592684368 26 6.0 0.24 0.27 1.9 0.048 40.0 170.0 0.9938 3.64 0.54 10.0 7 1 white 0.16 5.703226966466673 27 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.08 6.116016384477604 28 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.08 6.022923033889072 29 6.1 0.31 0.26 2.2 0.051 28.0 167.0 0.9926 3.37 0.47 10.4 6 0 white 0.14 5.856819257862355 30 7.2 0.34 0.34 12.6 0.048 7.0 41.0 0.9942 3.19 0.4 11.7 5 0 white 0.17 6.192277707466559 31 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.05 5.964351969004497 32 6.1 0.28 0.22 1.8 0.034 32.0 116.0 0.9898 3.36 0.44 12.6 6 0 white 0.15 6.27339126218223 33 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.03 5.989148797041992 34 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.17 5.719160807328876 35 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.18 5.817746500692863 36 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.1 5.868530845794709 37 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 5.764279012924561 38 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.15 6.172991242881125 39 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.08 5.460574103277423 40 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.04 6.432560649887165 41 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.14 5.722531059755198 42 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.16 5.808400902227788 43 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.01 5.739713686292646 44 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.06 6.479839078442581 45 6.0 0.38 0.26 6.0 0.034 42.0 134.0 0.9912 3.38 0.38 12.3 7 1 white 0.07 6.154363778052982 46 7.4 0.24 0.22 10.7 0.042 26.0 81.0 0.9954 2.86 0.36 9.7 6 0 white 0.01 6.056783144525866 47 6.6 0.25 0.3 1.6 0.046 32.0 134.0 0.993 3.42 0.51 10.1 7 1 white 0.12 5.881022852325742 48 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.07 5.984859167739728 49 7.3 0.2 0.37 1.2 0.037 48.0 119.0 0.992 3.32 0.49 10.9 6 0 white 0.1 6.133824353185275 50 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.13 6.0774683911393765 51 5.9 0.27 0.29 11.4 0.036 31.0 115.0 0.9949 3.35 0.48 10.5 8 1 white 0.15 5.907559040053343 52 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.11 6.176919749561108 53 6.5 0.26 0.43 8.9 0.083 50.0 171.0 0.9965 2.85 0.5 9.0 5 0 white 0.18 5.648383428804067 54 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.0 5.701100747622235 55 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.701100747622235 56 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.06 5.632464720274186 57 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.632464720274186 58 6.5 0.21 0.37 2.5 0.048 70.0 138.0 0.9917 3.33 0.75 11.4 7 1 white 0.07 6.113171978855604 59 7.8 0.4 0.49 7.8 0.06 34.0 162.0 0.9966 3.26 0.58 11.3 6 0 white 0.14 5.655594116200035 60 6.6 0.325 0.49 7.7 0.049 53.0 217.0 0.996 3.16 0.4 9.3 5 0 white 0.13 5.617926979775575 61 7.1 0.31 0.38 1.2 0.036 10.0 124.0 0.9924 3.14 0.44 9.9 6 0 white 0.17 5.963577725009429 62 7.0 0.35 0.3 6.5 0.028 27.0 87.0 0.9936 3.4 0.42 11.4 7 1 white 0.09 5.983573337610551 63 6.3 0.31 0.3 10.0 0.046 49.0 212.0 0.9962 3.74 0.55 11.9 6 0 white 0.06 5.686685052707816 64 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.0 5.704889229149558 65 7.3 0.26 0.33 17.85 0.049 41.5 195.0 1.0 3.06 0.44 9.1 7 1 white 0.1 5.645615584045515 66 7.0 0.24 0.3 4.2 0.04 41.0 213.0 0.9927 3.28 0.49 11.8 6 0 white 0.09 6.100208416231084 67 6.7 0.265 0.22 8.6 0.048 54.0 198.0 0.9955 3.25 0.41 10.2 5 0 white 0.19 5.833875112155567 68 8.5 0.32 0.36 14.9 0.041 47.0 190.0 0.9982 3.08 0.31 10.0 6 0 white 0.17 5.904191165055238 69 7.0 0.24 0.3 4.2 0.04 41.0 213.0 0.9927 3.28 0.49 11.8 6 0 white 0.08 6.100208416231084 70 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.12 5.8083491974390995 71 9.3 0.2 0.33 1.7 0.05 28.0 178.0 0.9954 3.16 0.43 9.0 4 0 white 0.0 5.95773846427943 72 8.2 0.15 0.48 2.7 0.052 24.0 190.0 0.995 3.5 0.45 10.9 7 1 white 0.16 5.91186959143937 73 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 5.86254384170698 74 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.02 6.172770568512249 75 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.04 5.956482002194207 76 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.19 6.1894753088339485 77 8.7 0.34 0.46 13.8 0.055 68.0 198.0 0.9988 3.36 0.37 9.5 6 0 white 0.09 5.7699618878136505 78 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.13 6.09371445121684 79 6.9 0.16 0.3 9.6 0.057 50.0 185.0 0.9978 3.39 0.38 9.6 6 0 white 0.07 5.635597061994645 80 7.5 0.22 0.29 4.8 0.05 33.0 87.0 0.994 3.14 0.42 9.9 5 0 white 0.07 6.027225346273269 81 6.7 0.16 0.28 2.5 0.046 40.0 153.0 0.9921 3.38 0.51 11.4 7 1 white 0.02 6.135243284680314 82 9.6 0.21 0.28 1.2 0.038 12.0 53.0 0.9926 2.8 0.46 10.6 5 0 white 0.17 6.386893752303621 83 8.0 0.3 0.28 5.7 0.044 31.0 124.0 0.9948 3.16 0.51 10.2 6 0 white 0.01 5.96263326666795 84 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 6.210861284165333 85 6.5 0.18 0.26 1.4 0.041 40.0 141.0 0.9941 3.34 0.72 9.5 6 0 white 0.03 5.7543381021827145 86 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.0 6.03799348334482 87 8.5 0.21 0.26 9.25 0.034 73.0 142.0 0.9945 3.05 0.37 11.4 6 0 white 0.1 6.298349263966173 88 9.4 0.16 0.3 1.4 0.042 26.0 176.0 0.9954 3.15 0.46 9.1 5 0 white 0.17 5.991868977030862 89 7.8 0.22 0.36 1.4 0.056 21.0 153.0 0.993 3.2 0.53 10.4 6 0 white 0.04 6.06028624953214 90 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.04 5.575535876996952 91 6.6 0.37 0.24 2.0 0.064 23.0 120.0 0.9946 3.32 0.54 9.4 5 0 white 0.0 5.59078730691175 92 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.02 6.02611974919833 93 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.07 5.714878646080535 94 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.19 5.714878646080535 95 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.19 5.846490209308541 96 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.05 5.651373730232223 97 7.6 0.38 0.2 3.4 0.046 9.0 116.0 0.9944 3.15 0.41 9.4 5 0 white 0.01 5.819698152522449 98 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 6.177179588784952 99 6.8 0.33 0.28 1.2 0.032 38.0 131.0 0.9889 3.19 0.41 13.0 6 0 white 0.09 6.4328404636031 100 7.3 0.19 0.24 6.3 0.054 34.0 231.0 0.9964 3.36 0.54 10.0 6 0 white 0.12 5.743644267808804 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