import matplotlib.pyplot as plt
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import GridSearchCV
from sklearn import datasets
from sklearn_evaluation.plot import grid_search
iris = datasets.load_iris()
parameters = {
'n_estimators': [1, 10, 50, 100],
}
est = RandomForestClassifier()
clf = GridSearchCV(est, parameters, cv=5)
X, y = datasets.make_classification(1000, 10, n_informative=5, class_sep=0.7)
clf.fit(X, y)
# changing numeric parameter without any restrictions
# in the rest of the parameter set
grid_search(clf.cv_results_, change='n_estimators')
plt.show()
TypeError is thrown.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Untitled-1 in <cell line: 20>()
<a href='untitled:Untitled-1?line=15'>16</a> clf.fit(X, y)
<a href='untitled:Untitled-1?line=16'>17</a> # changing numeric parameter without any restrictions
<a href='untitled:Untitled-1?line=17'>18</a> # in the rest of the parameter set
---> <a href='untitled:Untitled-1?line=19'>20</a> grid_search(clf.cv_results_, change='n_estimators')
<a href='untitled:Untitled-1?line=20'>21</a> plt.show()
File ~/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py:81, in grid_search(cv_results_, change, subset, kind, cmap, ax)
[74](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=73)[ grid_scores = [
]()[75](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=74)[ gs(p, m, s) for p, m, s in
]()[76](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=75)[ zip(cv_results_['params'], cv_results_['mean_test_score'],
]()[77](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=76)[ cv_results_['std_test_score'])
]()[78](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=77)[ ]
]()[80](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=79)[ if isinstance(change, string_types) or len(change) == 1:
---> ]()[81](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=80)[ return _grid_search_single(grid_scores, change, subset, kind, ax)
]()[82](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=81)[ elif len(change) == 2:
]()[83](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=82)[ return _grid_search_double(grid_scores, change, subset, cmap, ax)
File ~/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py:142, in _grid_search_single(grid_scores, change, subset, kind, ax)
]()[140](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=139)[ label = ['{}: {}'.format(*t) for t in params_kv]
]()[141](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=140)[ # now convert it to one string
--> ]()[142](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=141)[ label = reduce(lambda x, y: x + ', ' + y, label)
]()[144](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=143)[ if kind == 'bar':
]()[145](file:///home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/sklearn_evaluation/plot/grid_search.py?line=144)[ bar_shifter(y, yerr=stds, label=label)
TypeError: reduce() of empty iterable with no initial value]()
System:
python: 3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:39:04) [GCC 10.3.0]
executable: /home/adrien/mambaforge/envs/fno/bin/python
machine: Linux-4.15.0-175-generic-x86_64-with-glibc2.27
Python dependencies:
pip: 22.0.4
setuptools: 62.1.0
sklearn: 1.0.2
numpy: 1.21.5
scipy: 1.8.0
Cython: None
pandas: 1.4.2
matplotlib: 3.5.1
joblib: 1.1.0
threadpoolctl: 3.1.0
Built with OpenMP: True
/home/adrien/mambaforge/envs/fno/lib/python3.10/site-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")