我写了下面的代码。X
是具有形状的数据框(1000,5)
,y
是具有形状的数据框(1000,1)
。y
是要预测的目标数据,而且是不平衡的。我想应用交叉验证和 SMOTE。
def Learning(n, est, X, y):
s_k_fold = StratifiedKFold(n_splits = n)
acc_scores = []
rec_scores = []
f1_scores = []
for train_index, test_index in s_k_fold.split(X, y):
X_train = X[train_index]
y_train = y[train_index]
sm = SMOTE(random_state=42)
X_resampled, y_resampled = sm.fit_resample(X_train, y_train)
X_test = X[test_index]
y_test = y[test_index]
est.fit(X_resampled, y_resampled)
y_pred = est.predict(X_test)
acc_scores.append(accuracy_score(y_test, y_pred))
rec_scores.append(recall_score(y_test, y_pred))
f1_scores.append(f1_score(y_test, y_pred))
print('Accuracy:',np.mean(acc_scores))
print('Recall:',np.mean(rec_scores))
print('F1:',np.mean(f1_scores))
Learning(3, SGDClassifier(), X_train_s_pca, y_train)
当我运行代码时,我收到以下错误:
[Int64Index([ 4231, 4235, 4246, 4250, 4255, 4295, 4317, 4344, 4381,\n 4387,\n ...\n 13122, 13123, 13124, 13125, 13126, 1313127, 13128, , 13130,\n
13131],\n dtype='int64', length=8754)] 在 [columns]"
帮助使其运行表示赞赏。