问题
i am running the notebook at this site https://github.com/vsmolyakov/experiments_with_python/blob/master/chp01/ensemble_methods.ipynb to practice ensemble methods with python, and getting an error when running this part of the code in python 3:
plt.figure()
(_, caps, _) = plt.errorbar(num_est, bg_clf_cv_mean, yerr=bg_clf_cv_std, c='blue', fmt='-o', capsize=5)
for cap in caps:
cap.set_markeredgewidth(1)
plt.ylabel('Accuracy'); plt.xlabel('Ensemble Size'); plt.title('Bagging Tree Ensemble');
plt.show()
The error is "matplotlib does not support generators as input" what is the solution? best regards
回答1:
In that example
there is a line num_est = map(int, np.linspace(1,100,20))
. This produces a list in python 2.7. But in python 3 it is just a generator. The map is strange anyways, so I'd recommend to replace that line by
num_est = np.linspace(1,100,20).astype(int)
来源:https://stackoverflow.com/questions/53862456/matplotlib-does-not-support-generators-as-input