【问题标题】:How can I evaluate all the combinations obtained by GridSearchCV?如何评估 GridSearchCV 获得的所有组合?
【发布时间】:2018-05-08 16:35:27
【问题描述】:

通过使用 GridSearchCV,我可以获得 clf.cv_results_['params'] 并且我想遍历所有可能的组合并打印一些概率:

for params in zip(clf.cv_results_['params']):
        print(params)
        clf= SVC(params)
        clf.fit(X_train, y_train)
        z_test=clf.predict(X_test)
        print("Probability 1:", prob_error(y_test,z_test))
        print("Probability 2:", average_error(y_test,z_test))

但是,在参数中我得到了这个:

({'C': 1000, 'gamma': 1000, 'tol': 2},)

如何转换它以适应算法?因为这段代码在“clf.fit(X_train, y_train)”中有错误:

TypeError: must be real number, not tuple

【问题讨论】:

    标签: python python-3.x machine-learning scikit-learn grid-search


    【解决方案1】:

    你为什么在clf.cv_results_['params'] 上使用 zip。删除它并像下面这样:

    for params in clf.cv_results_['params']:
            print(params)
            clf= SVC(**params)
            clf.fit(X_train, y_train)
            z_test=clf.predict(X_test)
            print("Probability 1:", prob_error(y_test,z_test))
            print("Probability 2:", average_error(y_test,z_test))
    

    更多详情请看这里:

    【讨论】:

      猜你喜欢
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-21
      • 1970-01-01
      相关资源
      最近更新 更多