【发布时间】:2020-05-10 16:47:45
【问题描述】:
有一个 323 列和 10348 行的数据框。我想使用以下代码使用分层 k 折来划分它
df= pd.read_csv("path")
x=df.loc[:, ~df.columns.isin(['flag'])]
y= df['flag']
StratifiedKFold(n_splits=5, random_state=None, shuffle=False)
for train_index, test_index in skf.split(x, y):
print("TRAIN:", train_index, "TEST:", test_index)
x_train, x_test = x[train_index], x[test_index]
y_train, y_test = y[train_index], y[test_index]
但我收到以下错误
KeyError: "None of [Int64Index([ 0, 1, 2, 3, 4, 5, 6, 7, 8,\n 10,\n ...\n 10338, 10339, 10340, 10341, 10342, 10343, 10344, 10345, 10346,\n 10347],\n dtype='int64', length=9313)] are in the [columns]"
任何人告诉我为什么我会得到这个错误以及如何解决它
【问题讨论】:
标签: python python-3.x pandas python-2.7 scikit-learn