simpleml.models.base_model
¶
Module Contents¶
Classes¶
Abstract Base class for all Model objects. Defines the required |
|
Main model class needs to be initialize-able in order to play nice with |
|
Base class for all Model objects. Defines the required |
-
class
simpleml.models.base_model.
AbstractModel
(has_external_files=True, external_model_kwargs=None, params=None, **kwargs)[source]¶ Bases:
future.utils.with_metaclass()
Abstract Base class for all Model objects. Defines the required parameters for versioning and all other metadata can be stored in the arbitrary metadata field
Also outlines the expected subclass methods (with NotImplementedError). Design choice to not abstract unified API across all libraries since each has a different internal mechanism
params: model parameter metadata for easy insight into hyperparameters across trainings feature_metadata: metadata insight into resulting features and importances
Need to explicitly separate passthrough kwargs to external models since most do not support arbitrary **kwargs in the constructors
-
abstract
_create_external_model
(self, **kwargs)[source]¶ Abstract method for each subclass to implement
should return the desired model object
-
abstract
_fit
(self)[source]¶ Abstract method to act as a placeholder. Inheriting classes MUST instantiate this method to manage the fit operation. Intentionally not abstracting function because each library internally configures a little differently
-
_hash
(self)[source]¶ - Hash is the combination of the:
Pipeline
Model
Params
Config
May only include attributes that exist at instantiation. Any attribute that gets calculated later will result in a race condition that may return a different hash depending on when the function is called
-
_predict
(self, X, **kwargs)[source]¶ Separate out actual predict call for optional overwrite in subclasses
-
assert_pipeline
(self, msg='')[source]¶ Helper method to raise an error if pipeline isn’t present and configured
-
property
external_model
(self)[source]¶ All model objects are going to require some filebase persisted object
Wrapper around whatever underlying class is desired (eg sklearn or keras)
-
get_feature_metadata
(self, **kwargs)[source]¶ Abstract method for each model to define
Should return a dict of feature information (importance, coefficients…)
-
predict
(self, X, transform=True, **kwargs)[source]¶ Pass through method to external model after running through pipeline :param transform: bool, whether to transform input via pipeline
before predicting, default True
-
abstract
-
class
simpleml.models.base_model.
LibraryModel
(has_external_files=True, external_model_kwargs=None, params=None, **kwargs)[source]¶ Bases:
simpleml.models.base_model.Model
Main model class needs to be initialize-able in order to play nice with database persistence and loading. This class is the in between that defines the expected methods for each extended library.
Examples: Scikit-learn estimators –> SklearnModel(LibraryModel): … Keras estimators –> KerasModel(LibraryModel): … PyTorch … …
Need to explicitly separate passthrough kwargs to external models since most do not support arbitrary **kwargs in the constructors
-
class
simpleml.models.base_model.
Model
(has_external_files=True, external_model_kwargs=None, params=None, **kwargs)[source]¶ Bases:
simpleml.models.base_model.AbstractModel
Base class for all Model objects. Defines the required parameters for versioning and all other metadata can be stored in the arbitrary metadata field
- pipeline_id: foreign key relation to the pipeline used to transform input to the model
(training is also dependent on originating dataset but scoring only needs access to the pipeline)
Need to explicitly separate passthrough kwargs to external models since most do not support arbitrary **kwargs in the constructors