RuleTreeClusterClassifier#
- class RuleTreeClusterClassifier(n_components: int = 2, clus_impurity: str = 'r2', bic_eps: float = 0.0, max_leaf_nodes=inf, min_samples_split=2, max_depth=inf, prune_useless_leaves=True, base_stumps: RegressorMixin | list = None, random_state=None, component_split: str = 'best')[source]#
Bases:
ClassifierMixin,RuleTreeClusterRuleTreeCluster whose leaves predict a class: the tree is built as in RuleTreeCluster, without looking at the target, and each node predicts the majority class of its instances, as in RuleTreeClassifier.
- Parameters:
n_components (int, default=2) – Number of principal components predicted by the stumps of each node.
clus_impurity ({'r2', 'bic'}, default='r2') – Criterion to choose the split among the ones on the different components: the variance of the component explained by the split (‘r2’) or the Bayesian Information Criterion of the two clusters (‘bic’).
bic_eps (float, default=0.0) – A split is kept only if it decreases the BIC of the node by more than bic_eps times its value.
max_leaf_nodes (int, default=inf) – Maximum number of leaves.
min_samples_split (int, default=2) – Minimum number of instances to split a node.
max_depth (int, default=inf) – Maximum depth of the tree (the root has depth 0).
prune_useless_leaves (bool, default=True) – Whether to merge, after fit, the sibling leaves with the same prediction.
base_stumps (RuleTreeBaseStump or list, default=None) – Regression stumps used to split the nodes, fitted to predict a principal component. If None, DecisionTreeStumpRegressor().
random_state (int, RandomState instance or None, default=None) – Seed of the principal component analysis and of the random choice of the stumps, also given to the stumps without a random_state.
component_split ({'best', 'joint'}, default='best') – How a node is split on its principal components. ‘best’ fits a stump on each component and keeps the best split according to
clus_impurity. ‘joint’ fits one stump on all the components together (a regression with several targets): the split is the one that most decreases the sum of squared distances of the instances from the centers of the two children, in the space of the components, as a k-means with two clusters whose border is a rule;clus_impurityis not used. With ‘joint’, the base stumps must support several targets (e.g. the decision tree, pivot and oblique stumps, not the fair stump).
- Variables:
classes (numpy.ndarray) – Classes of the target.
n_classes (int) – Number of classes.
See also
RuleTreeClusterthe clustering tree.
RuleTreeClassifiera tree whose splits are chosen with the target.
Examples
>>> from sklearn.datasets import make_blobs >>> from RuleTree.tree.RuleTreeCluster import RuleTreeClusterClassifier >>> X, y = make_blobs(n_samples=300, centers=3, cluster_std=0.5, random_state=0) >>> model = RuleTreeClusterClassifier(max_depth=2, random_state=0).fit(X, y) >>> round(model.score(X, y), 2) 0.99
- prepare_node(y: ndarray, idx: ndarray, node_id: str, node: RuleTreeNode | None = None) RuleTreeNode[source]#
Create a node (or update
node) with the statistics of classification, as in RuleTreeClassifier.- Parameters:
y (numpy.ndarray) – Target of the whole data set.
idx (numpy.ndarray) – Indices of the instances reaching the node.
node_id (str) – Identifier of the node.
node (RuleTreeNode, default=None) – Existing node to update instead of creating a new one.
- Returns:
node
- Return type:
- predict_proba(X: ndarray = None, X_ts=None, X_img=None, X_txt=None)[source]#
Class probabilities of each instance: the ones of the leaf it reaches.
- Parameters:
X (numpy.ndarray of shape (n_samples, n_features), default=None) – Tabular data.
X_ts (default=None) – Not supported by clustering, present for API consistency.
X_img (default=None) – Not supported by clustering, present for API consistency.
X_txt (default=None) – Not supported by clustering, present for API consistency.
- Returns:
proba
- Return type:
numpy.ndarray of shape (n_samples, n_classes)