Model Model

Model subclasses are responsible for training themselves on records, making predictions about the value of a feature in the record, and assessing their prediction accuracy.

class dffml.model.model.Model(config)[source]

Abstract base class which should be derived from and implemented using various machine learning frameworks or concepts.

CONFIG

alias of ModelConfig

class dffml.model.model.ModelConfig(location: str, features: dffml.feature.feature.Features, location_save: dffml.df.types.DataFlow, location_load: dffml.df.types.DataFlow)[source]
no_enforce_immutable()

By default, all properties of a config object are immutable. If you would like to mutate immutable properties, you must explicitly call this method using it as a context manager.

Examples

>>> from dffml import config
>>>
>>> @config
... class MyConfig:
...     C: int
>>>
>>> config = MyConfig(C=2)
>>> with config.no_enforce_immutable():
...     config.C = 1
class dffml.model.model.ModelContext(parent: Model)[source]

Abstract base class which should be derived from and implemented using various machine learning frameworks or concepts.

abstract async predict(sources: SourcesContext) AsyncIterator[Record][source]

Uses trained data to make a prediction about the quality of a record.

abstract async train(sources: Sources)[source]

Train using records as the data to learn from.

exception dffml.model.model.ModelNotTrained[source]
class dffml.model.model.SimpleModel(config: BaseConfig)[source]
CONTEXT

alias of SimpleModelNoContext

close()[source]

Save model to disk.

disk_path(extention: Optional[str] = None)[source]

We do this for convenience of the user so they can usually just use the default location and if they train models with different parameters this method transparently to the user creates a filename unique the that configuration of the model where data is saved and loaded.

open()[source]

Load saved model from disk if it exists.

property parent

Simple models are both the parent and the context. This property is used to fake out anything attempting to access the model context’s parent.

class dffml.model.model.SimpleModelNoContext[source]

No need for CONTEXT since we implement __call__