Please help me to get out of this error, maybe, it’s duplicate but I could not set it for my code.
import pandas as pd
from sklearn.model_selection import KFold
df = pd.read_csv('DATA.txt',delimiter=',')
df.head()
X= df.COL1,df.COL2
Y=df.COL3
print(X)
print(Y)
cv = KFold(n_splits=2, random_state=10, shuffle=False)
for train_index, test_index in cv.split(X):
print("Train Index: ", train_index, "n")
print("Test Index: ", test_index)
X_train, X_test, Y_train, Y_test = X[train_index], X[test_index], Y[train_index], Y[test_index]
print(X_train)
print(Y_train)
ERROR
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-56-8c160cb8bf67> in <module> ----> 1 X_train, X_test, Y_train, Y_test = X[train_index], X[test_index], Y[train_index], Y[test_index] TypeError: only integer scalar arrays can be converted to a scalar index
dataset
9.999999,0.1,1 94.9999,0.1,1 89.9999,0.2,0 99.9999,0.3,0
Advertisement
Answer
I think you might want to select your X columns slightly differently, e.g.
X = df[['COL1', 'COL2']]