DecisionTreeClassifier

In [ ]:
DecisionTreeClassifier(name: str,
                       max_features = "auto",
                       max_leaf_nodes: int = 1e9,
                       max_depth: int = 5,
                       min_samples_leaf: int = 1,
                       min_info_gain: float = 0.0,
                       nbins: int = 32)

A DecisionTreeClassifier made of a single tree.

Parameters

Name Type Optional Description
name
str
Name of the model to be stored in the database.
max_features
str
The number of randomly chosen features from which to pick the best feature to split on a given tree node. This can be an integer or one of the two following methods.
  • auto: square root of the total number of predictors.
  • max: number of predictors.
max_leaf_nodes
int
The maximum number of leaf nodes a tree in the forest can have: an integer between 1 and 1e9, inclusive.
max_depth
int
The maximum depth for growing each tree: an integer between 1 and 100, inclusive.
min_samples_leaf
int
The minimum number of samples each branch must have after splitting a node: an integer between 1 and 1e6, inclusive. A split that produces fewer remaining samples is discarded.
min_info_gain
float
The minimum threshold for including a split: a float between 0.0 and 1.0, inclusive. Splits that gain less information than this threshold are discarded.
nbins
int
The number of bins to use for continuous features: an integer between 2 and 1000, inclusive.

Attributes

After the object is created, all parameters become attributes. Additional attributes will be created 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 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 / report Computes a classification report using various metrics to evaluate the model (AUC, accuracy, PRC AUC, F1...). For 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's Cutoff curve.
deploySQL Returns the SQL code needed to deploy the model.
drop Drops the model from the Vertica database.
features_importance Computes the model features importance using the Gini Index.
fit Trains the model.
get_attr Returns the model attribute.
get_params Returns the model parameters.
get_tree Returns a tablesample with all the input tree information.
lift_chart Draws the model's lift chart.
plot_tree Draws the input tree (requires the graphviz module).
prc_curve Draws the model's PRC curve.
predict Predicts using the input relation.
predict_proba Returns the model's probabilities using the input relation.
roc_curve Draws the model's ROC curve.
score Computes the model's score.
set_params Sets the parameters of the model.
to_graphviz Converts the input tree to a Graphviz tree.
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 [3]:
from verticapy.learn.tree import DecisionTreeClassifier
model = DecisionTreeClassifier(name = "public.rf_titanic",
                               max_features = "auto",
                               max_leaf_nodes = 32,
                               max_depth = 3,
                               min_samples_leaf = 5,
                               min_info_gain = 0.0,
                               nbins = 32)
display(model)
<RandomForestClassifier>