Learn R Programming

fastml (version 0.5.0)

get_best_model_idx: Get Best Model Indices by Metric and Group

Description

Identifies and returns the indices of rows in a data frame where the specified metric reaches the overall maximum within groups defined by one or more columns.

Usage

get_best_model_idx(df, metric, group_cols = c("Model", "Engine"))

Value

A numeric vector of row indices in df corresponding to groups whose maximum metric equals the overall best metric value.

Arguments

df

A data frame containing model performance metrics and grouping columns.

metric

A character string specifying the name of the metric column in df. The metric values are converted to numeric for comparison.

group_cols

A character vector of column names used for grouping. Defaults to c("Model", "Engine").

Details

The function converts the metric values to numeric and creates a combined grouping factor using the specified group_cols. It then computes the maximum metric value within each group and determines the overall best metric value across the entire data frame. Finally, it returns the indices of rows belonging to groups that achieve this overall maximum.