以下是代码:
oof_train =np.zeros((n-train))oof_test = np.zeros((n_test,))oof_test_skf = np.zeros((5,n_test))for i,(train_index,test_index) in enumerate(kf.split(X_train)):kf_X_train=X_train[train_index]kf_Y_train = Y_train[train_index]kf_X_test=X_train[test_index]model=RandomForestclassifier.fit(kf_X_train,kf_Y_train)oof_train[test_index]=model.predict(kf_X_test)oof_test_skf[i,:]=model.predict(X_test)oof_test[:]=oof_test_skf.mean(axis=0)
print(oof_train,oof_test)