-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathiris_stack3.py
33 lines (23 loc) · 989 Bytes
/
iris_stack3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
################## load packages #####################
from sklearn import datasets
from sklearn.linear_model import LogisticRegression
from mlxtend.classifier import StackingClassifier
from mlxtend.feature_selection import ColumnSelector
from sklearn.pipeline import make_pipeline
################## load data #####################
iris = datasets.load_iris()
x, y = iris.data, iris.target
################## define classifier #####################
pipe1 = make_pipeline(ColumnSelector(cols=(0, 1)),
LogisticRegression())
pipe2 = make_pipeline(ColumnSelector(cols=(2, 3)),
LogisticRegression())
sclf = StackingClassifier(classifiers=[pipe1, pipe2],
meta_classifier=LogisticRegression())
################## fit and predict #####################
sclf.fit(x, y)
print(sclf.predict(x))
########### predict class probability ###########
print(sclf.predict_proba(x))