Numpy Array Typeerror: Only Integer Scalar Arrays Can Be Converted to a Scalar Index

Numpy: only integer scalar arrays can be converted to a scalar index

You are missing the shape in the second element of the tuple:

x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))

TypeError: only integer scalar arrays can be converted to a scalar index in python

Probably you either have arrays that are not numpy or indexes that are not of the int type. If it doesn't work, then show some rows with data X, Y.

X = df[['Smedications', 'Infections', 'lib' , 'north']].values

Y= df['Comorbidities'].values

kf = KFold(n_splits=10, shuffle=True)
list(kf.split(X))
splits = list(kf.split(X))
train_indices, test_indices = splits[0]
X_train = np.array(X)[train_indices.astype(int)]
X_test = np.array(X)[test_indices.astype(int)]
y_train = np.array(y)[train_indices.astype(int)]
y_test = np.array(y)[test_indices.astype(int)]

model = LogisticRegression()
model.fit(X_train, y_train)
print(model.score(X_test, y_test))


Related Topics



Leave a reply



Submit