A decision tree classifier.
Read more in the User Guide.
new DecisionTreeClassifier(opts?: object): DecisionTreeClassifier;
Name | 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. Default Value 0 |
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. Default Value 'gini' |
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 | "auto" | "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: Default Value 0 |
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. Default Value 1 |
opts.min_samples_split? |
number |
The minimum number of samples required to split an internal node: Default Value 2 |
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. Default Value 0 |
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. Default Value 'best' |
Defined in: generated/tree/DecisionTreeClassifier.ts:23
Return the index of the leaf that each sample is predicted as.
apply(opts: object): Promise<ArrayLike>;
Name | 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 . |
opts.check_input? |
boolean |
Allow to bypass several input checking. Don’t use this parameter unless you know what you’re doing. Default Value true |
Promise
<ArrayLike
>
Defined in: generated/tree/DecisionTreeClassifier.ts:204
Compute the pruning path during Minimal Cost-Complexity Pruning.
See Minimal Cost-Complexity Pruning for details on the pruning process.
cost_complexity_pruning_path(opts: object): Promise<any>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
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.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.y? |
ArrayLike |
The target values (class labels) as integers or strings. |
Promise
<any
>
Defined in: generated/tree/DecisionTreeClassifier.ts:250
Return the decision path in the tree.
decision_path(opts: object): Promise<any[]>;
Name | 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 . |
opts.check_input? |
boolean |
Allow to bypass several input checking. Don’t use this parameter unless you know what you’re doing. Default Value true |
Promise
<any
[]>
Defined in: generated/tree/DecisionTreeClassifier.ts:302
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
dispose(): Promise<void>;
Promise
<void
>
Defined in: generated/tree/DecisionTreeClassifier.ts:187
Build a decision tree classifier from the training set (X, y).
fit(opts: object): Promise<any>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
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.check_input? |
boolean |
Allow to bypass several input checking. Don’t use this parameter unless you know what you’re doing. Default Value true |
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.y? |
ArrayLike |
The target values (class labels) as integers or strings. |
Promise
<any
>
Defined in: generated/tree/DecisionTreeClassifier.ts:349
Return the depth of the decision tree.
The depth of a tree is the maximum distance between the root and any leaf.
get_depth(opts: object): Promise<any>;
Name | Type |
---|---|
opts |
object |
Promise
<any
>
Defined in: generated/tree/DecisionTreeClassifier.ts:409
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
get_metadata_routing(opts: object): Promise<any>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
opts.routing? |
any |
A MetadataRequest encapsulating routing information. |
Promise
<any
>
Defined in: generated/tree/DecisionTreeClassifier.ts:441
Return the number of leaves of the decision tree.
get_n_leaves(opts: object): Promise<any>;
Name | Type |
---|---|
opts |
object |
Promise
<any
>
Defined in: generated/tree/DecisionTreeClassifier.ts:479
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
init(py: PythonBridge): Promise<void>;
Name | Type |
---|---|
py |
PythonBridge |
Promise
<void
>
Defined in: generated/tree/DecisionTreeClassifier.ts:125
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.
predict(opts: object): Promise<ArrayLike>;
Name | 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 . |
opts.check_input? |
boolean |
Allow to bypass several input checking. Don’t use this parameter unless you know what you’re doing. Default Value true |
Promise
<ArrayLike
>
Defined in: generated/tree/DecisionTreeClassifier.ts:511
Predict class log-probabilities of the input samples X.
predict_log_proba(opts: object): Promise<ArrayLike[]>;
Name | 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 . |
Promise
<ArrayLike
[]>
Defined in: generated/tree/DecisionTreeClassifier.ts:557
Predict class probabilities of the input samples X.
The predicted class probability is the fraction of samples of the same class in a leaf.
predict_proba(opts: object): Promise<ArrayLike[]>;
Name | 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 . |
opts.check_input? |
boolean |
Allow to bypass several input checking. Don’t use this parameter unless you know what you’re doing. Default Value true |
Promise
<ArrayLike
[]>
Defined in: generated/tree/DecisionTreeClassifier.ts:597
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.
score(opts: object): Promise<number>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
opts.X? |
ArrayLike [] |
Test samples. |
opts.sample_weight? |
ArrayLike |
Sample weights. |
opts.y? |
ArrayLike |
True labels for X . |
Promise
<number
>
Defined in: generated/tree/DecisionTreeClassifier.ts:646
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:
set_fit_request(opts: object): Promise<any>;
Name | 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 . |
Promise
<any
>
Defined in: generated/tree/DecisionTreeClassifier.ts:699
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:
set_predict_proba_request(opts: object): Promise<any>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
opts.check_input? |
string | boolean |
Metadata routing for check\_input parameter in predict\_proba . |
Promise
<any
>
Defined in: generated/tree/DecisionTreeClassifier.ts:746
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:
set_predict_request(opts: object): Promise<any>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
opts.check_input? |
string | boolean |
Metadata routing for check\_input parameter in predict . |
Promise
<any
>
Defined in: generated/tree/DecisionTreeClassifier.ts:788
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:
set_score_request(opts: object): Promise<any>;
Name | Type | Description |
---|---|---|
opts |
object |
- |
opts.sample_weight? |
string | boolean |
Metadata routing for sample\_weight parameter in score . |
Promise
<any
>
Defined in: generated/tree/DecisionTreeClassifier.ts:830
boolean
=false
Defined in: generated/tree/DecisionTreeClassifier.ts:21
boolean
=false
Defined in: generated/tree/DecisionTreeClassifier.ts:20
PythonBridge
Defined in: generated/tree/DecisionTreeClassifier.ts:19
string
Defined in: generated/tree/DecisionTreeClassifier.ts:16
any
Defined in: generated/tree/DecisionTreeClassifier.ts:17
The classes labels (single output problem), or a list of arrays of class labels (multi-output problem).
classes_(): Promise<ArrayLike>;
Promise
<ArrayLike
>
Defined in: generated/tree/DecisionTreeClassifier.ts:868
Names of features seen during fit. Defined only when X
has feature names that are all strings.
feature_names_in_(): Promise<ArrayLike>;
Promise
<ArrayLike
>
Defined in: generated/tree/DecisionTreeClassifier.ts:976
The inferred value of max_features.
max_features_(): Promise<number>;
Promise
<number
>
Defined in: generated/tree/DecisionTreeClassifier.ts:895
The number of classes (for single output problems), or a list containing the number of classes for each output (for multi-output problems).
n_classes_(): Promise<number>;
Promise
<number
>
Defined in: generated/tree/DecisionTreeClassifier.ts:922
Number of features seen during fit.
n_features_in_(): Promise<number>;
Promise
<number
>
Defined in: generated/tree/DecisionTreeClassifier.ts:949
The number of outputs when fit
is performed.
n_outputs_(): Promise<number>;
Promise
<number
>
Defined in: generated/tree/DecisionTreeClassifier.ts:1003
py(): PythonBridge;
PythonBridge
Defined in: generated/tree/DecisionTreeClassifier.ts:112
py(pythonBridge: PythonBridge): void;
Name | Type |
---|---|
pythonBridge |
PythonBridge |
void
Defined in: generated/tree/DecisionTreeClassifier.ts:116
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.
tree_(): Promise<any>;
Promise
<any
>
Defined in: generated/tree/DecisionTreeClassifier.ts:1030