vastorbit.machine_learning.vast.neighbors.KNeighborsRegressor¶
- class vastorbit.machine_learning.vast.neighbors.KNeighborsRegressor(name: str = None, overwrite_model: bool = False, n_neighbors: int = 5, p: int = 2)¶
[Beta Version] Creates a
KNeighborsRegressorobject using the k-nearest neighbors algorithm. This object uses pure SQL to compute all the distances and final score.Warning
This algorithm uses a CROSS JOIN during computation and is therefore computationally expensive at O(n * n), where n is the total number of elements. Since KNeighborsRegressor uses the p- distance, it is highly sensitive to unnormalized data.
Important
This algorithm is not VAST Native and relies solely on SQL for attribute computation. While this model does not take advantage of the benefits provided by a model management system, including versioning and tracking, the SQL code it generates can still be used to create a pipeline.
- Parameters:
n_neighbors (int, optional) – Number of neighbors to consider when computing the score.
p (int, optional) – The
pof thep-distances (distance metric used during the model computation).
- Variables:
created (Many attributes are)
phase. (during the fitting)
n_neighbors_ (int) – Number of neighbors.
p_ (int) – The
pof thep-distances.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.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
KNeighborsRegressormodel:from vastorbit.machine_learning.vast import KNeighborsRegressor
Then we can create the model:
model = KNeighborsRegressor()
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.Metrics¶
We can get the entire report using:
result = model.report()
value explained_variance 9.992007221626409e-16 max_error 3.8 median_absolute_error 0.7999999999999998 mean_absolute_error 0.8470948012232363 mean_squared_error 1.4249847094801225 root_mean_squared_error 1.0702824800752226 r2 -0.5191985265390417 r2_adj -0.5262048225876461 aic 477.40423564508205 bic 513.4764789076636 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
KNeighborsRegressor, we can easily get the ANOVA table using:result = model.report(metrics = "anova")
Df SS MS F p_value Regression 6 54.17617737003087 9.029362895005145 11.136054457759826 3.808709808621569e-12 Residual 1301 1054.8800000000008 0.8108224442736363 Total 1307 992.9701834862386 Rows: 1-3 | Columns: 6You can also use the
KNeighborsRegressor.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)123chloridesDouble123densityDouble123free_sulfur_dioxideDecimal(7, 2)123total_sulfur_dioxideDecimal(7, 2)123phDecimal(6, 3)123sulphatesDecimal(6, 3)123alcoholDouble123qualityInteger123goodIntegerAbccolorVarchar(20)123seedrandDecimal(26, 6)123predictionDouble1 6.0 0.26 0.5 2.2 0.048 0.9928 59.0 153.0 3.08 0.61 9.8 5 0 white 0.09 5.8 2 7.5 0.23 0.68 11.0 0.047 0.9978 37.0 133.0 2.99 0.38 8.8 5 0 white 0.11 5.8 3 7.4 0.2 1.66 2.1 0.022 0.99165 34.0 113.0 3.26 0.55 12.2 6 0 white 0.12 5.8 4 7.3 0.21 0.29 1.6 0.034 0.9917 29.0 118.0 3.3 0.5 11.0 8 1 white 0.19 5.8 5 6.7 0.64 0.23 2.1 0.08 0.99538 11.0 119.0 3.36 0.7 10.9 5 0 red 0.09 5.8 6 5.1 0.42 0.0 1.8 0.044 0.99157 18.0 88.0 3.68 0.73 13.6 7 1 red 0.01 5.8 7 7.7 0.3 0.32 1.6 0.037 0.9919 23.0 124.0 2.93 0.33 11.0 6 0 white 0.14 5.8 8 7.7 0.32 0.62 10.6 0.036 0.9978 56.0 153.0 3.13 0.44 8.9 6 0 white 0.0 5.8 9 6.7 0.105 0.32 12.4 0.051 0.998 34.0 106.0 3.54 0.45 9.2 6 0 white 0.03 5.8 10 7.6 0.21 0.44 1.9 0.036 0.9913 10.0 119.0 3.01 0.7 12.8 6 0 white 0.03 5.8 11 8.9 0.33 0.32 1.5 0.047 0.9954 11.0 200.0 3.19 0.46 9.4 5 0 white 0.01 5.8 12 6.5 0.19 0.32 1.4 0.04 0.9922 31.0 132.0 3.36 0.54 10.8 7 1 white 0.16 5.8 13 7.5 0.59 0.22 1.8 0.0819999999999999 0.99499 43.0 60.0 3.1 0.42 9.2 5 0 red 0.19 5.8 14 7.0 0.6 0.3 4.5 0.068 0.99914 20.0 110.0 3.3 1.17 10.2 5 0 red 0.0 5.8 15 7.0 0.62 0.1 1.4 0.071 0.996 27.0 63.0 3.28 0.61 9.2 5 0 red 0.1 5.8 16 5.4 0.74 0.0 1.2 0.0409999999999999 0.99258 16.0 46.0 4.01 0.59 12.5 6 0 red 0.19 5.8 17 7.5 0.27 0.79 11.95 0.04 0.99839 51.0 159.0 2.98 0.44 8.7 5 0 white 0.1 5.8 18 6.8 0.18 0.3 12.8 0.062 0.99808 19.0 171.0 3.0 0.52 9.0 7 1 white 0.18 5.8 19 5.4 0.5 0.13 5.0 0.028 0.99079 12.0 107.0 3.48 0.88 13.5 7 1 white 0.19 5.8 20 7.2 0.19 0.27 11.2 0.061 0.99772 46.0 149.0 2.99 0.59 9.3 6 0 white 0.01 5.8 21 6.8 0.3 0.22 6.2 0.06 0.99858 41.0 190.0 3.18 0.51 9.2 5 0 white 0.0 5.8 22 6.5 0.17 0.31 1.5 0.041 0.99092 34.0 121.0 3.06 0.46 10.5 6 0 white 0.07 5.8 23 6.2 0.21 0.26 13.1 0.05 0.99772 59.0 150.0 3.31 0.46 9.0 5 0 white 0.13 5.8 24 7.9 0.6 0.06 1.6 0.069 0.9964 15.0 59.0 3.3 0.46 9.4 5 0 red 0.08 5.8 25 7.3 0.65 0.0 1.2 0.065 0.9946 15.0 21.0 3.39 0.47 10.0 7 1 red 0.17 5.8 26 5.8 0.27 0.2 14.95 0.044 0.9962 22.0 179.0 3.37 0.37 10.2 5 0 white 0.17 5.8 27 6.5 0.17 0.54 8.5 0.082 0.9959 64.0 163.0 2.89 0.39 8.8 6 0 white 0.14 5.8 28 6.9 0.23 0.4 7.5 0.04 0.9927 50.0 151.0 3.11 0.27 11.4 6 0 white 0.13 5.8 29 5.8 0.25 0.26 13.1 0.051 0.9972 44.0 148.0 3.29 0.38 9.3 5 0 white 0.11 5.8 30 7.2 0.43 0.24 6.7 0.058 0.995 40.0 163.0 3.2 0.41 9.9 5 0 white 0.18 5.8 31 6.4 0.24 0.32 14.9 0.047 0.9968 54.0 162.0 3.28 0.5 10.2 6 0 white 0.13 5.8 32 6.1 0.25 0.49 7.6 0.052 0.9956 67.0 226.0 3.16 0.47 8.9 5 0 white 0.19 5.8 33 7.3 0.22 0.49 9.4 0.034 0.9939 29.0 134.0 2.99 0.32 11.0 7 1 white 0.07 5.8 34 6.4 0.18 0.74 11.9 0.046 0.9978 54.0 168.0 3.58 0.68 10.1 5 0 white 0.19 5.8 35 6.9 0.26 0.49 1.6 0.058 0.9965 39.0 166.0 3.65 0.52 9.4 4 0 white 0.11 5.8 36 7.0 0.35 0.3 6.5 0.028 0.9936 27.0 87.0 3.4 0.42 11.4 7 1 white 0.05 5.8 37 7.1 0.16 0.25 1.3 0.034 0.9915 28.0 123.0 3.27 0.55 11.4 6 0 white 0.17 5.8 38 10.0 0.91 0.42 1.6 0.056 0.9968 34.0 181.0 3.11 0.46 10.0 4 0 white 0.12 5.8 39 7.0 0.23 0.42 1.1 0.062 0.99318 35.0 100.0 3.04 0.4 9.2 5 0 white 0.05 5.8 40 6.4 0.14 0.28 7.9 0.057 0.99425 21.0 82.0 3.26 0.36 10.0 6 0 white 0.19 5.8 41 6.8 0.3 0.26 20.3 0.037 0.99727 45.0 150.0 3.04 0.38 12.3 6 0 white 0.2 5.8 42 6.8 0.29 0.32 1.8 0.032 0.99095 18.0 130.0 3.05 0.62 11.2 6 0 white 0.2 5.8 43 6.0 0.19 0.29 1.2 0.046 0.99033 29.0 92.0 3.22 0.53 11.3 6 0 white 0.1 5.8 44 6.2 0.36 0.22 5.25 0.038 0.99184 44.0 145.0 3.22 0.4 11.2 6 0 white 0.1 5.8 45 12.0 0.28 0.49 1.9 0.074 0.9976 10.0 21.0 2.98 0.66 9.9 7 1 red 0.05 5.8 46 6.4 0.57 0.02 1.8 0.067 0.997 4.0 11.0 3.46 0.68 9.5 5 0 red 0.18 5.8 47 7.0 0.45 0.34 2.7 0.0819999999999999 0.998 16.0 72.0 3.55 0.6 9.5 5 0 red 0.05 5.8 48 11.1 0.42 0.47 2.65 0.085 0.99736 9.0 34.0 3.24 0.77 12.1 7 1 red 0.14 5.8 49 8.2 0.26 0.34 2.5 0.073 0.99594 16.0 47.0 3.4 0.78 11.3 7 1 red 0.19 5.8 50 6.8 0.49 0.22 2.3 0.071 0.99438 13.0 24.0 3.41 0.83 11.3 6 0 red 0.05 5.8 51 7.2 0.6 0.04 2.5 0.076 0.99745 18.0 88.0 3.53 0.55 9.5 5 0 red 0.18 5.8 52 7.4 0.635 0.1 2.4 0.08 0.99736 16.0 33.0 3.58 0.69 10.8 7 1 red 0.02 5.8 53 7.9 0.3 0.27 8.5 0.036 0.9939 20.0 112.0 2.96 0.46 11.7 6 0 white 0.13 5.8 54 7.0 0.12 0.19 4.9 0.055 0.9953 27.0 127.0 3.29 0.41 9.4 5 0 white 0.16 5.8 55 6.8 0.27 0.28 13.3 0.076 0.9979 50.0 163.0 3.03 0.38 8.6 6 0 white 0.14 5.8 56 6.0 0.26 0.18 7.0 0.055 0.99591 50.0 194.0 3.21 0.43 9.0 5 0 white 0.19 5.8 57 6.8 0.21 0.55 14.6 0.053 0.99805 34.0 159.0 2.93 0.44 9.2 5 0 white 0.06 5.8 58 7.2 0.2 0.3 2.0 0.039 0.9911 43.0 188.0 3.3 0.41 12.0 6 0 white 0.04 5.8 59 7.8 0.735 0.08 2.4 0.092 0.9974 10.0 41.0 3.24 0.71 9.8 6 0 red 0.16 5.8 60 7.7 0.58 0.1 1.8 0.102 0.99565 28.0 109.0 3.08 0.49 9.8 6 0 red 0.17 5.8 61 10.6 0.28 0.39 15.5 0.069 1.0026 6.0 23.0 3.12 0.66 9.2 5 0 red 0.15 5.8 62 10.4 0.44 0.73 6.55 0.074 0.999 38.0 76.0 3.17 0.85 12.0 7 1 red 0.09 5.8 63 6.4 0.32 0.27 4.9 0.034 0.9916 18.0 122.0 3.36 0.71 12.5 6 0 white 0.17 5.8 64 6.7 0.3 0.44 18.75 0.057 0.99956 65.0 224.0 3.11 0.53 9.1 5 0 white 0.09 5.8 65 6.6 0.29 0.29 1.8 0.036 0.98819 38.0 102.0 3.08 0.42 13.7 7 1 white 0.1 5.8 66 6.8 0.26 0.46 8.3 0.037 0.99601 49.0 173.0 3.17 0.47 9.3 5 0 white 0.2 5.8 67 7.5 0.38 0.29 4.9 0.021 0.99026 38.0 113.0 3.08 0.48 13.0 7 1 white 0.19 5.8 68 6.2 0.16 0.32 1.1 0.036 0.99096 74.0 184.0 3.22 0.41 11.0 6 0 white 0.12 5.8 69 7.7 0.25 0.49 2.5 0.047 0.99252 31.0 169.0 3.07 0.57 10.6 6 0 white 0.0 5.8 70 6.4 0.17 0.27 9.9 0.047 0.99596 26.0 101.0 3.34 0.5 9.9 6 0 white 0.07 5.8 71 6.6 0.18 0.28 1.7 0.041 0.99207 53.0 161.0 3.13 0.45 10.2 6 0 white 0.19 5.8 72 7.1 0.2 0.27 9.6 0.037 0.99444 19.0 105.0 3.04 0.37 10.5 7 1 white 0.11 5.8 73 7.7 0.3 0.23 2.0 0.068 0.99382 28.0 138.0 3.11 0.62 9.8 5 0 white 0.03 5.8 74 6.9 0.21 0.62 6.3 0.042 0.99358 7.0 109.0 2.96 0.59 10.2 6 0 white 0.01 5.8 75 7.3 0.24 0.3 2.5 0.042 0.9911 31.0 104.0 3.05 0.56 11.3 7 1 white 0.09 5.8 76 6.6 0.18 0.26 17.3 0.051 0.9984 17.0 149.0 3.0 0.43 9.4 6 0 white 0.19 5.8 77 6.1 0.44 0.28 4.25 0.032 0.9916 43.0 132.0 3.26 0.47 11.3 7 1 white 0.02 5.8 78 6.5 0.5 0.22 4.1 0.036 0.9902 35.0 131.0 3.26 0.55 13.0 7 1 white 0.04 5.8 79 6.0 0.24 0.41 1.3 0.036 0.99018 42.0 118.0 3.04 0.64 11.7333333333333 6 0 white 0.0 5.8 80 6.0 0.29 0.41 10.8 0.048 0.9937 55.0 149.0 3.09 0.59 11.0 7 1 white 0.19 5.8 81 6.4 0.19 0.35 10.2 0.043 0.99632 40.0 106.0 3.16 0.5 9.7 6 0 white 0.19 5.8 82 7.1 0.68 0.0 2.3 0.087 0.99783 17.0 26.0 3.45 0.53 9.5 5 0 red 0.1 5.8 83 6.9 0.2 0.37 6.2 0.027 0.992 24.0 97.0 3.38 0.49 12.2 7 1 white 0.12 5.8 84 6.8 0.25 0.24 4.55 0.053 0.9955 41.0 211.0 3.37 0.67 9.5 6 0 white 0.16 5.8 85 7.4 0.3 0.22 1.4 0.046 0.9928 16.0 135.0 3.08 0.77 10.4 7 1 white 0.13 5.8 86 6.3 0.26 0.49 1.5 0.052 0.9924 34.0 134.0 2.99 0.61 9.8 6 0 white 0.07 5.8 87 6.1 0.17 0.28 4.5 0.033 0.9933 46.0 150.0 3.43 0.49 10.9 6 0 white 0.2 5.8 88 6.5 0.21 0.37 2.5 0.048 0.9917 70.0 138.0 3.33 0.75 11.4 7 1 white 0.19 5.8 89 6.4 0.31 0.26 13.2 0.046 0.9975 57.0 205.0 3.17 0.41 9.6 5 0 white 0.1 5.8 90 7.9 0.33 0.41 1.5 0.0559999999999999 0.99396 6.0 35.0 3.29 0.71 11.0 6 0 red 0.11 5.8 91 10.6 0.36 0.57 2.3 0.087 0.99676 6.0 20.0 3.14 0.72 11.1 7 1 red 0.09 5.8 92 6.7 0.15 0.29 5.0 0.058 0.9946 28.0 105.0 3.52 0.44 10.2 7 1 white 0.07 5.8 93 6.0 0.41 0.21 1.9 0.05 0.9928 29.0 122.0 3.42 0.52 10.5 6 0 white 0.16 5.8 94 8.0 0.55 0.17 8.2 0.04 0.9956 13.0 60.0 3.09 0.3 9.5 4 0 white 0.05 5.8 95 6.3 0.6 0.44 11.0 0.05 0.9972 50.0 245.0 3.19 0.57 9.3 4 0 white 0.11 5.8 96 6.4 0.3 0.51 5.5 0.048 0.9942 62.0 172.0 3.08 0.45 9.1 6 0 white 0.16 5.8 97 6.9 0.2 0.36 1.5 0.031 0.9931 38.0 147.0 3.35 0.56 11.0 6 0 white 0.04 5.8 98 9.2 0.28 0.46 3.2 0.058 0.996 39.0 133.0 3.14 0.58 9.5 5 0 white 0.0 5.8 99 7.8 0.3 0.29 16.85 0.054 0.9998 23.0 135.0 3.16 0.38 9.0 6 0 white 0.18 5.8 100 6.4 0.3 0.38 7.8 0.046 0.9955 35.0 192.0 3.1 0.37 9.0 5 0 white 0.01 5.8 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.Parameter Modification¶
In order to see the parameters:
model.get_params()
And to manually change some of the parameters:
model.set_params({'n_neighbors': 3})
- __init__(name: str = None, overwrite_model: bool = False, n_neighbors: int = 5, p: int = 2) None¶
Methods
__init__([name, overwrite_model, n_neighbors, p])contour([nbins, chart])Draws the model's contour plot.
deploySQL([X, test_relation, key_columns])Returns the SQL code needed to deploy the model.
drop()KNeighborsRegressormodels are not stored in the VAST DataBase.export_models(name, path[, kind])Exports machine learning models.
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.
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.
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