简体   繁体   English

在 jupyter notebook 中运行时出错

[英]Getting error while running in jupyter notebook

ERROR错误

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()检查可用参数列表。

CODE代码

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.

相关问题 为什么在运行 jupyter notebook 时出现错误? - Why am I getting an error while running jupyter notebook? 在 Jupyter 笔记本中运行时出现错误 - Getting errors while running in Jupyter notebook 为了将 chrome 设置为 jupyter 的默认浏览器,我在运行配置文件时遇到错误 - jupyter_notebook_config.py - In order to set chrome as default browser for jupyter , i'm getting error while running config file- jupyter_notebook_config.py 让 Jupyter 笔记本在运行连续进程时监听输入事件? - Getting a Jupyter notebook to listen to input events while running a continuous process? 在Windows的Jupyter Notebook中运行Linux命令时出错 - Error while running Linux commands in Jupyter notebook on windows 在 jupyter notebook 中使用 min() 函数时出错 - Getting Error while using min() funtion in jupyter notebook 在Jupyter Notebook中使用watson_developer_cloud时出错 - Getting error while using watson_developer_cloud in Jupyter Notebook sklearn:在jupyter笔记本中导入sklean时出错 - sklearn: Getting error while importing sklean in jupyter notebook 在Jupyter Notebook中连接到SQL DB时出现错误 - I am getting an error while connecting to an sql DB in Jupyter Notebook 尝试打开 Jupyter 笔记本或 Spyder 时出现 kernel 错误 - Getting kernel error while trying to open Jupyter notebook or Spyder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM