Reputation:
I've tried to run code and get the error too many values to unpack, how to fix the issue? This a piece of code, cannot see the error...
parameter_grid = [{'n_estimators': [100], 'max_depth': [2, 4, 7, 12, 16]}, {'max_depth': [4], 'n_estimators': [25, 50, 100, 250]}]
metrics = ['precision_weighted', 'recall_weighted']
for metric in metrics:
print("\n##### searching optimal parameters for ", metric)
classifier = GridSearchCV(ExtraTreesClassifier(random_state=0), parameter_grid, cv=5, scoring=metric)
classifier.fit(X_train, y_train)
print("\ngrid scores for the parameter grid:")
for params, avg_score, _ in classifier.cv_results_:
print(params, '-->', round(avg_score, 3))
Upvotes: 2
Views: 1671
Reputation: 14102
cv_results_
is a dict that contains the results of the GridSearchCV
. It looks something like this:
That means if you want to access it, you need to access it the same way you access a dictionary in Python:
for key, value in classifier.cv_results_.items():
# do something like print("{} ... {}".format(key, value))
The error basically says: You are asking to unpack the content, which contains too many values, into few placeholders/receivers that are less than what we can unpack!
Upvotes: 1