【问题标题】:How to evaluate a soft Voting classifier being trained on some data如何评估在某些数据上训练的软投票分类器
【发布时间】:2018-01-13 06:59:57
【问题描述】:

我拿了3个分类模型,

clf1 = DecisionTreeClassifier(max_depth=4)
clf2 = KNeighborsClassifier(n_neighbors=7)
clf3 = SVC(kernel='rbf', probability=True)

我将它们作为参数传递给投票分类器并选择软投票。

eclf = VotingClassifier(estimators=[('dt', clf1), ('knn', clf2), ('svc', clf3)], voting='soft', weights=[2,1,2])

clf1 = clf1.fit(titanic_train1,y_train)
clf2 = clf2.fit(titanic_train1,y_train)
clf3 = clf3.fit(titanic_train1,y_train)
eclf = eclf.fit(titanic_train1,y_train)

这里出现错误,AttributeError: 'VotingClassifier' object has 没有属性'best_score_'

print("CvScore",eclf.best_score_)
print("Train accuracy",eclf.score(titanic_train1, y_train))

我想为此模型找到最佳调整参数?

【问题讨论】:

  • VotingClassifier 简单地采用单个估计器的概率并返回具有最大概率的类。您实际上想通过best_score_ 访问什么?你说你遇到了一个错误,但没有描述你想要做什么。

标签: python scikit-learn classification data-science


【解决方案1】:

VotingClassifier 没有 best_score_ 属性。您可以查看 scikit-learn 文档 here 以查看缺少 best_score_ 属性。

如果您想获得交叉验证分数,则需要使用 K-FoldGridSearchCV 之类的东西,其中 K-Fold 将让您了解分类器对幼稚数据的泛化程度,而 GridSearchCV 将帮助确定模型的最佳参数配置。

【讨论】:

    猜你喜欢
    • 2021-04-19
    • 1970-01-01
    • 2019-02-07
    • 2018-03-04
    • 2021-05-27
    • 2022-10-23
    • 2019-04-05
    • 2013-07-04
    • 1970-01-01
    相关资源
    最近更新 更多