Exemplo n.º 1
0
from sklearn.datasets import load_iris
from mlxtend.feature_selection import ColumnSelector
from sklearn.pipeline import make_pipeline

iris = load_iris()
X = iris.data[:100]
y = iris.target[:100]

pipe1 = make_pipeline(ColumnSelector(cols=(0, 2)), LogisticRegression())
pipe2 = make_pipeline(ColumnSelector(cols=(1, 2, 3)), LogisticRegression())

sclf = StackingClassifier(classifiers=[pipe1, pipe2],
                          meta_classifier=LogisticRegression())

sclf.fit(X, y)
decision_scores = sclf.decision_function(X)
print("Val auc Score of Stacking: %f" %
      (roc_auc_score(y,
                     sclf.predict_proba(X)[:, 1])))

fig, axe = plt.subplots(2, 2, figsize=(30, 20))
rlb.ComprehensiveIndicatorFigure(y, decision_scores, axe[0], 1)
rlb.ComprehensiveIndicatorSkLibFigure(y, decision_scores, axe[1])

# In[]:
# 5、ROC Curve with decision_function
from sklearn import model_selection
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier