Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Add support for dict of scores in 'scoring' attribute" #23

Open
MarekWadinger opened this issue Apr 24, 2023 · 0 comments
Open

"Add support for dict of scores in 'scoring' attribute" #23

MarekWadinger opened this issue Apr 24, 2023 · 0 comments

Comments

@MarekWadinger
Copy link

Complete Description of the Issue

As a software developer, I want to track the improvement of ML model over iterations using multiple scoring metrics. This is a default behavior of parameter searching algorithms in sklearn (e.g., GridSearchCV ). Though able to use same API, NatureInspiredSearchCV raises a KeyError.

This seems to be due to default cv_results key used for evaluation, that changes from 'mean_test_score' to f'mean_test_{self.refit}'. However, method refit is not passed to ParameterSearch.

Simplest Possible Self-Contained Example Showing the Bug

from sklearn.datasets import make_classification
from sklearn.tree import DecisionTreeClassifier as DTC
from sklearn_nature_inspired_algorithms.model_selection import\
    NatureInspiredSearchCV as NIS_CV

X, y = make_classification()

tree = DTC(random_state=0)

param_grid = {'max_depth': [1, 2]}

scoring = {'AUC': 'roc_auc', 'F1': 'f1_macro'}

sh = NIS_CV(tree, param_grid,
            scoring=scoring, refit=False).fit(X, y)

Full Backtrace of Exception

Exception has occurred: KeyError Exception has occurred: KeyError 'mean_test_score' File "./Sklearn-Nature-Inspired-Search/sklearn_nature_inspired_algorithms/model_selection/_parameter_search.py", line 39, in _evaluate mean_test_score = cv_results['mean_test_score'] File "./Sklearn-Nature-Inspired-Search/sklearn_nature_inspired_algorithms/model_selection/_stagnation_stopping_task.py", line 40, in eval x_f = super().eval(A) File "./Sklearn-Nature-Inspired-Search/sklearn_nature_inspired_algorithms/model_selection/nature_inspired_search_cv.py", line 47, in _run_search self.__algorithm.run(task=task) File "./Sklearn-Nature-Inspired-Search/sklearn_nature_inspired_algorithms/model_selection/nature_inspired_search_cv.py", line 19, in fit return super().fit(X, y, groups=groups, **fit_params) File "./RnD/Similarity/bug_nia.py", line 15, in scoring=scoring, refit=False).fit(X, y) KeyError: 'mean_test_score'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant