1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| from sklearn import metrics from sklearn.ensemble import BaggingClassifier, AdaBoostClassifier from sklearn.metrics import accuracy_score
for name,clf in models.items(): bcclf = BaggingClassifier(estimator=clf,n_estimators=50,max_samples=0.7,max_features=0.7,bootstrap=True,bootstrap_features=True,n_jobs=1,random_state=42)
bcclf.fit(train_x,train_y.flatten()) pre = [x[1] for x in bcclf.predict_proba(valid_x)] fpr,tpr,thresholds = metrics.roc_curve(valid_y.flatten(),pre,pos_label=1) auc = metrics.auc(fpr, tpr) print("Bagging auc", name, auc)
if name!="Knn": adclf = AdaBoostClassifier(estimator=clf,n_estimators=30,learning_rate=1,algorithm="SAMME.R") adclf.fit(train_x,train_y.flatten()) pre = [x[1] for x in adclf.predict_proba(valid_x)] fpr, tpr, thresholds = metrics.roc_curve( valid_y.flatten(), pre, pos_label=1) auc = metrics.auc(fpr, tpr) print("Boosting auc", name, auc)
print()
|