Base Model

class python.model.base.BaseModel(file_name)[source]

Bases: object

Abstract class that handles the loaded model.

explain(features, samples=None)[source]

Abstract method

family = ''
features()[source]

Get the features of the model

The returned list contains records. Each record contais (at least) the name and type of the variable. If the model supports feature importances calculation (if the clasifier has feature_importances_ atribute), they will also be present.

Returns

Model features.

Return type

list[dict]

Raises

RuntimeError – If the model is not ready.

property info

Get model information.

This function gives complete description of the model. The returned ibject contais the following keys:

metadata (dict): Model metadata (see metadata()).

model (dict): Context information of the learnt model.
type (str):

Type of the underlying model object.

predictor_type (str):

It could be the same as ‘type’. However, for sklearn.pipeline.Pipeline it will output the class of the predictor inside it.

is_explainable (bool):

True if the model class allows SHAP explanations to be computed.

task (str):

Task type. Either ‘BINARY_CLASSIFICATION’, ‘MULTILABEL_CLASSIFICATION’ or ‘REGRESSION’

class_names (list or None):

Class names if defined (for classification only).

Returns

Information about the model.

Return type

dict

Raises

RuntimeError – If the model is not ready.

is_ready()[source]

Check if model is already loaded.

Returns

Is the model already loaded and ready for predictions?

Return type

bool

load()[source]

Launch model loading in a separated thread

Once it finishes, the instance _is_ready parameter is set to True.

The loaded object is expected to be a dict containing the following keys: model (model object) and metadata (dict). The later contains one or two elements: features (list of dict) with at least the name and type of the variables and optional class_names (list of str) with the list of class-names in order (for classification).

property metadata

Get metadata of the model_name.

Returns

Metadata of the model containing information about the features and classes (optional)

Return type

dict

Raises

RuntimeError – If the model is not ready.

predict(features)[source]

Abstract method

predict_proba(features)[source]

Abstract method

preprocess(features)[source]

Abstract method

task_type(as_text=False)[source]

Get task type of the model

Either ‘REGRESSION’, ‘CLASSIFICATION’, ‘BINARY_CLASSIFICATION’ or ‘MULTILABEL_CLASSIFICATION’.

Returns

If as_text=False, returns the task of the model (classification, regression, etc.) as a Task class instance. If as_text=True, returns the task of the model as text.

Return type

Task or str

Raises

RuntimeError – If the model is not ready.