我不明白为什么运行以下代码时会出现错误KeyError: '[ 1351 1352 1353 ... 13500 13501 13502] not in index'
:
cv = KFold(n_splits=10)
for train_index, test_index in cv.split(X):
f_train_X, f_valid_X = X[train_index], X[test_index]
f_train_y, f_valid_y = y[train_index], y[test_index]
我使用X
(Pandas数据帧)分割I cv.split(X)
。
X.shape
y.shape
Out: (13503, 17)
Out: (13503,)
问题是您试图使用
X[train_index]
索引X
的方式。您需要使用.loc
或.iloc
,因为您有pandas
数据帧。使用这个
第1种方式:使用
的示例iloc
第二种方法:通过提前将pandas转换为numpy
相关问题 更多 >
编程相关推荐