我一直在RandomSearchCV中遇到AttributeError

x_tu = data_cls_tu.iloc[:,1:].valuesy_tu = data_cls_tu.iloc[:,0].valuesclassifier = DecisionTreeClassifier()parameters = [{"max_depth": [3,None],               "min_samples_leaf": np.random.randint(1,9),               "criterion": ["gini","entropy"]}]randomcv = RandomizedSearchCV(estimator=classifier, param_distributions=parameters,                              scoring='accuracy', cv=10, n_jobs=-1,                              random_state=0)randomcv.fit(x_tu, y_tu)---------------------------------------------------------------------------AttributeError                            Traceback (most recent call last)<ipython-input-17-fa8376cb54b8> in <module>()     11                               scoring='accuracy', cv=10, n_jobs=-1,     12                               random_state=0)---> 13 randomcv.fit(x_tu, y_tu)~\Anaconda3\lib\site-packages\sklearn\model_selection\_search.py in fit(self, X, y, groups, **fit_params)    616         n_splits = cv.get_n_splits(X, y, groups)    617         # Regenerate parameter iterable for each fit--> 618         candidate_params = list(self._get_param_iterator())    619         n_candidates = len(candidate_params)    620         if self.verbose > 0:~\Anaconda3\lib\site-packages\sklearn\model_selection\_search.py in __iter__(self)    236         # in this case we want to sample without replacement    237         all_lists = np.all([not hasattr(v, "rvs")--> 238                             for v in self.param_distributions.values()])    239         rnd = check_random_state(self.random_state)    240 AttributeError: 'list' object has no attribute 'values'

你好,我在使用RandomSearchCV的fit方法时一直遇到错误。

当我使用GridSearchCV时它是正常工作的,但GridSearchCV花了5个小时才完成。

x_tu和y_tu都是numpy.ndarray类型。


回答:

param_distributions必须是dict对象(文档),但你传递的是包含单个dict的列表。去掉最外层的方括号后应该就能正常工作了。

应该像这样:

parameters = {"max_depth": [3,None],               "min_samples_leaf": [np.random.randint(1,9)],               "criterion": ["gini","entropy"]}

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注