[英]Getting error while running in jupyter notebook
Invalid parameter C for estimator DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None, max_features=None, max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, min_samples_leaf=1, min_samples_split=2, min_weight_fraction_leaf=0.0, presort=False, random_state=None, splitter='best').估计器决策树分类器的参数 C 无效(class_weight=None,criterion='gini',max_depth=None,max_features=None,max_leaf_nodes=None,min_impurity_decrease=0.0,min_impurity_sort=None,min_samples_leaf=1,min_samples_weight_split=2, =False,random_state=None,splitter='best')。 Check the list of available parameters with
estimator.get_params().keys()
.使用estimator.get_params().keys()
检查可用参数列表。
def train(X_train,y_train,X_test):
# Scaling features
X_train=preprocessing.scale(X_train)
X_test=preprocessing.scale(X_test)
Cs = 10.0 ** np.arange(-2,3,.5)
gammas = 10.0 ** np.arange(-2,3,.5)
param = [{'gamma': gammas, 'C': Cs}]
skf = StratifiedKFold(n_splits=5)
skf.get_n_splits(X_train, y_train)
cvk = skf
classifier = DecisionTreeClassifier()
clf = GridSearchCV(classifier,param_grid=param,cv=cvk)
clf.fit(X_train,y_train)
print("The best classifier is: ",clf.best_estimator_)
clf.best_estimator_.fit(X_train,y_train)
# Estimate score
scores = model_selection.cross_val_score(clf.best_estimator_, X_train,y_train, cv=5)
print (scores)
print('Estimated score: %0.5f (+/- %0.5f)' % (scores.mean(), scores.std() / 2))
title = 'Learning Curves (SVM, rbf kernel, $\gamma=%.6f$)' %clf.best_estimator_.gamma
plot_learning_curve(clf.best_estimator_, title, X_train, y_train, cv=5)
plt.show()
# Predict class
y_pred = clf.best_estimator_.predict(X_test)
return y_test,y_pred
It looks like you are making the
param
an array with a single dictionary inside.
看起来您正在使
param
成为一个内部有单个字典的数组。
param
needs to be just a dictionary:
param
需要只是一个字典:
EDIT : Looking into this further, as mentioned by @DzDev, passing an array containing a single dictionary is also a valid way to pass in parameters.编辑:进一步研究这一点,正如@DzDev 所提到的,传递包含单个字典的数组也是传递参数的有效方法。
It appears that your issue is that you are mixing the concepts of two different types of estimators.您的问题似乎是您混合了两种不同类型估计量的概念。 You are passing in the parameters for svm.SVC but are sending in a DecisionTreeClassifier estimator.您正在传递svm.SVC的参数,但正在发送DecisionTreeClassifier估计器。 So it turns out the error is exactly as it says, 'C'
is not a valid parameter.所以事实证明错误正如它所说的那样, 'C'
不是一个有效的参数。 You should update to either using a svm.SVC
estimator or updates your parameters to be correct for the DecisionTreeClassifier
.您应该更新为使用svm.SVC
估计器或更新您的参数以使其对DecisionTreeClassifier
正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.