KNeighborsRegressor (Beta)¶
In [ ]:
KNeighborsRegressor(name: str,
n_neighbors: int = 5,
p: int = 2)
Creates a KNeighborsRegressor object using the k-nearest neighbors algorithm. This object uses pure SQL to compute all the distances and final score.
⚠ Warning: This algorithm is computationally expensive; It uses a CROSS JOIN during the computation, the complexity of which is O(n * n), where n is the total number of elements. This algorithm uses the p-distance so it is very sensitive to unnnormalized data.
Parameters¶
| Name | Type | Optional | Description |
|---|---|---|---|
name | str | ❌ | Name of the model to be stored in the database. |
n_neighbors | int | ✓ | Number of neighbors to consider when computing the score. |
p | int | ✓ | The p corresponding to the one of the p-distance (distance metric used during the model computation). |
Attributes¶
After the object creation, all the parameters become attributes. The model will also create extra attributes when fitting the model:
| Name | Type | Description |
|---|---|---|
input_relation | str | Training relation. |
X | list | List of the predictors. |
y | str | Response column. |
test_relation | str | Relation to use to test the model. All model methods are abstractions that simplify the process. The testing relation will be used by the methods to evaluate the model. If empty, the training relation will be used instead. This attribute can be changed at any time. |
Methods¶
| Name | Description |
|---|---|
| contour | Draws the model's contour plot. |
| deploySQL | Returns the SQL code needed to deploy the model. |
| fit | Trains the model. |
| get_attr | Returns the model attribute. |
| get_params | Returns the model parameters. |
| predict | Predicts using the input relation. |
| regression_report / report | Computes a regression report using multiple metrics to evaluate the model (r2, mse, max error...). |
| score | Computes the model score. |
| set_params | Sets the parameters of the model. |
Example¶
In [13]:
from verticapy.learn.neighbors import KNeighborsRegressor
model = KNeighborsRegressor(n_neighbors = 5,
p = 2)
display(model)
