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