Class: DecisionTreeClassifier
A decision tree classifier.
Read more in the User Guide.
Constructors
new DecisionTreeClassifier()
new DecisionTreeClassifier(
opts
?):DecisionTreeClassifier
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.ccp_alpha ? | any | Complexity parameter used for Minimal Cost-Complexity Pruning. The subtree with the largest cost complexity that is smaller than ccp_alpha will be chosen. By default, no pruning is performed. See Minimal Cost-Complexity Pruning for details. |
opts.class_weight ? | any | Weights associated with classes in the form {class_label: weight} . If undefined , all classes are supposed to have weight one. For multi-output problems, a list of dicts can be provided in the same order as the columns of y. Note that for multioutput (including multilabel) weights should be defined for each class of every column in its own dict. For example, for four-class multilabel classification weights should be [{0: 1, 1: 1}, {0: 1, 1: 5}, {0: 1, 1: 1}, {0: 1, 1: 1}] instead of [{1:1}, {2:5}, {3:1}, {4:1}]. The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n_samples / (n_classes \* np.bincount(y)) For multi-output, the weights of each column of y will be multiplied. Note that these weights will be multiplied with sample_weight (passed through the fit method) if sample_weight is specified. |
opts.criterion ? | "gini" | "entropy" | "log_loss" | The function to measure the quality of a split. Supported criteria are “gini” for the Gini impurity and “log_loss” and “entropy” both for the Shannon information gain, see Mathematical formulation. |
opts.max_depth ? | number | The maximum depth of the tree. If undefined , then nodes are expanded until all leaves are pure or until all leaves contain less than min_samples_split samples. |
opts.max_features ? | number | "sqrt" | "log2" | The number of features to consider when looking for the best split: |
opts.max_leaf_nodes ? | number | Grow a tree with max_leaf_nodes in best-first fashion. Best nodes are defined as relative reduction in impurity. If undefined then unlimited number of leaf nodes. |
opts.min_impurity_decrease ? | number | A node will be split if this split induces a decrease of the impurity greater than or equal to this value. The weighted impurity decrease equation is the following: |
opts.min_samples_leaf ? | number | The minimum number of samples required to be at a leaf node. A split point at any depth will only be considered if it leaves at least min_samples_leaf training samples in each of the left and right branches. This may have the effect of smoothing the model, especially in regression. |
opts.min_samples_split ? | number | The minimum number of samples required to split an internal node: |
opts.min_weight_fraction_leaf ? | number | The minimum weighted fraction of the sum total of weights (of all the input samples) required to be at a leaf node. Samples have equal weight when sample_weight is not provided. |
opts.monotonic_cst ? | any [] | 1: monotonic increase |
opts.random_state ? | number | Controls the randomness of the estimator. The features are always randomly permuted at each split, even if splitter is set to "best" . When max_features < n_features , the algorithm will select max_features at random at each split before finding the best split among them. But the best found split may vary across different runs, even if max_features=n_features . That is the case, if the improvement of the criterion is identical for several splits and one split has to be selected at random. To obtain a deterministic behaviour during fitting, random_state has to be fixed to an integer. See Glossary for details. |
opts.splitter ? | "random" | "best" | The strategy used to choose the split at each node. Supported strategies are “best” to choose the best split and “random” to choose the best random split. |
Returns DecisionTreeClassifier
Defined in generated/tree/DecisionTreeClassifier.ts:23
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/tree/DecisionTreeClassifier.ts:21 |
_isInitialized | boolean | false | generated/tree/DecisionTreeClassifier.ts:20 |
_py | PythonBridge | undefined | generated/tree/DecisionTreeClassifier.ts:19 |
id | string | undefined | generated/tree/DecisionTreeClassifier.ts:16 |
opts | any | undefined | generated/tree/DecisionTreeClassifier.ts:17 |
Accessors
classes_
Get Signature
get classes_():
Promise
<ArrayLike
>
The classes labels (single output problem), or a list of arrays of class labels (multi-output problem).
Returns Promise
<ArrayLike
>
Defined in generated/tree/DecisionTreeClassifier.ts:810
feature_names_in_
Get Signature
get feature_names_in_():
Promise
<ArrayLike
>
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Returns Promise
<ArrayLike
>
Defined in generated/tree/DecisionTreeClassifier.ts:918
max_features_
Get Signature
get max_features_():
Promise
<number
>
The inferred value of max_features.
Returns Promise
<number
>
Defined in generated/tree/DecisionTreeClassifier.ts:837
n_classes_
Get Signature
get n_classes_():
Promise
<number
>
The number of classes (for single output problems), or a list containing the number of classes for each output (for multi-output problems).
Returns Promise
<number
>
Defined in generated/tree/DecisionTreeClassifier.ts:864
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/tree/DecisionTreeClassifier.ts:891
n_outputs_
Get Signature
get n_outputs_():
Promise
<number
>
The number of outputs when fit
is performed.
Returns Promise
<number
>
Defined in generated/tree/DecisionTreeClassifier.ts:945
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/tree/DecisionTreeClassifier.ts:117
tree_
Get Signature
get tree_():
Promise
<any
>
The underlying Tree object. Please refer to help(sklearn.tree._tree.Tree)
for attributes of Tree object and Understanding the decision tree structure for basic usage of these attributes.
Returns Promise
<any
>
Defined in generated/tree/DecisionTreeClassifier.ts:972
Methods
apply()
apply(
opts
):Promise
<ArrayLike
>
Return the index of the leaf that each sample is predicted as.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.check_input ? | boolean | Allow to bypass several input checking. Don’t use this parameter unless you know what you’re doing. |
opts.X ? | ArrayLike | The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix . |
Returns Promise
<ArrayLike
>
Defined in generated/tree/DecisionTreeClassifier.ts:190
cost_complexity_pruning_path()
cost_complexity_pruning_path(
opts
):Promise
<any
>
Compute the pruning path during Minimal Cost-Complexity Pruning.
See Minimal Cost-Complexity Pruning for details on the pruning process.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. If undefined , then samples are equally weighted. Splits that would create child nodes with net zero or negative weight are ignored while searching for a split in each node. Splits are also ignored if they would result in any single class carrying a negative weight in either child node. |
opts.X ? | ArrayLike | The training input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csc_matrix . |
opts.y ? | ArrayLike | The target values (class labels) as integers or strings. |
Returns Promise
<any
>
Defined in generated/tree/DecisionTreeClassifier.ts:233
decision_path()
decision_path(
opts
):Promise
<any
[]>
Return the decision path in the tree.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.check_input ? | boolean | Allow to bypass several input checking. Don’t use this parameter unless you know what you’re doing. |
opts.X ? | ArrayLike | The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix . |
Returns Promise
<any
[]>
Defined in generated/tree/DecisionTreeClassifier.ts:279
dispose()
dispose():
Promise
<void
>
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Returns Promise
<void
>
Defined in generated/tree/DecisionTreeClassifier.ts:173
fit()
fit(
opts
):Promise
<any
>
Build a decision tree classifier from the training set (X, y).
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.check_input ? | boolean | Allow to bypass several input checking. Don’t use this parameter unless you know what you’re doing. |
opts.sample_weight ? | ArrayLike | Sample weights. If undefined , then samples are equally weighted. Splits that would create child nodes with net zero or negative weight are ignored while searching for a split in each node. Splits are also ignored if they would result in any single class carrying a negative weight in either child node. |
opts.X ? | ArrayLike | The training input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csc_matrix . |
opts.y ? | ArrayLike | The target values (class labels) as integers or strings. |
Returns Promise
<any
>
Defined in generated/tree/DecisionTreeClassifier.ts:322
get_depth()
get_depth(
opts
):Promise
<any
>
Return the depth of the decision tree.
The depth of a tree is the maximum distance between the root and any leaf.
Parameters
Parameter | Type |
---|---|
opts | object |
Returns Promise
<any
>
Defined in generated/tree/DecisionTreeClassifier.ts:375
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRequest encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/tree/DecisionTreeClassifier.ts:407
get_n_leaves()
get_n_leaves(
opts
):Promise
<any
>
Return the number of leaves of the decision tree.
Parameters
Parameter | Type |
---|---|
opts | object |
Returns Promise
<any
>
Defined in generated/tree/DecisionTreeClassifier.ts:443
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/tree/DecisionTreeClassifier.ts:130
predict()
predict(
opts
):Promise
<ArrayLike
>
Predict class or regression value for X.
For a classification model, the predicted class for each sample in X is returned. For a regression model, the predicted value based on X is returned.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.check_input ? | boolean | Allow to bypass several input checking. Don’t use this parameter unless you know what you’re doing. |
opts.X ? | ArrayLike | The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix . |
Returns Promise
<ArrayLike
>
Defined in generated/tree/DecisionTreeClassifier.ts:475
predict_log_proba()
predict_log_proba(
opts
):Promise
<ArrayLike
[]>
Predict class log-probabilities of the input samples X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix . |
Returns Promise
<ArrayLike
[]>
Defined in generated/tree/DecisionTreeClassifier.ts:518
predict_proba()
predict_proba(
opts
):Promise
<ArrayLike
[]>
Predict class probabilities of the input samples X.
The predicted class probability is the fraction of samples of the same class in a leaf.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.check_input ? | boolean | Allow to bypass several input checking. Don’t use this parameter unless you know what you’re doing. |
opts.X ? | ArrayLike | The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix . |
Returns Promise
<ArrayLike
[]>
Defined in generated/tree/DecisionTreeClassifier.ts:556
score()
score(
opts
):Promise
<number
>
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. |
opts.X ? | ArrayLike [] | Test samples. |
opts.y ? | ArrayLike | True labels for X . |
Returns Promise
<number
>
Defined in generated/tree/DecisionTreeClassifier.ts:601
set_fit_request()
set_fit_request(
opts
):Promise
<any
>
Request metadata passed to the fit
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.check_input ? | string | boolean | Metadata routing for check_input parameter in fit . |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in fit . |
Returns Promise
<any
>
Defined in generated/tree/DecisionTreeClassifier.ts:649
set_predict_proba_request()
set_predict_proba_request(
opts
):Promise
<any
>
Request metadata passed to the predict_proba
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.check_input ? | string | boolean | Metadata routing for check_input parameter in predict_proba . |
Returns Promise
<any
>
Defined in generated/tree/DecisionTreeClassifier.ts:694
set_predict_request()
set_predict_request(
opts
):Promise
<any
>
Request metadata passed to the predict
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.check_input ? | string | boolean | Metadata routing for check_input parameter in predict . |
Returns Promise
<any
>
Defined in generated/tree/DecisionTreeClassifier.ts:734
set_score_request()
set_score_request(
opts
):Promise
<any
>
Request metadata passed to the score
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in score . |
Returns Promise
<any
>
Defined in generated/tree/DecisionTreeClassifier.ts:774