module mlmodel.piecewise_tree_regression
¶
Short summary¶
module mlinsights.mlmodel.piecewise_tree_regression
Implements a kind of piecewise linear regression by modifying the criterion used by the algorithm which builds a decision tree.
Classes¶
class |
truncated documentation |
---|---|
Implements a kind of piecewise linear regression by modifying the criterion used by the algorithm which builds a decision … |
Properties¶
property |
truncated documentation |
---|---|
|
HTML representation of estimator. This is redundant with the logic of _repr_mimebundle_. The latter should … |
|
Return the feature importances. The importance of a feature is computed as the (normalized) total reduction … |
Methods¶
method |
truncated documentation |
---|---|
Fits linear regressions for all leaves. Sets attributes |
|
Computes the predictions with a linear regression fitted with the observations mapped to each leave of the … |
|
Replaces the string stored in criterion by an instance of a class. |
|
Overloads method predict. Falls back into the predict from a decision tree is criterion is mse, mae, … |
|
Returns the leave index for each observation of X. |
Documentation¶
Implements a kind of piecewise linear regression by modifying the criterion used by the algorithm which builds a decision tree.
-
class
mlinsights.mlmodel.piecewise_tree_regression.
PiecewiseTreeRegressor
(criterion='mselin', splitter='best', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None)¶ Bases:
sklearn.tree._classes.DecisionTreeRegressor
Implements a kind of piecewise linear regression by modifying the criterion used by the algorithm which builds a decision tree. See sklearn.tree.DecisionTreeRegressor to get the meaning of the parameters except criterion:
mselin
: optimizes for a piecewise linear regressionsimple
: optimizes for a stepwise regression (equivalent to mse)
-
__abstractmethods__
= frozenset({})¶
-
__init__
(criterion='mselin', splitter='best', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None)¶ Initialize self. See help(type(self)) for accurate signature.
-
_abc_impl
= <_abc._abc_data object>¶
-
_fit_reglin
(X, y, sample_weight)¶ Fits linear regressions for all leaves. Sets attributes
leaves_mapping_
,betas_
,leaves_index_
. The first attribute is a dictionary{leave: row}
which maps a leave of the tree to the coefficientsbetas_[row, :]
of a regression trained on all training points mapped a specific leave.leaves_index_
keeps in memory a set of leaves.
-
_mapping_train
(X)¶
-
_predict_reglin
(X, check_input=True)¶ Computes the predictions with a linear regression fitted with the observations mapped to each leave of the tree.
- Parameters
X – array-like or sparse matrix of shape = [n_samples, n_features] The input samples. Internally, it will be converted to
dtype=np.float32
and if a sparse matrix is provided to a sparsecsr_matrix
.check_input – boolean, (default=True) Allow to bypass several input checking. Don’t use this parameter unless you know what you do.
- Returns
y, array of shape = [n_samples] or [n_samples, n_outputs] The predicted classes, or the predict values.
-
fit
(X, y, sample_weight=None, check_input=True, X_idx_sorted=None)¶ Replaces the string stored in criterion by an instance of a class.
-
predict
(X, check_input=True)¶ Overloads method predict. Falls back into the predict from a decision tree is criterion is mse, mae, simple. Computes the predictions from linear regression if the criterion is mselin.
-
predict_leaves
(X)¶ Returns the leave index for each observation of X.
- Parameters
X – array
- Returns
array leaves index in
self.leaves_index_