Source code for bspump.model.model

import logging
import json

from bspump.asab import Configurable

###

L = logging.getLogger(__name__)

###


[docs] class Model(Configurable): """ Generic `Model` object. Loads trained model and parameters. """ ConfigDefaults = { "path_model": "", # path to serialized model "path_parameters": "", # path to serialized model }
[docs] def __init__(self, app, id=None, config=None): self.Id = id if id is not None else self.__class__.__name__ super().__init__("model:{}".format(self.Id), config=config) self.PathModel = self.Config["path_model"] self.PathParameters = self.Config["path_parameters"] self.App = app self.Loop = app.Loop
[docs] def load_model_from_file(self): """ Load model from file. """ raise NotImplementedError()
[docs] def load_parameters_from_file(self): """ Loads model parameters from json file. Override if needed. """ with open(self.PathParameters) as f: self.Parameters = json.load(f)
[docs] async def update(self): """ Updates model on fly. """ pass
[docs] def transform(self, *args): """ Method used to transform data for model input. """ raise NotImplementedError()
[docs] def predict(self, *args): """ Method uses model to predict value from sample. """ raise NotImplementedError()