我有两个不同的特性集(因此,具有相同的行数和标签),在我的例子中DataFrames
:
df1
:
| A | B | C |
-------------
| 1 | 4 | 2 |
| 1 | 4 | 8 |
| 2 | 1 | 1 |
| 2 | 3 | 0 |
| 3 | 2 | 5 |
df2
:
labels
:
| labels |
----------
| 5 |
| 5 |
| 1 |
| 7 |
| 3 |
我想用它们来训练VotingClassifier
。但是拟合步骤只允许指定一个特征集。目标是使clf1
与df1
匹配,clf2
与{
eclf = VotingClassifier(estimators=[('df1-clf', clf1), ('df2-clf', clf2)], voting='soft')
eclf.fit(...)
我该如何处理这种情况?有什么简单的解决办法吗?在
为了尽可能多地使用sklearn工具,我发现以下方法更具吸引力。在
定制函数来实现您想要的功能是非常容易的。在
导入先决条件:
逻辑取自VotingClassifier source。在
现在测试上述方法。 首先获取一些数据:
^{pr2}$将数据分成训练和测试:
将X划分为不同的特征数据:
获取分类器列表:
将分类器与数据匹配:
使用测试数据预测:
获得预测的准确性:
如果有任何疑问,请随时询问。在
相关问题 更多 >
编程相关推荐