As a software developer, I want to tune dict-like parameters of ML model to improve its ability to generalize. This is a default behavior of parameter searching algorithms in sklearn (e.g., GridSearchCV ). Though able to use same API, NatureInspiredSearchCV raises an TypeError.
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 = {'class_weight':
[{False: 1, True: 2},
{False: 1, True: 1}]}
sh = NIS_CV(tree, param_grid, scoring='f1_macro').fit(X, y)
Full Backtrace of Exception
Exception has occurred: TypeErrorException has occurred: TypeError
unhashable type: 'dict'
File "./Sklearn-Nature-Inspired-Search/sklearn_nature_inspired_algorithms/model_selection/_parameter_search.py", line 23, in get_cached_score
if cache_key in self.cache:
File "./Sklearn-Nature-Inspired-Search/sklearn_nature_inspired_algorithms/model_selection/_parameter_search.py", line 35, in _evaluate
score = self.get_cached_score(params)
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
sh = NIS_CV(tree, param_grid, scoring='f1_macro').fit(X, y)
TypeError: unhashable type: 'dict'
Complete Description of the Issue
As a software developer, I want to tune dict-like parameters of ML model to improve its ability to generalize. This is a default behavior of parameter searching algorithms in sklearn (e.g., GridSearchCV ). Though able to use same API, NatureInspiredSearchCV raises an TypeError.
Simplest Possible Self-Contained Example Showing the Bug
Full Backtrace of Exception
Exception has occurred: TypeError
Exception has occurred: TypeError unhashable type: 'dict' File "./Sklearn-Nature-Inspired-Search/sklearn_nature_inspired_algorithms/model_selection/_parameter_search.py", line 23, in get_cached_score if cache_key in self.cache: File "./Sklearn-Nature-Inspired-Search/sklearn_nature_inspired_algorithms/model_selection/_parameter_search.py", line 35, in _evaluate score = self.get_cached_score(params) 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
sh = NIS_CV(tree, param_grid, scoring='f1_macro').fit(X, y)
TypeError: unhashable type: 'dict'