View source: R/hmda.rashamon.set.R
| hmda.rashomon.set | R Documentation |
Selects a set of near-optimal models from a grid-analysis table.
The function can either retain all models within a given percentage of the
best model, or retain the top n models according to a selected
performance metric.
hmda.rashomon.set(
grid_analysis,
metric = "aucpr",
criterion = c("within_percent", "top_n"),
distance_percentage = 0.01,
top_n = 5,
fallback_min_models = 2
)
grid_analysis |
A data frame containing model IDs and performance
metrics, usually returned by |
metric |
Character string specifying the metric used for model
selection and weighting. Supported values include |
criterion |
Character string specifying the selection rule. Supported
values are |
distance_percentage |
Numeric. The allowed distance from the best model
when |
top_n |
Integer. Number of top-ranked models to retain when
|
fallback_min_models |
Integer. Minimum number of models to retain. If the
selected model based on within_perent set contains fewer models than this value, the function
falls back to the best |
The function is used to define the model set from which WMSHAP values are
computed. In the "within_percent" criterion, the function retains
models that are close to the best-performing model according to the selected
metric.
For metrics where larger values indicate better performance, such as
"aucpr", "auc", and "r2", models are ranked in
decreasing order. For metrics where smaller values indicate better
performance, such as "logloss", models are ranked in increasing order.
The argument fallback_min_models is useful when the
"within_percent" criterion retains only a single model. In that case,
WMSHAP would no longer be meaningfully multi-model. The fallback rule can be
used to force a minimum number of retained models while recording whether
this correction was necessary.
A list with the following components:
Character vector of the final selected model IDs. This includes the fallback models if the fallback rule was used.
Character vector of model IDs selected by the requested rule before applying the minimum-size fallback.
A data frame containing the selected model IDs, the selection metric, the metric value, and the normalized model weight for each retained model.
A named numeric vector containing the metric
value for all valid models in grid_analysis. The names are
the model IDs.
A one-row data frame describing the selection rule, the number of models retained before and after fallback, whether the fallback was used, the best and second-best metric values, the top-two metric gap, and the cutoff used for selection.
## Not run:
# Assume grid_analysis was returned by hmda.grid.analysis()
# Retain all models within 1 percent of the best AUCPR model.
rashomon_1pct <- hmda.rashomon.set(
grid_analysis = grid_analysis,
metric = "aucpr",
criterion = "within_percent",
distance_percentage = 0.01,
fallback_min_models = 2
)
# Access the final retained model IDs.
rashomon_1pct$model_ids
# Inspect whether the fallback rule was used.
rashomon_1pct$diagnostics
# Retain the top 5 models according to AUCPR.
rashomon_top5 <- hmda.rashomon.set(
grid_analysis = grid_analysis,
metric = "aucpr",
criterion = "top_n",
top_n = 5
)
rashomon_top5$selected_model_table
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.