RegressionSplitter#
- class RegressionSplitter(criterion='squared_error', min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, min_impurity_decrease=0.0)[source]#
Bases:
DecisionTreeSplitterSplitter for regression that maximizes the decrease of impurity.
The numerical features are split by a scikit-learn
DecisionTreeRegressorof depth 1 with the same parameters (x <= thresholdgoes left). Then each value of each categorical feature is tested (x == valuegoes left), and the best categorical split replaces the numerical one if its gain is higher (see DecisionTreeSplitter).- Parameters:
criterion ({'squared_error', 'absolute_error', 'poisson'} or callable, default='squared_error') – Impurity measure. A callable
f(y_true, y_pred) -> float(e.g. a scikit-learn metric) is supported only for categorical features.min_samples_leaf (int or float, default=1) – Minimum number of instances in each child (a fraction of the instances of the node if float). Applies to the numerical features.
min_weight_fraction_leaf (float, default=0.0) – Minimum fraction of the sample weights of the node in each child. Applies to the numerical features.
max_features (int, float, {'sqrt', 'log2'} or None, default=None) – Number of numerical features considered for the split, drawn at random; None for all.
random_state (int, RandomState instance or None, default=None) – Seed of the choice of the features (
max_features) and of the ties between features with the same gain. With None, a tree gives the stump its ownrandom_state.min_impurity_decrease (float, default=0.0) – A numerical split is kept only if it decreases the weighted impurity by at least this value.
- Variables:
feature (int) – Column of the feature matrix used by the split.
threshold (float or object) – Threshold of a numerical split, or value of a categorical split.
is_categorical (bool) – Whether the split is categorical.
gain (float) – Decrease of impurity of the split.
impurity (list of float) – Impurity of the node, of the left child and of the right child.
See also
ClassificationSplitterthe same splitter for classification.
DecisionTreeStumpRegressorthe stump made of a MatrixTransformer and this splitter.
Notes
The categorical splits do not use
sample_weightand ignoremin_samples_leaf. On a binary feature, the threshold is halfway between its two values; the categorical values that would leave a child empty are not tested.Examples
>>> from sklearn.datasets import load_diabetes >>> from RuleTree.stumps.splitters import RegressionSplitter >>> X, y = load_diabetes(return_X_y=True) >>> splitter = RegressionSplitter(random_state=0) >>> splitter = splitter.fit(X, y, numerical=list(range(10)), categorical=[], context=None, node_id=None, cache=None) >>> splitter.feature_, round(float(splitter.threshold_), 4) (8, -0.0038)
- task = 'reg'#