Auditioner
The Auditioner
class is the main entry point for the Audition module. Users pass its constructor a database connection, information about the model groups to be evaluated, and a specification for a filter to prune the worst-performing models.
Other methods allow users to define more complex selection rules, list selected models, or plot results from the selection process.
Attributes#
logger = verboselogs.VerboseLogger(__name__)
module-attribute
#
Classes#
AuditionRunner
#
Source code in src/triage/component/audition/__init__.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
Attributes#
config = config_dict
instance-attribute
#
db_engine = db_engine
instance-attribute
#
dir = directory
instance-attribute
#
Functions#
__init__(config_dict, db_engine, directory=None)
#
Source code in src/triage/component/audition/__init__.py
407 408 409 410 |
|
run()
#
Source code in src/triage/component/audition/__init__.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
|
validate()
#
Source code in src/triage/component/audition/__init__.py
444 445 446 447 448 |
|
Auditioner
#
Source code in src/triage/component/audition/__init__.py
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 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 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 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 289 290 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 357 358 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 |
|
Attributes#
average_regret_for_rules
property
#
Returns the average regret for each selection rule, over the specified list of train/test periods.
Returns:
Type | Description |
---|---|
dict
|
A dict with a key-value pair for each selection rule and the average regret for that rule. Structure: {'descriptive rule_name': .5} |
baseline_model_groups = model_groups_filter(train_end_times=train_end_times, initial_model_group_ids=baseline_model_group_ids, models_table=models_table, db_engine=db_engine)
instance-attribute
#
best_distance_plotter = BestDistancePlotter(self.distance_from_best_table, self.directory)
instance-attribute
#
directory = directory
instance-attribute
#
distance_from_best_table = DistanceFromBestTable(db_engine=db_engine, models_table=models_table, distance_table=distance_table, agg_type=agg_type)
instance-attribute
#
first_pass_model_groups = model_groups_filter(train_end_times=train_end_times, initial_model_group_ids=model_group_ids, models_table=models_table, db_engine=db_engine)
instance-attribute
#
metric_filters = initial_metric_filters
instance-attribute
#
metrics
property
#
model_group_performance_plotter = ModelGroupPerformancePlotter(self.distance_from_best_table, self.directory)
instance-attribute
#
model_group_thresholder = ModelGroupThresholder(distance_from_best_table=self.distance_from_best_table, train_end_times=train_end_times, initial_model_group_ids=self.first_pass_model_groups, initial_metric_filters=initial_metric_filters)
instance-attribute
#
results_for_rule = {}
instance-attribute
#
selection_rule_model_group_ids
property
#
Calculate the current winners for each selection rule and the most recent date
Returns:
Type | Description |
---|---|
dict
|
A dict with a key-value pair for each selection rule and the list of n |
dict
|
model_group_ids that it selected. Structure: {'descriptive rule_name':[1,2,3]} |
selection_rule_performance_plotter = SelectionRulePerformancePlotter(self.selection_rule_picker, directory)
instance-attribute
#
selection_rule_picker = SelectionRulePicker(self.distance_from_best_table)
instance-attribute
#
selection_rule_plotter = SelectionRulePlotter(self.selection_rule_picker, self.directory)
instance-attribute
#
thresholded_model_group_ids
property
#
The model group thresholder will have a varying list of model group ids depending on its current thresholding rules, this is a reference to whatever that current list is.
Returns:
Type | Description |
---|---|
list
|
list of model group ids allowed by the current metric threshold rules |
train_end_times = sorted(train_end_times)
instance-attribute
#
Functions#
__init__(db_engine, model_group_ids, train_end_times, initial_metric_filters, models_table=None, distance_table=None, directory=None, agg_type='worst', baseline_model_group_ids=None)
#
Filter model groups using a two-step process:
- Broad thresholds to filter out truly bad models
- A selection rule grid to find the best model groups over time for each of a variety of methods
This is achieved by creating a 'best distance' table, which functions like a denormalized 'model group/model/evaluations', storing for each model group/train end time/metric/parameter: 1. the raw evaluation value, 2. the distance of that evaluation metric from the best model group at that train time, 3. and the distance of the metric from the best model group the next train time
Each of the steps is computed based on the data in this table, and an iterative process of sending thresholding/selection configuration and viewing the results.
For step 1, the initial configuration is sent in this constructor (as 'initial_metric_filters', format detailed below), future iterations of this configuration are sent to 'update_metric_filters'.
For step 2, all configuration is sent to the object via 'register_selection_rule_grid', and its format is detailed in that method's docstring
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_engine
|
engine
|
A database engine with access to a results schema of a completed modeling run |
required |
model_group_ids
|
list
|
A large list of model groups to audition. No effort should be needed to pick 'good' model groups, but they should all be groups that could be used if they are found to perform well. They should also each have evaluations for any train end times you wish to include in analysis |
required |
train_end_times
|
list
|
A list of train end times that all of the given model groups contain evaluations for and that you want to be deemed important in the analysis |
required |
initial_metric_filters
|
list
|
A list of metrics to filter model groups on, and how to filter them. Each entry should be a dict of the format:
|
required |
models_table
|
string
|
The name of the results schema models table that you want to use. Will default to 'models', which is also the default in triage. |
None
|
distance_table
|
string
|
The name of the 'best distance' table to use. Will default to 'best_distance', but this can be sent if you want to avoid clobbering the results from a prior analysis. |
None
|
baseline_model_group_ids
|
list
|
An optional list of model groups for baseline models which will be included on all plots without being subject to filtering or included as candidate models from the selection process. |
None
|
Source code in src/triage/component/audition/__init__.py
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 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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
plot_model_groups()
#
Display model group plots, one of the below for each configured metric.
-
A cumulative plot showing the effect of different worse-than-best thresholds for the given metric across the thresholded model groups.
-
A performance-over-time plot showing the value for the given metric over time for each thresholded model group
Source code in src/triage/component/audition/__init__.py
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 |
|
plot_selection_rules()
#
Plot data about the configured selection rules. The three plots outlined below are plotted for each metric.
We base a lot of this on the concept of the 'regret'. The regret refers to the difference in performance between a model group and the best model group for the next testing window if a selection rule is followed.
- A distance-next-time plot, showing the fraction of models worse then a succession of regret thresholds for each selection rule
- A regret-over-time plot for each selection rule
- A metric-over-time plot for each selection rule
Source code in src/triage/component/audition/__init__.py
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 |
|
register_selection_rule_grid(rule_grid, plot=True)
#
Register a grid of selection rules
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule_grid
|
list
|
Groups of selection rules that share parameters. See documentation below for schema. |
required |
plot
|
(boolean, defaults to True) Whether or not to plot the selection rules at this time. |
True
|
rules_grid
is a list of dicts. Each dict, which defines a group, has two required keys:
shared_parameters
and selection_rules
.
shared_parameters
: A list of dicts, each with a set of parameters that are taken
by all selection rules in this group.
For each of these shared parameter sets, the grid will create selection rules combining the set with all possible selection rule/parameter combinations.
This can be used to quickly combine, say, a variety of rules that all are concerned with precision at top 100 entities.
selection_rules
: A list of dicts, each with:
- A 'name' attribute that matches a selection rule in audition.selection_rules
- Parameters and values taken by that selection rule. Values in list form are all added to the grid. If the selection rule has no parameters, or the parameters are all covered by the shared parameters in this group, none are needed here.
Each selection rule in the group must have all of its required parameters covered by the shared parameters in its group and the parameters given to it.
Refer to Selection Rules for available selection rules and their parameters. The exceptions are the first two arguments to each selection rule, 'df' and 'train_end_time'. These are contextual and thus provided internally by Audition.
Example:
[{
'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'}
]
}]
Source code in src/triage/component/audition/__init__.py
350 351 352 353 354 355 356 357 358 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 |
|
save_result_model_group_ids(fname='results_model_group_ids.json')
#
Source code in src/triage/component/audition/__init__.py
221 222 223 |
|
set_one_metric_filter(metric='precision@', parameter='100_abs', max_from_best=0.05, threshold_value=0.1)
#
Set one thresholding metric filter
If one wnats to update multiple filters, one should use update_metric_filters()
instead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric
|
string
|
model evaluation metric such as 'precision@' |
'precision@'
|
parameter
|
string
|
model evaluation parameter such as '100_abs' |
'100_abs'
|
max_from_best
|
string
|
The maximum value that the given metric can be below the best for a given train end time |
0.05
|
threshold_value
|
string
|
The thresold value that the given metric can be |
0.1
|
plot
|
boolean, default True
|
Whether or not to also plot model group performance and thresholding details at this time. |
required |
Source code in src/triage/component/audition/__init__.py
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 |
|
update_metric_filters(new_filters=None, plot=True)
#
Update the thresholding metric filters
Args:
new_filters (list): A list of metrics to filter model
groups on, and how to filter them. This is an identical format to
the list given to 'initial_metric_filters' in the constructor.
Each entry should be a dict with the keys:
initial_metric_filters metric (string) -- model evaluation metric, such as 'precision@' parameter (string) -- model evaluation metric parameter, such as '300_abs' max_below_best (float) The maximum value that the given metric can be below the best for a given train end time threshold_value (float) The threshold value that the given metric can be plot (boolean, default True): Whether or not to also plot model group performance and thresholding details at this time.
Source code in src/triage/component/audition/__init__.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|