Selection Rules
Selection Rules#
The Triage uses selection rules to compare the performance of trained model groups over time, and select a model group for future predictions. A selection rule tries to predict the best-performing model group in some train/test period, based on the historical performance of each model group on some metric.
For example, a simple selection rule might predict that the best-performing model group during one train/test period will perform best in the following period.
A selection rule can be evaluated by calculating its regret, or the difference between the performance of its selected model group and the best-performing model group in some period.
Triage supports 8 model selection rules. Each is represented internally by one of the following functions:
BoundSelectionRule
#
A selection rule bound with a set of arguments
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
dict
|
A set of keyword arguments, that should be sufficient to call the function when a dataframe and train_end_time is added |
required |
function_name
|
string
|
The name of a function in SELECTION_RULES |
None
|
descriptive_name
|
string
|
A descriptive name, used in charts If none is given it will be automatically constructed |
None
|
function
|
function
|
A function |
None
|
Source code in src/triage/component/audition/selection_rules.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
|
pick(dataframe, train_end_time)
#
Run the selection rule for a given time on a dataframe
Source code in src/triage/component/audition/selection_rules.py
492 493 494 495 496 497 498 499 500 501 |
|
best_average_two_metrics(df, train_end_time, metric1, parameter1, metric2, parameter2, metric1_weight=0.5, n=1)
#
Pick the model with the highest average combined value to date
of two metrics weighted together using metric1_weight
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric1_weight
|
float
|
relative weight of metric1, between 0 and 1 |
0.5
|
metric1
|
string
|
model evaluation metric, such as 'precision@' |
required |
parameter1
|
string
|
model evaluation metric parameter, such as '300_abs' |
required |
metric2
|
string
|
model evaluation metric, such as 'precision@' |
required |
parameter2
|
string
|
model evaluation metric parameter, such as '300_abs' |
required |
train_end_time
|
Timestamp
|
current train end time |
required |
df
|
DataFrame
|
dataframe containing the columns model_group_id, train_end_time, metric, parameter, raw_value, below_best |
required |
n
|
int
|
the number of model group ids to return |
1
|
Source code in src/triage/component/audition/selection_rules.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
best_average_value(df, train_end_time, metric, parameter, n=1)
#
Pick the model with the highest average metric value so far
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric
|
string
|
model evaluation metric, such as 'precision@' |
required |
parameter
|
string
|
model evaluation metric parameter, such as '300_abs' |
required |
train_end_time
|
Timestamp
|
current train end time |
required |
df
|
DataFrame
|
dataframe containing the columns model_group_id, train_end_time, metric, parameter, raw_value, dist_from_best_case |
required |
n
|
int
|
the number of model group ids to return |
1
|
Source code in src/triage/component/audition/selection_rules.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
best_avg_recency_weight(df, train_end_time, metric, parameter, curr_weight, decay_type, n=1)
#
Pick the model with the highest average metric value so far, penalized for relative variance as: avg_value - (stdev_penalty) * (stdev - min_stdev) where min_stdev is the minimum standard deviation of the metric across all model groups
Parameters:
Name | Type | Description | Default |
---|---|---|---|
decay_type
|
string
|
either 'linear' or 'exponential'; the shape of how the weights fall off between the current and first point |
required |
curr_weight
|
float
|
amount of weight to put on the most recent point, relative to the first point (e.g., a value of 5.0 would mean the current data is weighted 5 times as much as the first one) |
required |
metric
|
string
|
model evaluation metric, such as 'precision@' |
required |
parameter
|
string
|
model evaluation metric parameter, such as '300_abs' |
required |
train_end_time
|
Timestamp
|
current train end time |
required |
df
|
DataFrame
|
dataframe containing the columns model_group_id, train_end_time, metric, parameter, raw_value, below_best |
required |
n
|
int
|
the number of model group ids to return |
1
|
Source code in src/triage/component/audition/selection_rules.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
best_avg_var_penalized(df, train_end_time, metric, parameter, stdev_penalty, n=1)
#
Pick the model with the highest average metric value so far, placing less weight in older results. You need to specify two parameters: the shape of how the weight affects points (decay_type, linear or exponential) and the relative weight of the most recent point (curr_weight).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stdev_penalty
|
float
|
penalty for instability |
required |
metric
|
string
|
model evaluation metric, such as 'precision@' |
required |
parameter
|
string
|
model evaluation metric parameter, such as '300_abs' |
required |
train_end_time
|
Timestamp
|
current train end time |
required |
df
|
DataFrame
|
dataframe containing the columns model_group_id, train_end_time, metric, parameter, raw_value, below_best |
required |
n
|
int
|
the number of model group ids to return |
1
|
Source code in src/triage/component/audition/selection_rules.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
|
best_current_value(df, train_end_time, metric, parameter, n=1)
#
Pick the model group with the best current metric value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric
|
string
|
model evaluation metric, such as 'precision@' |
required |
parameter
|
string
|
model evaluation metric parameter, such as '300_abs' |
required |
train_end_time
|
Timestamp
|
current train end time |
required |
df
|
DataFrame
|
dataframe containing the columns: model_group_id, train_end_time, metric, parameter, raw_value, dist_from_best_case |
required |
n
|
int
|
the number of model group ids to return |
1
|
Source code in src/triage/component/audition/selection_rules.py
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 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
lowest_metric_variance(df, train_end_time, metric, parameter, n=1)
#
Pick the model with the lowest metric variance so far
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric
|
string
|
model evaluation metric, such as 'precision@' |
required |
parameter
|
string
|
model evaluation metric parameter, such as '300_abs' |
required |
train_end_time
|
Timestamp
|
current train end time |
required |
df
|
DataFrame
|
dataframe containing the columns model_group_id, train_end_time, metric, parameter, raw_value, below_best |
required |
n
|
int
|
the number of model group ids to return |
1
|
Source code in src/triage/component/audition/selection_rules.py
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 |
|
most_frequent_best_dist(df, train_end_time, metric, parameter, dist_from_best_case, n=1)
#
Pick the model that is most frequently within dist_from_best_case
from the
best-performing model group across test sets so far
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dist_from_best_case
|
float
|
distance from the best performing model |
required |
metric
|
string
|
model evaluation metric, such as 'precision@' |
required |
parameter
|
string
|
model evaluation metric parameter, such as '300_abs' |
required |
train_end_time
|
Timestamp
|
current train end time |
required |
df
|
DataFrame
|
dataframe containing the columns model_group_id, train_end_time, metric, parameter, raw_value, below_best |
required |
n
|
int
|
the number of model group ids to return |
1
|
Source code in src/triage/component/audition/selection_rules.py
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 |
|
random_model_group(df, train_end_time, n=1)
#
Pick a random model group (as a baseline)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train_end_time
|
Timestamp
|
current train end time |
required |
df
|
DataFrame
|
dataframe containing the columns model_group_id, train_end_time, metric, parameter, raw_value, below_best |
required |
n
|
int
|
the number of model group ids to return |
1
|
Source code in src/triage/component/audition/selection_rules.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
RuleMakers#
Triage uses RuleMaker
classes to conveniently format the parameter grids accepted by make_selection_rule_grid
. Each type of RuleMaker
class holds methods that build parameter grids for a subset of the available selection rules.
The arguments of each add_rule_
method map to the arguments of the corresponding model selection function.
BaseRules
#
Source code in src/triage/component/audition/rules_maker.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
selection_rules = []
instance-attribute
#
shared_parameters = []
instance-attribute
#
__init__()
#
Source code in src/triage/component/audition/rules_maker.py
2 3 4 5 6 |
|
create()
#
Source code in src/triage/component/audition/rules_maker.py
20 21 22 23 24 25 26 |
|
RandomGroupRuleMaker
#
Bases: BaseRules
The RandomGroupRuleMaker
class generates a rule that randomly selects n
model groups for each train set.
Unlike the other two RuleMaker classes, it generates its selection rule spec
on __init__
Source code in src/triage/component/audition/rules_maker.py
133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
selection_rules = [{'name': 'random_model_group', 'n': n}]
instance-attribute
#
shared_parameters = [{}]
instance-attribute
#
__init__(n=1)
#
Source code in src/triage/component/audition/rules_maker.py
143 144 145 |
|
SimpleRuleMaker
#
Bases: BaseRules
Holds methods that generate parameter grids for selection rules that evaluate the performance of a model group in terms of a single metric. These include:
- best_current_value
- best_average_value
- lowest_metric_variance
- most_frequent_best_dist
- best_avg_var_penalized
- best_avg_recency_weight
Source code in src/triage/component/audition/rules_maker.py
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 86 87 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 |
|
add_rule_best_average_value(metric=None, parameter=None, n=1)
#
Source code in src/triage/component/audition/rules_maker.py
54 55 56 57 58 59 60 61 62 |
|
add_rule_best_avg_recency_weight(metric=None, parameter=None, n=1, curr_weight=[1.5, 2.0, 5.0], decay_type=['linear'])
#
Source code in src/triage/component/audition/rules_maker.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
add_rule_best_avg_var_penalized(metric=None, parameter=None, stdev_penalty=0.5, n=1)
#
Source code in src/triage/component/audition/rules_maker.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
add_rule_best_current_value(metric=None, parameter=None, n=1)
#
Source code in src/triage/component/audition/rules_maker.py
44 45 46 47 48 49 50 51 52 |
|
add_rule_lowest_metric_variance(metric=None, parameter=None, n=1)
#
Source code in src/triage/component/audition/rules_maker.py
64 65 66 67 68 69 70 71 72 |
|
add_rule_most_frequent_best_dist(metric=None, parameter=None, n=1, dist_from_best_case=[0.01, 0.05, 0.1, 0.15])
#
Source code in src/triage/component/audition/rules_maker.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
TwoMetricsRuleMaker
#
Bases: BaseRules
The TwoMetricsRuleMaker
class allows for the specification of rules that
evaluate a model group's performance in terms of two metrics. It currently
supports one rule:
Source code in src/triage/component/audition/rules_maker.py
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 |
|
add_rule_best_average_two_metrics(metric1='precision@', parameter1='100_abs', metric2='recall@', parameter2='300_abs', metric1_weight=[0.5], n=1)
#
Source code in src/triage/component/audition/rules_maker.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
create_selection_grid(*args)
#
Source code in src/triage/component/audition/rules_maker.py
179 180 |
|
Selection Grid#
make_selection_rule_grid(rule_groups)
#
Convert a compact selection rule group representation to a list of bound selection rules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule_groups
|
list
|
List of dicts used to specify selection rule grid. |
required |
Most users will want to use rulemaker objects
to generate their rule_group
specifications.
An example rule_groups specification:
[{
'shared_parameters': [
{'metric': 'precision@', 'parameter': '100_abs'},
{'metric': 'recall@', 'parameter': '100_abs'},
],
'selection_rules': [
{'name': 'most_frequent_best_dist', 'dist_from_best_case': [0.1, 0.2, 0.3]},
{'name': 'best_current_value'}
]
}, {
'shared_parameters': [
{'metric1': 'precision@', 'parameter1': '100_abs'},
],
'selection_rules': [
{
'name': 'best_average_two_metrics',
'metric2': ['recall@'],
'parameter2': ['100_abs'],
'metric1_weight': [0.4, 0.5, 0.6]
},
]
}]
Source code in src/triage/component/audition/selection_rule_grid.py
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|