原理
(1)模型融合
(2)集成学习
实现
参考资料
from mlxtend.classifier import EnsembleVoteClassifier
from mlxtend.classifier import StackingClassifier
from lightgbm import LGBMClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.svm import SVC
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.ensemble import RandomForestClassifier
if model_type == 'ensemble':
clf1 = LogisticRegression(random_state=0)
clf2 = XGBClassifier(random_state=0)
clf3 = SVC(random_state=0, kernel='linear', probability=True)
clf4 = MLPClassifier(random_state=0)
model = EnsembleVoteClassifier(clfs=[clf1, clf2, clf3, clf4],
weights=[1, 2, 2, 1], voting='soft', verbose=2)
elif model_type == 'stack':
clf1 = XGBClassifier(random_state=0)
clf2 = SVC(random_state=0, kernel='linear', probability=True)
clf3 = MLPClassifier(random_state=0)
lr = LogisticRegression()
model = StackingClassifier(classifiers=[clf1, clf2, clf3],
use_probas=True,
average_probas=False,
meta_classifier=lr)