
VerticaPy
Example: Methods in a Binary Classification Model¶
In this example, we use the 'Titanic' dataset to demonstrate the methods available to binary classification models.
from verticapy.datasets import load_titanic
titanic = load_titanic()
display(titanic)
Let's create a logistic regression to predict the survival of the passengers. We'll use the age and the fare as predictors.
from verticapy.learn.linear_model import LogisticRegression
model = LogisticRegression("public.LR_titanic")
model.fit("public.titanic", ["age", "fare"], "survived")
Fitting the model creates new model attributes, making methods easier to use.
model.X
model.y
model.input_relation
model.test_relation
Since we didn't write a test relation when fitting the model, the model will use the training relation as the test relation.
Let's compute the accuracy of the model.
model.score(method = "accuracy")
The 'score' method uses the 'y' attribute and the model prediction in the 'test_relation' to compute the accuracy of the model. You can change these attributes at any time to deploy the models on different columns.
Models have many useful attributes. For example, the 'coef_' attribute gives us the p-value of the model.
model.coef_
You can view other attributes using the 'get_attr' method.
model.get_attr()
PRC, ROC or lift charts can help you visualize your model.
model.roc_curve()
model.prc_curve()
model.lift_chart()
Let's look at the SQL query for our model.
display(model.deploySQL())
You can evaluate the quality of your model with the 'classification_report' method.
model.classification_report()
You can also add the prediction to your vDataFrame.
model.predict(titanic, name = "pred_survived")