offline
learn_offline(environment, learner, inputs, outputs, *, input_transform=None, output_transform=None)
Learn from an offline environment.
Learn from an offline environment by learning from the input-output pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
environment
|
OfflineEnvironment
|
The offline environment. |
required |
learner
|
SupervisedLearner
|
The supervised learner. |
required |
inputs
|
list[str]
|
The input feature names. |
required |
outputs
|
list[str]
|
The output feature names. |
required |
input_transform
|
Transform | None
|
The transform to apply to the input features. Will be part of the final model. |
None
|
output_transform
|
InvertibleTransform | None
|
The transform to apply to the output features. Its inverse will be part of the final model. |
None
|
Returns:
| Type | Description |
|---|---|
Model
|
The model learned from the environment. |
Source code in src/flowcean/core/strategies/offline.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 62 63 64 65 66 | |
evaluate_offline(models, environment, inputs, outputs, metrics)
Evaluate a model on an offline environment.
Evaluate a model on an offline environment by predicting the outputs from the inputs and comparing them to the true outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
Model | Iterable[Model]
|
The models to evaluate. |
required |
environment
|
OfflineEnvironment
|
The offline environment. |
required |
inputs
|
Sequence[str]
|
The input feature names. |
required |
outputs
|
Sequence[str]
|
The output feature names. |
required |
metrics
|
Sequence[Metric]
|
The metrics to evaluate the model with. |
required |
Returns:
| Type | Description |
|---|---|
Report
|
The evaluation report. |
Source code in src/flowcean/core/strategies/offline.py
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 105 106 107 | |
tune_threshold(model, environment, inputs, outputs, metric, *, thresholds=None, num_thresholds=19)
Find optimal decision threshold for a classifier.
Evaluates the model at multiple threshold values and returns the threshold that maximizes the given metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
ClassifierModel
|
The classifier model to tune. |
required |
environment
|
OfflineEnvironment
|
The offline environment with validation/test data. |
required |
inputs
|
Sequence[str]
|
The input feature names. |
required |
outputs
|
Sequence[str]
|
The output feature names. |
required |
metric
|
Metric
|
The metric to optimize (e.g., FBetaScore, Accuracy). |
required |
thresholds
|
Sequence[float] | None
|
Specific thresholds to evaluate. If None, generates num_thresholds evenly spaced values between 0.05 and 0.95. |
None
|
num_thresholds
|
int
|
Number of thresholds to evaluate if thresholds is None (default: 19). |
19
|
Returns:
| Type | Description |
|---|---|
float
|
Tuple of (best_threshold, results_dict) where results_dict maps |
dict[float, float]
|
each threshold to its metric score. |
Example
from flowcean.sklearn.metrics.classification import FBetaScore metric = FBetaScore(beta=1.0) best_threshold, results = tune_threshold( ... model, eval_env, inputs, outputs, metric ... ) print(f"Best threshold: {best_threshold:.3f}") model.threshold = best_threshold # Apply the best threshold
Source code in src/flowcean/core/strategies/offline.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |