FlatMatrixClassificationSplitter#
- class FlatMatrixClassificationSplitter(criterion='gini', min_samples_leaf=1, class_weight=None, gain_function=None)[source]#
Bases:
FlatMatrixSplitterSplitter for classification that evaluates all the candidate splits together with matrix operations (see FlatMatrixSplitter) and maximizes the decrease of impurity.
- Parameters:
criterion ({'gini', 'entropy', 'log_loss', 'misclassification'}, default='gini') – Impurity measure; ‘log_loss’ is the same as ‘entropy’, ‘misclassification’ is the fraction of the instances outside the majority class.
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).
class_weight (dict, 'balanced' or None, default=None) – Weights of the classes in the impurity; ‘balanced’ weighs them inversely to their frequency.
gain_function (callable, default=None) – Gain of all the candidates of a node, instead of the information gain (see FlatMatrixSplitter).
- 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) – Gain of the split: the information gain, or the value of
gain_function.impurity (list of float) – Impurity of the node, of the left child and of the right child.
See also
ClassificationSplitterthe splitter to use when the impurity is not changed.
Examples
>>> from sklearn.datasets import load_iris >>> from RuleTree.stumps.splitters import FlatMatrixClassificationSplitter >>> X, y = load_iris(return_X_y=True) >>> splitter = FlatMatrixClassificationSplitter() >>> splitter = splitter.fit(X, y, numerical=[0, 1, 2, 3], categorical=[], context=None, node_id=None, cache=None) >>> splitter.feature_, round(splitter.threshold_, 2), round(splitter.gain_, 3) (2, 2.45, 0.333) >>> splitter.apply(X[[0, 100]]) array([1, 2])
- task = 'clf'#