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
Possible to Loop Through Excel Files With Differently Named Sheets, and Import into a List
Sub Totals and Grand Totals in Python
How to Ask a Set of Questions Multiple Times Based on User Input
How to Fill Empty Cell Value in Pandas With Condition
How to Open a Password Protected Excel File Using Python
How to Remove \N from a List Element
How to Clear All Variables in the Middle of a Python Script
How to Get the Return Value from a Thread in Python
Easiest Way to Replace a String Using a Dictionary of Replacements
How Does \R (Carriage Return) Work in Python
How to Close a Tkinter Window by Pressing a Button
How to Make Type Cast for Python Custom Class
How to Compare 2 Indexes in Same List in Python