[英]please help me to find a ValueError in this code
# https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.RandomizedSearchCV.html #在這個簡歷中找到最大的alphas來最小化錯誤
from sklearn.model_selection import RandomizedSearchCV
#use multinomialnb as a model
model = MultinomialNB(class_prior = [0.5, 0.5])
parameters = {'alphas' :[0.00001,0.0005, 0.0001,0.005,0.001,0.05,0.01,0.1,0.5,1,5,10,50,100]}
#use randomizedsearch as a cv
clf = RandomizedSearchCV(model, parameters, cv= 5,
scoring='roc_auc',verbose=1,return_train_score=True)
#to fit the model
clf.fit(X_tr, y_train)#in this line to genrate the error
#to genrate a dataframe & sort the value
results = pd.DataFrame.from_dict(clf.cv_results_)
results = results.sort_values(['param_alphas'])
#to find a auc result to genrate a auc curve
train_auc= results['mean_train_score']
train_auc_std= results['std_train_score']
cv_auc = results['mean_test_score']
cv_auc_std= results['std_test_score']
alphas = results['param_alphas']```
ValueError Traceback (most recent call last)
<ipython-input-65-23b8907f0343> in <module>
7
8 clf = RandomizedSearchCV(model, parameters, cv= 5, scoring='roc_auc',verbose=1,return_train_score=True)
----> 9 clf.fit(X_tr, y_train)
10
11 results = pd.DataFrame.from_dict(clf.cv_results_)
ValueError: Invalid parameter alphas for estimator MultinomialNB(alpha=1.0, class_prior=[0.5, 0.5], fit_prior=True). Check the list of available parameters with `estimator.get_params().keys()`.
字典parameters
的鍵應該是“alpha”而不是“alphas”。
所以只需將該行更改為:
parameters = {'alpha' :[0.00001,0.0005, 0.0001,0.005,0.001,0.05,0.01,0.1,0.5,1,5,10,50,100]}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.