model.model

Module Contents

Classes

Model

Base class for H1st Model.

class model.model.Model

Bases: h1st.h1flow.h1step_containable.NodeContainable, h1st.trust.trustable.Trustable

Base class for H1st Model.

To create your own model, inherit Model class and implement process accordingly. Please refer to Tutorial for more details how to create a model.

The framework allows you to persist and load model to the model repository. To persist the model, you can call persist(), and then load to retrieve the model. See persist() and load() document for more detail.

Model Persistence and Loading Example
import h1st

class MyModeler(h1st.model.Modeler):
    def build_model(self):
        ...

class MyModel(h1st.model.Model):



my_modeler = MyModeler()
my_modeler.model_class = MyModel

my_model = my_modeler.build_model()

# Persist the model to repo
my_model.persist('1st_version')

# Load the model from the repo
my_model_2 = MyModel()
my_model_2.load('1st_version')
persist(self, path: str, version: str = None) str

Persist this model’s properties to the ModelRepository. Currently, only stats, metrics, model properties are supported.

model property could be single model, list or dict of models Currently, only sklearn and tensorflow-keras are supported.

Parameters

version – model version, leave blank for autogeneration

Returns

model version

load(self, path: str, version: str = None) Any

Load parameters from the specified version from the ModelRepository. Leave version blank to load latest version.

train(self, data: Dict[str, Any] = None) None

Implement logic to create the corresponding MLModel, including both training and evaluation.

evaluate(self, data: Dict, model: Dict) Dict

Implement logic to evaluate the model using the prepared_data This function will calculate model metrics and store it into self.metrics

Parameters
  • prepared_data – the prepared data

  • model – the corresponding h1st Model to evaluate against.

predict(self, input_data: Dict) Dict

Implement logic to generate prediction from data

:params input_data is input data for prediction :returns: a dictionary with key predictions containing the predictions