ploomber.OnlineModel

class ploomber.OnlineModel(module)

A subclass of ploomber.OnlineDAG to provider a simpler interface for online DAGs whose terminal task calls model.predict. OnlineModel is initialized with a module following a standard structure. Looks for a pipeline-features.yaml in the module’s root directory (e.g. src/my_module/pipeline-features.yaml), a model.pickle in the module’s root directory. The terminal task is executed with a model parameter which contains the load model and calls model.predict. The last task in pipeline-features.yaml should be named features.

See here for a complete example: https://github.com/ploomber/projects/blob/master/templates/ml-online/src/ml_online/infer.py

Parameters:

module – A module following a standard structure

Examples

>>> import my_module 
>>> model = OnlineModel(my_module) 
>>> model.predict(x=some_input) 

Methods

get_partial()

Must return the location of a partial dag (str or pathlib.Path)

init_dag_from_partial(partial)

Initialize partial returned by get_partial()

predict(**kwargs)

Returns the output of model.predict(upstream['features'])

terminal_params()

Must return a dictionary with parameters passed to terminal_task

terminal_task(upstream, model)

Las function to execute.

get_partial()

Must return the location of a partial dag (str or pathlib.Path)

classmethod init_dag_from_partial(partial)

Initialize partial returned by get_partial()

predict(**kwargs)

Returns the output of model.predict(upstream['features'])

terminal_params()

Must return a dictionary with parameters passed to terminal_task

static terminal_task(upstream, model)

Las function to execute. The upstream parameter contains the output of all tasks that have no downstream dependencies