ClassificationSplitter#
- class ClassificationSplitter(criterion='gini', min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, min_impurity_decrease=0.0, class_weight=None)[source]#
Bases:
DecisionTreeSplitterSplitter for classification that maximizes the decrease of impurity (information gain).
The numerical features are split by a scikit-learn
DecisionTreeClassifierof 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 ({'gini', 'entropy'} or callable, default='gini') – Impurity measure. A callable
f(y, sample_weight, class_weight) -> floatis 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.
class_weight (dict, 'balanced' or None, default=None) – Weights of the classes in the impurity; ‘balanced’ weighs them inversely to their frequency.
- 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) – Information gain of the split.
impurity (list of float) – Impurity of the node, of the left child and of the right child.
See also
RegressionSplitterthe same splitter for regression.
DecisionTreeStumpClassifierthe 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_iris >>> from RuleTree.stumps.splitters import ClassificationSplitter >>> X, y = load_iris(return_X_y=True) >>> splitter = ClassificationSplitter(random_state=0) >>> splitter = splitter.fit(X, y, numerical=[0, 1, 2, 3], categorical=[], context=None, node_id=None, cache=None) >>> splitter.feature_, round(float(splitter.threshold_), 2), round(float(splitter.gain_), 3) (3, 0.8, 0.333) >>> splitter.apply(X[[0, 100]]) array([1, 2])
- task = 'clf'#