- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 0 个
- 通用积分
- 0
- 学术水平
- 0 点
- 热心指数
- 0 点
- 信用等级
- 0 点
- 经验
- 127 点
- 帖子
- 14
- 精华
- 0
- 在线时间
- 13 小时
- 注册时间
- 2018-4-18
- 最后登录
- 2018-5-20
初中生
还不是VIP/贵宾
- 威望
- 0 级
- 论坛币
- 0 个
- 通用积分
- 0
- 学术水平
- 0 点
- 热心指数
- 0 点
- 信用等级
- 0 点
- 经验
- 127 点
- 帖子
- 14
- 精华
- 0
- 在线时间
- 13 小时
- 注册时间
- 2018-4-18
- 最后登录
- 2018-5-20
|
10论坛币
在做模型融合的时候提示feature_names mismatch 实在是找不出哪里出错了 请大神帮忙看看
from sklearn.base import clone
def stacking(base_learners, meta_learner, X, y, generator):
print("Fitting final base learners...", end="")
train_base_learners(base_learners, X, y, verbose=False)
print("done")
print("Generating cross-validated predictions...")
cv_preds, cv_y = [], []
for i, (train_idx, test_idx) in enumerate(generator.split(X)):
fold_xtrain, fold_ytrain = X[train_idx, :], y[train_idx]
fold_xtest, fold_ytest = X[test_idx, :], y[test_idx]
fold_base_learners = {name: clone(model)
for name, model in base_learners.items()}
train_base_learners(
fold_base_learners, fold_xtrain, fold_ytrain, verbose=False)
fold_P_base = predict_base_learners(
fold_base_learners, fold_xtest, verbose=False)
cv_preds.append(fold_P_base)
cv_y.append(fold_ytest)
print("Fold %i done" % (i + 1))
print("CV-predictions done")
cv_preds = np.vstack(cv_preds)
cv_y = np.hstack(cv_y)
print("Fitting meta learner...", end="")
meta_learner.fit(cv_preds, cv_y)
print("done")
return base_learners, meta_learner
from sklearn.model_selection import KFold
cv_base_learners, cv_meta_learner = stacking(
get_models(), clone(meta_learner), xtrain.values, ytrain.values, KFold(2))
P_pred, p = ensemble_predict(cv_base_learners, cv_meta_learner, xtest, verbose=False)
print("\nEnsemble ROC-AUC score: %.3f" % roc_auc_score(ytest, p))
|
|