model
Model
Bases: ABC
Base class for models.
A model is used to predict outputs for given inputs.
predict(input_features)
abstractmethod
Predict outputs for the given inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_features
|
Data
|
The inputs for which to predict the outputs. |
required |
Returns:
Type | Description |
---|---|
Data
|
The predicted outputs. |
Source code in src/flowcean/core/model.py
24 25 26 27 28 29 30 31 32 33 |
|
save(file)
Save the model to the file.
This method can be used to save a flowcean model to a file or a file-like object. To save a model to a file use
with open("model.fml", "wb") as f:
model.save(f)
The resulting file will contain the model any any attached transforms.
It can be loaded again using the load
method from the Model
class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
Path | BinaryIO
|
The file like object to save the model to. |
required |
Source code in src/flowcean/core/model.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
load(file)
staticmethod
Load a model from file.
This method can be used to load a previously saved flowcean model from a file or a file-like object. To load a model from a file use
with open("model.fml", "rb") as f:
model = Model.load(f)
The load
method will automatically determine the model type and and
any attached transforms and will load them into the correct model
class.
As this method uses the pickle
module to load the model, it is not
safe to load models from untrusted sources as this could lead to
arbitrary code execution!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
Path | BinaryIO
|
The file like object to load the model from. |
required |
Source code in src/flowcean/core/model.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
save_state()
abstractmethod
Save the model state to a dictionary.
To save the model to a file, use the save
method.
To create a model from a state dictionary, use the load_from_state
method.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
A dictionary containing the model state. |
Source code in src/flowcean/core/model.py
106 107 108 109 110 111 112 113 114 115 116 |
|
load_from_state(state)
abstractmethod
classmethod
Load the model from a state dictionary.
To load a model from a file use the load
method.
To save the model state to a dictionary, use the save_state
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
dict[str, Any]
|
A dictionary containing the model state. |
required |
Source code in src/flowcean/core/model.py
118 119 120 121 122 123 124 125 126 127 128 |
|