You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, OptunaSearchCV only supports a single scoring metric, either a string or a callable. This limitation makes it challenging to evaluate models using multiple evaluation metrics simultaneously, which is a common requirement in complex machine learning tasks.
In contrast, GridSearchCV supports multiple scoring metrics by allowing a dictionary, list, or tuple as input for the scoring parameter. This flexibility is particularly useful for tasks where multiple metrics must be considered (e.g., accuracy and f1_macro for imbalanced classification problems).
Providing support for multiple scoring metrics in OptunaSearchCV would make it a more versatile tool for hyperparameter optimization and align its functionality more closely with GridSearchCV.
Description
I propose extending OptunaSearchCV to support multiple scoring metrics, following the approach used in GridSearchCV.
Key Features:
Enhanced scoring parameter:
Allow scoring to accept:
A dictionary with metric names as keys and callables as values.
A list or tuple of unique metric names.
A callable returning a dictionary where keys are metric names and values are metric scores.
Refit behavior:
Add a refit parameter to specify which metric should be used to select the best hyperparameters. This should mirror the behavior of GridSearchCV (e.g., refit="accuracy").
Comprehensive results:
Include all specified scoring metrics in the cv_results_ attribute to provide a detailed evaluation of model performance for each metric.
Example Usage:
fromsklearn.svmimportSVCfromsklearn.datasetsimportload_irisfromsklearn.metricsimportmake_scorer, f1_score# Load datasetX, y=load_iris(return_X_y=True)
# Define modelclf=SVC()
# Define hyperparameter search spaceparam_distributions= {
"C": [0.1, 1, 10],
"kernel": ["linear", "rbf"]
}
# Define multiple scoring metricsscoring= {
"accuracy": "accuracy",
"f1_macro": make_scorer(f1_score, average="macro"),
}
# OptunaSearchCV with multiple scoring metricsoptuna_search=OptunaSearchCV(
estimator=clf,
param_distributions=param_distributions,
scoring=scoring,
refit="accuracy", # Use accuracy to select the best parameterscv=3,
)
# Fit the modeloptuna_search.fit(X, y)
# Print resultsprint("Best parameters:", optuna_search.best_params_)
print("Best score:", optuna_search.best_score_)
Alternatives (optional)
No response
Additional context (optional)
I propose this feature because allowing multiple scoring metrics in OptunaSearchCV would make it easier to implement evaluation methods such as Tibshirani-Tibshirani and BBC-CV.
The text was updated successfully, but these errors were encountered:
jckkvs
added
the
feature
Change that does not break compatibility, but affects the public interfaces.
label
Dec 23, 2024
Thank you for sharing your code regarding multiple scoring.
I have reviewed it and found no major technical issues.
As you mentioned, I understand that this feature has relatively low urgency or importance.
Since the issue is labeled as contribution-welcome, could you clarify what kind of contributions you are expecting?
Thank you for your comment! My previous PR was closed because the core team (excluding myself) could not notice the PR so I've forgotten the PR to update it.
So I think sending the same changes to https://github.com/optuna/optuna-integration is expected for the team, I believe. I'm a bit busy nowadays, so anyone can takeover the pull request if interested in it.
Thank you for the clarification! While this is not an essential feature, I find it quite interesting and valuable. I'm also a bit busy at the moment, so I may not be able to act on it immediately, but I would like to take over the pull request.
Motivation
Currently,
OptunaSearchCV
only supports a single scoring metric, either a string or a callable. This limitation makes it challenging to evaluate models using multiple evaluation metrics simultaneously, which is a common requirement in complex machine learning tasks.In contrast,
GridSearchCV
supports multiple scoring metrics by allowing a dictionary, list, or tuple as input for thescoring
parameter. This flexibility is particularly useful for tasks where multiple metrics must be considered (e.g.,accuracy
andf1_macro
for imbalanced classification problems).Providing support for multiple scoring metrics in
OptunaSearchCV
would make it a more versatile tool for hyperparameter optimization and align its functionality more closely withGridSearchCV
.Description
I propose extending
OptunaSearchCV
to support multiple scoring metrics, following the approach used inGridSearchCV
.Key Features:
Enhanced
scoring
parameter:Allow
scoring
to accept:Refit behavior:
Add a
refit
parameter to specify which metric should be used to select the best hyperparameters. This should mirror the behavior ofGridSearchCV
(e.g.,refit="accuracy"
).Comprehensive results:
Include all specified scoring metrics in the
cv_results_
attribute to provide a detailed evaluation of model performance for each metric.Example Usage:
Alternatives (optional)
No response
Additional context (optional)
I propose this feature because allowing multiple scoring metrics in
OptunaSearchCV
would make it easier to implement evaluation methods such as Tibshirani-Tibshirani and BBC-CV.The text was updated successfully, but these errors were encountered: