RuleTreeClusterRegressor#
- class RuleTreeClusterRegressor(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:
RegressorMixin,RuleTreeClusterRuleTreeCluster whose leaves predict a value: the tree is built as in RuleTreeCluster, without looking at the target, and each node predicts the mean of the target of its instances, as in RuleTreeRegressor.
- 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:
root (RuleTreeNode) – Root of the fitted tree.
See also
RuleTreeClusterthe clustering tree.
RuleTreeRegressora tree whose splits are chosen with the target.
Examples
>>> from sklearn.datasets import load_diabetes >>> from RuleTree.tree.RuleTreeCluster import RuleTreeClusterRegressor >>> X, y = load_diabetes(return_X_y=True) >>> model = RuleTreeClusterRegressor(max_depth=2, random_state=0).fit(X, y) >>> model.predict(X[:2]).round(1) array([177.6, 111.8])
- 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 regression, as in RuleTreeRegressor.- 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: