model#

class predict_backend.ml.model.Model(model, label, metadata=None, name=None, description=None, version=None)#

Bases: Asset

The model asset is a wrapper for machine learning models. Accessing attributes and member functions of

the model asset also passes through access to the underlying machine learning model. Here is an example:


>>> import numpy as np
>>> from predict_backend.ml.model import Model
>>> from sklearn.linear_model import LogisticRegression
>>> X = np.random.rand(10).reshape(-1, 1)
>>> Y = np.random.randint(0, 2, size=(10, 1))
>>> model = Model(LogisticRegression(), label="test", name="model")
>>> model.fit(X, Y)

Additionally, for specific packages the model asset stores hyperparameter information and the time it took to run certain model functions. Currently supported packages are xgboost and sklearn.

Parameters:
  • model – The machine learning model that this asset keeps track of.

  • label (str) – Label of Asset, see its documentation for more details.

  • metadata (dict) – Metadata of Asset, see its documentation for more details. Defaults to None.

  • name (str) – Name of Asset, see its documentation for more details. Defaults to None.

  • description (Optional[str]) – Description of Asset, see its documentation for more details. Defaults to None.

  • version (Optional[int]) – Version of Asset, see its documentation for more details. Defaults to 0.

get_all_metainfo()#

Returns the dictionary containing the model metadata.

Return type:

Dict

Returns:

Model metadata, including hyperparameters and times taken for last function calls.

get_recent_time()#

Returns the time taken for the most recent function which had its time recorded.

Returns:

The time taken in seconds as a float. If no time is found, returns None instead.

get_time(attr)#

Returns the last time taken to run the function named attr. The function needs to have been called on the model asset rather than the underlying ML model in order for the time to be recorded. Returns None if no time was found.

Parameters:

attr (str) – The name of the function to find the time taken.

Return type:

Optional[str]

Returns:

The time taken in seconds as a float. If no time is found, returns None instead.

update_model_notes()#

This function updates the asset’s stored metadata about the model.

Return type:

None