simpleml.models.base_model module

class simpleml.models.base_model.AbstractModel(has_external_files=True, external_model_kwargs={}, params={}, **kwargs)[source]

Bases: simpleml.persistables.base_persistable.Persistable, simpleml.persistables.saving.AllSaveMixin

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

add_pipeline(pipeline)[source]

Setter method for pipeline used

assert_fitted(msg='')[source]

Helper method to raise an error if model isn’t fit

assert_pipeline(msg='')[source]

Helper method to raise an error if pipeline isn’t present and configured

external_model

All model objects are going to require some filebase persisted object

Wrapper around whatever underlying class is desired (eg sklearn or keras)

feature_metadata = Column(None, JSON(), table=None, default=ColumnDefault({}))
fit(**kwargs)[source]

Pass through method to external model after running through pipeline

fit_predict(**kwargs)[source]

Wrapper for fit and predict methods

fitted
get_feature_metadata(**kwargs)[source]

Abstract method for each model to define

Should return a dict of feature information (importance, coefficients…)

get_labels(dataset_split=None)[source]

Wrapper method to return labels from dataset

get_params(**kwargs)[source]

Pass through method to external model

load(**kwargs)[source]

Extend main load routine to load relationship class

object_type = 'MODEL'
params = Column(None, JSON(), table=None, default=ColumnDefault({}))
predict(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
save(**kwargs)[source]

Extend parent function with a few additional save routines

  1. save params
  2. save feature metadata
score(X, y=None, **kwargs)[source]

Pass through method to external model

set_params(**params)[source]

Pass through method to external model

transform(*args, **kwargs)[source]

Run input through pipeline – only method that should reference the pipeline relationship directly (gates the connection point for easy extension in the future)

class simpleml.models.base_model.LibraryModel(has_external_files=True, external_model_kwargs={}, params={}, **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 … …

author
created_timestamp
feature_metadata
filepaths
has_external_files
hash_
id
metadata_
modified_timestamp
name
params
pipeline
pipeline_id
project
registered_name
version
version_description
class simpleml.models.base_model.Model(has_external_files=True, external_model_kwargs={}, params={}, **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)
author
created_timestamp
feature_metadata
filepaths
has_external_files
hash_
id
metadata_
modified_timestamp
name
params
pipeline
pipeline_id
project
registered_name
version
version_description