[英]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.