在scikit-learn中组合概率分类器的最佳方法 [英] Best way to combine probabilistic classifiers in scikit-learn
本文介绍了在scikit-learn中组合概率分类器的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个逻辑回归和一个随机森林,我想将它们结合起来(合奏)以通过取平均值来进行最终的分类概率计算.
I have a logistic regression and a random forest and I'd like to combine them (ensemble) for the final classification probability calculation by taking an average.
在sci-kit学习中是否有内置的方法可以做到这一点?我可以以某种方式将两者的集合用作分类器吗?还是我需要推出自己的分类器?
Is there a built-in way to do this in sci-kit learn? Some way where I can use the ensemble of the two as a classifier itself? Or would I need to roll my own classifier?
推荐答案
NOTE: The scikit-learn Voting Classifier is probably the best way to do this now
旧答案:
出于什么价值,我最终这样做如下:
For what it's worth I ended up doing this as follows:
class EnsembleClassifier(BaseEstimator, ClassifierMixin):
def __init__(self, classifiers=None):
self.classifiers = classifiers
def fit(self, X, y):
for classifier in self.classifiers:
classifier.fit(X, y)
def predict_proba(self, X):
self.predictions_ = list()
for classifier in self.classifiers:
self.predictions_.append(classifier.predict_proba(X))
return np.mean(self.predictions_, axis=0)
这篇关于在scikit-learn中组合概率分类器的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文