NaiveBayes

In [ ]:
NaiveBayes(name: str,
           alpha: float = 1.0,
           nbtype: str = "auto")

Creates a NaiveBayes object using the Vertica Naive Bayes' algorithm. It is a "probabilistic classifier" that applies Bayes' theorem with strong (naïve) independence assumptions between features.

Parameters

Name Type Optional Description
name
str
❌
Name of the model to be stored in the DB.
alpha
float
✓
A float that specifies use of Laplace smoothing if the event model is categorical, multinomial, or Bernoulli.
nbtype
str
✓
Naive Bayes Type.
  • auto: Vertica NB will treat columns according to data type:
    • Float Values are assumed to follow some Gaussian distribution.
    • Integer Values are assumed to belong to one multinomial distribution.
    • Str Values are assumed to follow some categorical distribution. The string values stored in these columns must not be greater than 128 characters.
    • Boolean Values are treated as categorical with two values.
  • bernoulli: Casts the variables to boolean.
  • categorical: Casts the variables to categorical.
  • multinomial: Casts the variables to integer.
  • gaussian: Casts the variables to float.

Attributes

After the object creation, all the parameters become attributes. The model will also create extra attributes when fitting the model:

Name Type Description
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 / 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.
contour Draws the model's contour plot.
cutoff_curve Draws the model Cutoff curve.
deploySQL Returns the SQL code needed to deploy the model.
drop Drops the model from the Vertica DB.
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 precision-recall curve.
predict Predicts using the input relation.
predict_proba Returns the model's probabilities using the input relation.
roc_curve Draws the model ROC curve.
score Computes the model score.
set_params Sets the parameters of the model.
to_memmodel Converts a specified Vertica model to a memModel model.
to_python Returns the Python code needed to deploy the model without using built-in Vertica functions.
to_sql Returns the SQL code needed to deploy the model without using Vertica built-in functions.

Example

In [1]:
from verticapy.learn.naive_bayes import NaiveBayes
model = NaiveBayes(name = "public.nb_titanic", alpha = 1.0)
display(model)
<NaiveBayes>