KNeighborsClassifier (Beta)¶
In [ ]:
KNeighborsClassifier(name: str,
cursor = None,
n_neighbors: int = 5,
p: int = 2)
Creates a KNeighborsClassifier object by 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. |
cursor | DBcursor | ✓ | Vertica DB cursor. |
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 is created, all parameters become attributes. Additional attributes will be created when fitting the model:
Name | Type | Description |
---|---|---|
classes_ | str | List of all the response classes. |
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 |
---|---|
classification_report | Computes a classification report using multiple metrics to evaluate the model (AUC, accuracy, PRC AUC, F1...). In case of multiclass classification, it will consider each category as positive and switch to the next one during the computation. |
confusion_matrix | Computes the model confusion matrix. |
cutoff_curve | Draws the model Cutoff curve. |
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. |
lift_chart | Draws the model Lift Chart. |
prc_curve | Draws the model PRC curve. |
predict | Predicts using the input relation. |
roc_curve | Draws the model precision-recall curve. |
score | Computes the model score. |
set_cursor | Sets a new DB cursor. |
set_params | Sets the parameters of the model. |
Example¶
In [14]:
from verticapy.learn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier(n_neighbors = 5,
p = 2)
display(model)