I am trying to use StackingClassifier with Logistic regression (Binary Classifier). Sample code:
from sklearn.datasets import load_iris
from mlxtend.classifier import StackingClassifier
from sklearn.linear_model import LogisticRegression
iris = load_iris()
X = iris.data
y = iris.target
y[y == 2] = 1 #Make it binary classifier
LR1 = LogisticRegression(penalty='l1')
LR2 = LogisticRegression(penalty='l1')
LR3 = LogisticRegression(penalty='l1')
LR4 = LogisticRegression(penalty='l1')
LR5 = LogisticRegression(penalty='l1')
clfs1= [LR1, LR2]
clfs2= [LR3, LR4, LR5]
cls_=[]
cls_.append(clfs1)
cls_.append(clfs2)
sclf = StackingClassifier(classifiers=sum(cls_,[]),
meta_classifier=LogisticRegression(penalty='l1'), use_probas=True, average_probas=False)
sclf.fit(X, y)
sclf.meta_clf_.coef_ #give the weight values
For each classifier, Initial logistic regression gives a probability value for two classes. As I am using stacking 5 classifiers, sclf.meta_clf_.coef_
gives 10 weights values.
array([[-0.96815163, 1.25335525, -0.03120535, 0.8533569 , -2.6250897 , 1.98034805, -0.361378 , 0.00571954, -0.03206343, 0.53138651]])
I am confused about the order of weight values. means
Are the 1st two values
(-0.96815163, 1.25335525)
for first logistic regressionLR1
?Are the 2nd two values
(-0.03120535, 0.8533569)
for first logistic regressionLR2
?
I want to find out which values are for which Logistic Regression (LR) for the stacking classifier.
Please Help.