eval_oml
eval_oml_iter_progressive(dataset, metric, models, step=100, weight_coeff=0.0, log_level=50)
¶
Evaluate OML Models on Streaming Data
This function evaluates one or more OML models on a streaming dataset. The evaluation
is done iteratively, and the models are tested every step
iterations. The results
are returned as a dictionary of metrics and their values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
list or Stream
|
A list of river.Stream objects containing the streaming data to be evaluated. If a single river.Stream object is provided, it is automatically converted to a list. |
required |
metric |
MultiClassMetric or RegressionMetric
|
The metric to be used for evaluation. |
required |
models |
dict
|
A dictionary of OML models to be evaluated. The keys are the names of the models, and the values are the model objects. |
required |
step |
int
|
Iteration number at which to yield results. This only takes into account the predictions, and not the training steps. Defaults to 100. |
100
|
weight_coeff |
float
|
Results are multiplied by (step/n_steps)**weight_coeff, where n_steps is the total number of iterations. Results from the beginning have a lower weight than results from the end if weight_coeff > 1. If weight_coeff == 0, then results are multiplied by 1 and every result has an equal weight. Defaults to 0.0. |
0.0
|
log_level |
int
|
The level of logging to use. 0 = no logging, 50 = print only important information. Defaults to 50. |
50
|
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing the evaluation results. The keys are the names of the models, and the values are dictionaries with the following keys: - “step”: A list of iteration numbers at which the model was evaluated. - “error”: A list of the weighted errors for each iteration. - “r_time”: A list of the weighted running times for each iteration. - “memory”: A list of the weighted memory usages for each iteration. - “metric_name”: The name of the metric used for evaluation. |
Reference
https://riverml.xyz/0.15.0/recipes/on-hoeffding-trees/
Examples:
>>> from river import compose
from river import linear_model
from river import preprocessing, datasets, utils, metrics
import matplotlib.pyplot as plt
from spotriver.utils.features import get_ordinal_date
from spotriver.evaluation.eval_nowcast import eval_nowcast_model, plot_nowcast_model
model = compose.Pipeline(
('ordinal_date', compose.FuncTransformer(get_ordinal_date)),
('scale', preprocessing.StandardScaler()),
('lin_reg', linear_model.LinearRegression())
)
dataset = datasets.AirlinePassengers()
dates, metric, y_trues, y_preds = eval_nowcast_model(model, dataset=dataset)
plot_nowcast_model(dates, metric, y_trues, y_preds)
Source code in spotriver/evaluation/eval_oml.py
9 10 11 12 13 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
fun_eval_oml_iter_progressive(result, metric=None, weights=None)
¶
Wrapper function for eval_oml_iter_progressive, returning a single function value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result |
dict
|
A dictionary of evaluation results, as returned by eval_oml_iter_progressive. |
required |
metric |
function
|
The metric function to use for computing the function value. Defaults to None, in which case the mean function is used. |
None
|
weights |
array
|
An array of weights for error, r_time, and memory. If None, the weights are set to [1, 0, 0], which considers only the error. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
array
|
An array of function values, one for each model in the evaluation results. |
Raises:
Type | Description |
---|---|
ValueError
|
If the weights array is not of length 3. |
Reference
https://riverml.xyz/0.15.0/recipes/on-hoeffding-trees/
Examples:
>>> from spotriver.evaluation.eval_oml import fun_eval_oml_iter_progressive
>>> result = {
... "model1": {
... "step": [1, 2, 3],
... "error": [0.1, 0.2, 0.3],
... "r_time": [0.1, 0.2, 0.3],
... "memory": [0.1, 0.2, 0.3],
... "metric_name": "MAE"
... },
... "model2": {
... "step": [1, 2, 3],
... "error": [0.2, 0.3, 0.4],
... "r_time": [0.2, 0.3, 0.4],
... "memory": [0.2, 0.3, 0.4],
... "metric_name": "MAE"
... }
... }
>>> fun_eval_oml_iter_progressive(result)
array([0.1, 0.2])
Source code in spotriver/evaluation/eval_oml.py
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 |
|
plot_oml_iter_progressive(result, log_x=False, log_y=False, figsize=None, filename=None)
¶
Plot evaluation of OML models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result |
dict
|
A dictionary of evaluation results, as returned by eval_oml_iter_progressive. |
required |
log_x |
bool
|
If True, the x-axis is set to log scale. Defaults to False. |
False
|
log_y |
bool
|
If True, the y-axis is set to log scale. Defaults to False. |
False
|
figsize |
tuple
|
The size of the figure. Defaults to None, in which case
the default figure size |
None
|
filename |
str
|
The name of the file to save the plot to. If None, the plot is not saved. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Figure
|
The figure object. |
Reference
https://riverml.xyz/0.15.0/recipes/on-hoeffding-trees/
Examples:
>>> from spotriver.evaluation.eval_oml import plot_oml_iter_progressive
>>> result = {
... "model1": {
... "step": [1, 2, 3],
... "error": [0.1, 0.2, 0.3],
... "r_time": [0.1, 0.2, 0.3],
... "memory": [0.1, 0.2, 0.3],
... "metric_name": "MAE"
... },
... "model2": {
... "step": [1, 2, 3],
... "error": [0.2, 0.3, 0.4],
... "r_time": [0.2, 0.3, 0.4],
... "memory": [0.2, 0.3, 0.4],
... "metric_name": "MAE"
... }
... }
>>> plot_oml_iter_progressive(result)
<Figure size 1000x500 with 3 Axes>
Source code in spotriver/evaluation/eval_oml.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 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 |
|