DecisionTreeRegressor¶
In [ ]:
DecisionTreeRegressor(name: str,
cursor = None,
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 DecisionTreeRegressor made of a single tree.
Parameters¶
| Name | Type | Optional | Description |
|---|---|---|---|
name | str | ❌ | Name of the model to be stored in the database. |
cursor | DBcursor | ✓ | Vertica database cursor. |
max_features | str | ✓ | The number of randomly chosen features from which to pick the best feature to split on a given tree node. It can be an integer or one of the two following methods.
|
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 |
|---|---|---|
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 |
|---|---|
| contour | Draws the model's contour plot. |
| deploySQL | Returns the SQL code needed to deploy the model. |
| drop | Drops the model from the Vertica database. |
| features_importance | Computes importance of each feature in the model 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. |
| plot | Draws the Model. |
| plot_tree | Draws the input tree (requires the graphviz module). |
| predict | Predicts using the input relation. |
| regression_report | Computes a regression report using multiple metrics to evaluate the model (r2, mse, max error...). |
| score | Computes the model score. |
| set_cursor | Sets a new database cursor. |
| set_params | Sets the parameters of the model. |
| shapExplainer | Creates a shapExplainer for 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_sklearn | Converts this Vertica model to an sklearn model. |
| to_sql | Returns the SQL code needed to deploy the model without using Vertica built-in functions. |
Example¶
In [6]:
from verticapy.learn.tree import DecisionTreeRegressor
model = DecisionTreeRegressor(name = "public.rf_winequality",
max_features = "auto",
max_leaf_nodes = 32,
max_depth = 3,
min_samples_leaf = 5,
min_info_gain = 0.0,
nbins = 32)
display(model)
