h1st.core.model module

class h1st.core.model.Model[source]

Bases: h1st.core.node_containable.NodeContainable

Base class for H1ST Model.

To create your own model, inherit Model class and implement prepare_data, train and predict 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 as h1
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression

class MyModel(h1.Model):
    def __init__(self):
        self.model = LogisticRegression(random_state=0)

    def train(self, prepared_data):
        X, y = prepared_data['X'], prepared_data['y']
        self.model.fit(X, y)

my_model = MyModel()
X, y = load_iris(return_X_y=True)
prepared_data = {'X': X, 'y': y}
# Persist the model to repo

# Load the model from the repo
my_model_2 = MyModel()
load_data() → dict[source]

Implement logic of load data from data source


loaded data

prep(loaded_data: dict) → dict[source]

Implement logic to prepare data from loaded data


data – loaded data from load_data method


prepared data

explore(loaded_data: dict) → None[source]

Implement logic to explore data from loaded data

train(prepared_data: dict)[source]

Implement logic of training model


prepared_data – prepared data from prep method


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.


version – model version, leave blank for autogeneration


model version

load(version: str = None)h1st.core.model.Model[source]

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

evaluate(data: dict) → dict[source]

Implement logic to evaluate the model using the loaded data


data – loaded data

predict(input_data: dict) → dict[source]

Implement logic to generate prediction from data

Params data

data for prediction


prediction result as a dictionary

test_output(input_data: Any = None, schema=None)[source]

From NodeContainable. Validates the models’ prediction with a schema.:: :param input_data: input data for prediction, it can be anything. :param schema: target schema :return: validation result