batchflow.models

Contains models

class BaseModel[source]

Base interface for models.

property default_name

Placeholder for model name.

classmethod is_model_like(obj)[source]

Check if the obj provides the same interface, as required by this specification.

abstract load()[source]

Load the model from the disc.

abstract predict()[source]

Make a prediction using the model.

abstract reset()[source]

Reset the trained model to allow a new training from scratch.

abstract save()[source]

Save the model to the disc.

abstract train()[source]

Train the model.

class SklearnModel(*args, **kwargs)[source]

Base class for scikit-learn models

estimator

an instance of scikit-learn estimator

Notes

Configuration

estimator - an instance of scikit-learn estimator

load / path - a path to a pickled estimator

Examples

pipeline
    .init_model('static', SklearnModel, 'my_model',
                config={'estimator': sklearn.linear_model.SGDClassifier(loss='huber')})

pipeline
    .init_model('static', SklearnModel, 'my_model',
                config={'load/path': '/path/to/estimator.pickle'})
build(*args, **kwargs)[source]

Define the model

load(path)[source]

Load the model.

Parameters

path (str) – a full path to a file from which a model will be loaded

predict(x, *args, **kwargs)[source]

Predict with the data provided

Parameters

X (array-like) – Subset of the training data, shape (n_samples, n_features)

Notes

For more details and other parameters look at the documentation for the estimator used.

Returns

Predicted value per sample, shape (n_samples,)

Return type

array

reset()[source]

Reset the trained model to allow a new training from scratch

save(path)[source]

Save the model.

Parameters

path (str) – a full path to a file where a model will be saved to

train(x, y, *args, **kwargs)[source]

Train the model with the data provided

Parameters
  • X (array-like) – Subset of the training data, shape (n_samples, n_features)

  • y (numpy array) – Subset of the target values, shape (n_samples,)

Notes

For more details and other parameters look at the documentation for the estimator used.