def stacking(base_models, X, Y, T):
models = base_models
folds = list(KFold(len(Y), n_folds=10, random_state=0))
S_train = np.zeros((X.shape[0], len(models)))
S_test = np.zeros((T.shape[0], len(models)))
for i, bm in enumerate(models):
clf = bm[1]
S_test_i = np.zeros((T.shape[0], len(folds)))
for j, (train_idx, test_idx) in enumerate(folds):
X_train = X[train_idx]
y_train = Y[train_idx]
X_holdout = X[test_idx]
clf.fit(X_train, y_train)
y_pred = clf.predict(X_holdout)[:]
S_train[test_idx, i] = y_pred
S_test_i[:, j] = clf.predict(T)[:]
S_test[:, i] = S_test_i.mean(1)
nuss=NuSVR(kernel='rbf')
nuss.fit(S_train, Y)
yp = nuss.predict(S_test)[:]
return yp
# load train data, the growthrate and log value of train data has been preserved in advance
评论列表
文章目录