# https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.RandomizedSearchCV.html #in this cv find the maximum alphas to minimize the error
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()`.
The key for your dictionary parameters
should be "alpha" instead of "alphas".
So just change that line to:
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]}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.