def make_mf_lr(X ,y, clf, X_test, n_round=3):
n = X.shape[0]
'''
Fit metafeature by @clf and get prediction for test. Assumed that @clf -- regressor
'''
print clf
mf_tr = np.zeros(X.shape[0])
mf_te = np.zeros(X_test.shape[0])
for i in range(n_round):
skf = StratifiedKFold(y, n_folds=2, shuffle=True, random_state=42+i*1000)
for ind_tr, ind_te in skf:
X_tr = X[ind_tr]
X_te = X[ind_te]
# print('X_tr shape',X_tr.shape)
# print('X_te shape',X_te.shape)
y_tr = y[ind_tr]
y_te = y[ind_te]
clf.fit(X_tr, y_tr)
mf_tr[ind_te] += clf.predict_proba(X_te)[:,1]
mf_te += clf.predict_proba(X_test)[:,1]*0.5
y_pred = clf.predict_proba(X_te)[:,1]
score = roc_auc_score(y_te, y_pred)
print 'pred[{}] score:{}'.format(i, score)
return (mf_tr / n_round, mf_te / n_round)
评论列表
文章目录