Sklearn
This module provides interoperability
Scikit learned models can be used wit the ceruleo Transformers
The TimeSeriesWindowTransformer
is a scikit-learn transformers that takes
a transformer and iterator paramaters, to build a WindowedDatasetIterator
and generate the X and y.
Since the X and Y are generated by one scikit-learn transformer step, EstimatorWrapper
takes the (X,y) output of a TimeSeriesWindowTransformer
and calls the rest of the scikit-learn
pipeline spreading the (X,y) to positional parameters.
Finally CeruleoRegressor
, is a class similar to the sklearn.compose.TransformedTargetRegressor
.
Takes the transformer, and a regressor scikit-learn pipeline or model, and automatically builds
a scikit-learn pipeline using WindowedDatasetIterator
and EstimatorWrapper
.
CeruleoMetricWrapper
A wrapper around sklearn metrics
Example:
'''
grid_search = GridSearchCV(
estimator=regressor_gs,
param_grid={
'regressor': [RandomForestRegressor(max_depth=5)]
},
scoring=CeruleoMetricWrapper('neg_mean_absolute_error')
)
'''
Source code in ceruleo/models/sklearn.py
CeruleoRegressor
Bases: RegressorMixin
, BaseEstimator
A regressor wrapper similar to sklearn.compose.TransformedTargetRegressor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features_transformer |
The transformer |
required | |
regressor |
A scikit-learn regressor |
required |
Source code in ceruleo/models/sklearn.py
EstimatorWrapper
Bases: TransformerMixin
, BaseEstimator
Wrapper around sklearn estimators to allow calling the fit and predict
The transformer keeps the X and y together. This wrapper divide the X,y and call the fit(X,y) and predict(X,y) of the estimator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
estimator |
BaseEstimator
|
A scikit-learn estimator |
required |
Source code in ceruleo/models/sklearn.py
TimeSeriesWindowTransformer
Bases: TransformerMixin
, BaseEstimator
A scikit-learn transformer for obtaining a windowed time-series from the run-to-cycle failures
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transformer |
Transformer
|
A scikit-learn transformer |
required |
window_size |
int
|
Window size of the iterator |
required |
step |
int
|
Stride of the iterators |
1
|
horizon |
int
|
Horizon of the predictions |
1
|
shuffler |
AbstractShuffler
|
Shuffler of the data |
NotShuffled()
|
sample_weight |
SampleWeight
|
Sample weights callable |
NotWeighted()
|
right_closed |
bool
|
Wether to include the last point in each sliding window |
True
|
padding |
bool
|
Wether to pad when the lookback window is not complete |
True
|
Source code in ceruleo/models/sklearn.py
fit(dataset)
Fit the transformer with the given dataset
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
AbstractPDMDataset
|
Dataset to fit the transformer |
required |
fit_batch(model, train_batcher, val_batcher, n_epochs=15)
Fit the model using the given batcher
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
SKLearn Model |
required | |
train_batcher |
Batcher
|
Train dataset batcher |
required |
val_batcher |
Batcher
|
Validation dataset batcher |
required |
n_epochs |
Number of epochs, by default 15 |
15
|
Returns:
Name | Type | Description |
---|---|---|
model |
Model
|
the model |
history |
List
|
history of errors |
Source code in ceruleo/models/sklearn.py
predict(model, dataset_iterator)
Get the predictions for the given iterator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_iterator |
WindowedDatasetIterator
|
Dataset iterator from which obtain data to predict |
required |
Returns:
Type | Description |
---|---|
Array with the predictiosn |
Source code in ceruleo/models/sklearn.py
predict_batch(model, dataset_batcher)
Predict the values using the given batcher
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
SKLearn model |
required | |
dataset_batcher |
Batcher
|
The batcher |
required |
Returns:
Type | Description |
---|---|
ndarray
|
RUL Prediction array |
Source code in ceruleo/models/sklearn.py
train_model(model, train_iterator, val_windowed_iterator=None, **fit_kwargs)
Fit the model with the given dataset iterator Parameters: train_iterator: Training Iterator
Other Parameters:
Name | Type | Description |
---|---|---|
fit_kwargs |
Arguments for the fit method |
Returns:
Type | Description |
---|---|
A SKLearn model |