NearestCentroid (Beta)

In [ ]:
NearestCentroid(name: str,
                cursor = None,
                p: int = 2)

Creates a NearestCentroid object by using the k-nearest centroid algorithm. This object uses pure SQL to compute all the distances and final score.

⚠ Warning: This function uses the p-distance, which makes it very sensitive to unnormalized data.

Parameters

Name Type Optional Description
name
str
Name of the model to be stored in the database.
cursor
DBcursor
Vertica DB cursor.
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
centroids_
tablesample
The final centroids.
classes_
list
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 the model methods are abstractions which will simplify the process. The test relation will be used by many methods to evaluate the model. If empty, the training relation will be used as test. You can change it anytime by changing the test_relation attribute of the object.

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 ROC curve.
score Computes the model score.
set_cursor Sets a new DB cursor.
set_params Sets the parameters of the model.
shapExplainer Creates a shapExplainer for the model.
to_sklearn Converts the Vertica Model to an sklearn model.

Example

In [15]:
from verticapy.learn.neighbors import NearestCentroid
model = NearestCentroid(p = 2)
display(model)
<NearestCentroid>