module mlmodel.piecewise_tree_regression

Inheritance diagram of mlinsights.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.

source on GitHub

Classes

class

truncated documentation

PiecewiseTreeRegressor

Implements a kind of piecewise linear regression by modifying the criterion used by the algorithm which builds a decision …

Properties

property

truncated documentation

feature_importances_

Return the feature importances. The importance of a feature is computed as the (normalized) total reduction …

Methods

method

truncated documentation

__init__

_fit_reglin

Fits linear regressions for all leaves. Sets attributes leaves_mapping_, betas_, leaves_index_. …

_mapping_train

_predict_reglin

Computes the predictions with a linear regression fitted with the observations mapped to each leave of the …

fit

Replaces the string stored in criterion by an instance of a class.

predict

Overloads method predict. Falls back into the predict from a decision tree is criterion is mse, mae, …

predict_leaves

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.

source on GitHub

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, presort=False)[source]

Bases: sklearn.tree.tree.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 regression

  • simple: optimizes for a stepwise regression (equivalent to mse)

source on GitHub

__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, presort=False)[source]

Initialize self. See help(type(self)) for accurate signature.

_abc_impl = <_abc_data object>
_fit_reglin(X, y, sample_weight)[source]

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 coefficients betas_[row, :] of a regression trained on all training points mapped a specific leave. leaves_index_ keeps in memory a set of leaves.

source on GitHub

_mapping_train(X)[source]
_predict_reglin(X, check_input=True)[source]

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 sparse csr_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 – The predicted classes, or the predict values.

Return type

array of shape = [n_samples] or [n_samples, n_outputs]

source on GitHub

fit(X, y, sample_weight=None, check_input=True, X_idx_sorted=None)[source]

Replaces the string stored in criterion by an instance of a class.

source on GitHub

predict(X, check_input=True)[source]

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.

source on GitHub

predict_leaves(X)[source]

Returns the leave index for each observation of X.

Parameters

X – array

Returns

array leaves index in self.leaves_index_

source on GitHub