gpt4 book ai didi

python - RandomizedSearchCv 导致属性错误

转载 作者:行者123 更新时间:2023-11-30 09:01:06 26 4
gpt4 key购买 nike

在 RandomizedSearchCv 上执行 fit() 后:

        tfidf = TfidfVectorizer(strip_accents=None,lowercase=False,preprocessor=None)
param_grid =
{'vect__ngram_range': [(1,1)],'vect__stop_words': [stop, None],
'vect__tokenizer': [tokenizer, tokenizer_porter],
'clf__penalty': ['l1', 'l2'],
'clf__C': [1.0, 10.0, 100.0]},
lr_tfidf = Pipeline([('vect', tfidf),('clf',LogisticRegression(random_state=0))])
gs_lr_tfidf = RandomizedSearchCV(lr_tfidf,param_grid,cv=5,n_jobs=1)
gs_lr_tfidf.fit(X_train, y_train)

我收到以下错误:

    Traceback (most recent call last):
File "G:/pythonprojectraschka/ch08/ch08-2.py", line 95, in <module>
gs_lr_tfidf.fit(X_train, y_train)
File "C:\Anaconda3\lib\site-packages\sklearn\grid_search.py", line 996, in fit
return self._fit(X, y, sampled_params)
File "C:\Anaconda3\lib\site-packages\sklearn\grid_search.py", line 553, in _fit
for parameters in parameter_iterable
File "C:\Anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py", line 800, in __call__
while self.dispatch_one_batch(iterator):
File "C:\Anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py", line 653, in dispatch_one_batch
tasks = BatchedCalls(itertools.islice(iterator, batch_size))
File "C:\Anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py", line 68, in __init__
self.items = list(iterator_slice)
File "C:\Anaconda3\lib\site-packages\sklearn\grid_search.py", line 549, in <genexpr>
delayed(_fit_and_score)(clone(base_estimator), X, y, self.scorer_,
File "C:\Anaconda3\lib\site-packages\sklearn\grid_search.py", line 223, in __iter__
for v in self.param_distributions.values()])
AttributeError: 'list' object has no attribute 'values'

但例如,Pipeline(lr_tfidf) 执行没有任何问题:

lr_tfidf.fit(X_train, y_train)

可能是什么原因? X_train(text) 和 y_train(binary) 是正确的(我猜)numpy 数组。

带有数据集的完整代码: https://github.com/kuba2111/untitled12

最佳答案

这里您使用的是 RandomizedSearchCV而不是GridSearchCV 。所以看起来它认为其中一个参数是一个分布,并尝试从这个分布中采样。

因此,如果您愿意使用 GridSearchCV 对所有参数进行详尽的搜索,那么您的解决方案就是您的解决方案。

enter image description here

关于python - RandomizedSearchCv 导致属性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36488564/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com