module mlmodel.piecewise_estimator
¶
Short summary¶
module mlinsights.mlmodel.piecewise_estimator
Implements a piecewise linear regression.
Classes¶
class 
truncated documentation 

Uses a decision tree to split the space of features into buckets and trains a logistic regression (default) … 

Uses a decision tree to split the space of features into buckets and trains a linear regression on each of them. … 

Uses a decision tree to split the space of features into buckets and trains a linear regression (default) on … 
Functions¶
function 
truncated documentation 

Properties¶
property 
truncated documentation 


Returns the number of estimators = the number of buckets the data was split in. 
Returns the number of estimators = the number of buckets the data was split in. 


Returns the number of estimators = the number of buckets the data was split in. 
Methods¶
method 
truncated documentation 


Generic predict method, works for predict_proba and decision_function as well. 
Generic predict method, works for predict_proba and decision_function as well. 


Generic predict method, works for predict_proba and decision_function as well. 




Computes the predictions probabilities. Parameters ——— X: features, X is converted into … 


Trains the binner and an estimator on every bucket. Parameters ——— X: features, … 
Trains the binner and an estimator on every bucket. Parameters ——— X: features, … 


Trains the binner and an estimator on every bucket. Parameters ——— X: features, … 
Computes the predictions. Parameters ——— X: features, X is converted into an array if … 

Computes the predictions. Parameters ——— X: features, X is converted into an array if … 

Computes the predictions probabilities. Parameters ——— X: features, X is converted into … 


Maps every row to a tree in self.estimators_. 
Maps every row to a tree in self.estimators_. 


Maps every row to a tree in self.estimators_. 
Documentation¶
Implements a piecewise linear regression.

class
mlinsights.mlmodel.piecewise_estimator.
PiecewiseClassifier
(binner=None, estimator=None, n_jobs=None, random_state=None, verbose=False)[source]¶ Bases:
mlinsights.mlmodel.piecewise_estimator.PiecewiseEstimator
,sklearn.base.ClassifierMixin
Uses a decision tree to split the space of features into buckets and trains a logistic regression (default) on each of them. The second estimator is usually a sklearn.linear_model.LogisticRegression. It can also be sklearn.dummy.DummyClassifier to just get the average on each bucket.
The main issue with the PiecewiseClassifier is that each piece requires one example of each class in each bucket which may not happen. To avoid that, the training will pick up random example from other bucket to ensure this case does not happen.
 Parameters
binner – transformer or predictor which creates the buckets
estimator – predictor trained on every bucket
n_jobs – number of parallel jobs (for training and predicting)
random_state – to pick up random examples when buckets do not contain enough examples of each class
verbose – boolean or use
'tqdm'
to use tqdm to fit the estimators
binner allows the following values:
tree
: the model is sklearn.tree.DecisionTreeClassifier'bins'
: the model sklearn.preprocessing.KBinsDiscretizerany instanciated model
estimator allows the following values:
None
: the model is sklearn.linear_model.LogisticRegressionany instanciated model

__init__
(binner=None, estimator=None, n_jobs=None, random_state=None, verbose=False)[source]¶  Parameters
binner – transformer or predictor which creates the buckets
estimator – predictor trained on every bucket
n_jobs – number of parallel jobs (for training and predicting)
random_state – to pick up random examples when buckets do not contain enough examples of each class
verbose – boolean or use
'tqdm'
to use tqdm to fit the estimators
binner allows the following values:
tree
: the model is sklearn.tree.DecisionTreeClassifier'bins'
: the model sklearn.preprocessing.KBinsDiscretizerany instanciated model
estimator allows the following values:
None
: the model is sklearn.linear_model.LogisticRegressionany instanciated model

decision_function
(X)[source]¶ Computes the predictions probabilities.
 Parameters
X (features, X is converted into an array if X is a dataframe) –
 Returns
 Return type
predictions probabilities

predict
(X)[source]¶ Computes the predictions.
 Parameters
X (features, X is converted into an array if X is a dataframe) –
 Returns
 Return type
predictions

class
mlinsights.mlmodel.piecewise_estimator.
PiecewiseEstimator
(binner=None, estimator=None, n_jobs=None, verbose=False)[source]¶ Bases:
sklearn.base.BaseEstimator
Uses a decision tree to split the space of features into buckets and trains a linear regression on each of them. The second estimator can be a sklearn.linear_model.LinearRegression for a regression or sklearn.linear_model.LogisticRegression for a classifier. It can also be sklearn.dummy.DummyRegressor sklearn.dummy.DummyClassifier to just get the average on each bucket.
 Parameters
binner – transformer or predictor which creates the buckets
estimator – predictor trained on every bucket
n_jobs – number of parallel jobs (for training and predicting)
verbose – boolean or use
'tqdm'
to use tqdm to fit the estimators
binner must be filled or must be:
'bins'
: the model sklearn.preprocessing.KBinsDiscretizerany instanciated model
estimator allows the following values:
None
: the model is sklearn.linear_model.LinearRegressionany instanciated model

__init__
(binner=None, estimator=None, n_jobs=None, verbose=False)[source]¶  Parameters
binner – transformer or predictor which creates the buckets
estimator – predictor trained on every bucket
n_jobs – number of parallel jobs (for training and predicting)
verbose – boolean or use
'tqdm'
to use tqdm to fit the estimators
binner must be filled or must be:
'bins'
: the model sklearn.preprocessing.KBinsDiscretizerany instanciated model
estimator allows the following values:
None
: the model is sklearn.linear_model.LinearRegressionany instanciated model

_apply_predict_method
(X, method, parallelized, dimout)[source]¶ Generic predict method, works for predict_proba and decision_function as well.

fit
(X, y, sample_weight=None)[source]¶ Trains the binner and an estimator on every bucket.
 Parameters
X (features, X is converted into an array if X is a dataframe) –
y (target) –
sample_weight (sample weights) –
 Returns
self
 Return type
returns an instance of self.

binner_
¶  Type
binner

estimators_
¶ mapped to a leave to the tree
 Type
dictionary of estimators, each of them

mean_estimator_
¶ datasets in case the binner can find a bucket for a new observation
 Type
estimator trained on the whole

dim_
¶  Type
dimension of the output

mean_
¶  Type
average targets

n_estimators_
¶ Returns the number of estimators = the number of buckets the data was split in.

class
mlinsights.mlmodel.piecewise_estimator.
PiecewiseRegressor
(binner=None, estimator=None, n_jobs=None, verbose=False)[source]¶ Bases:
mlinsights.mlmodel.piecewise_estimator.PiecewiseEstimator
,sklearn.base.RegressorMixin
Uses a decision tree to split the space of features into buckets and trains a linear regression (default) on each of them. The second estimator is usually a sklearn.linear_model.LinearRegression. It can also be sklearn.dummy.DummyRegressor to just get the average on each bucket.
 Parameters
binner – transformer or predictor which creates the buckets
estimator – predictor trained on every bucket
n_jobs – number of parallel jobs (for training and predicting)
verbose – boolean or use
'tqdm'
to use tqdm to fit the estimators
binner allows the following values:
tree
: the model is sklearn.tree.DecisionTreeRegressor'bins'
: the model sklearn.preprocessing.KBinsDiscretizerany instanciated model
estimator allows the following values:
None
: the model is sklearn.linear_model.LinearRegressionany instanciated model

__init__
(binner=None, estimator=None, n_jobs=None, verbose=False)[source]¶  Parameters
binner – transformer or predictor which creates the buckets
estimator – predictor trained on every bucket
n_jobs – number of parallel jobs (for training and predicting)
verbose – boolean or use
'tqdm'
to use tqdm to fit the estimators
binner allows the following values:
tree
: the model is sklearn.tree.DecisionTreeRegressor'bins'
: the model sklearn.preprocessing.KBinsDiscretizerany instanciated model
estimator allows the following values:
None
: the model is sklearn.linear_model.LinearRegressionany instanciated model

mlinsights.mlmodel.piecewise_estimator.
_decision_function_piecewise_estimator
(i, est, X, association)[source]¶

mlinsights.mlmodel.piecewise_estimator.
_fit_piecewise_estimator
(i, model, X, y, sample_weight, association, nb_classes, random_state)[source]¶