I am trying to load and split my data however i get TypeError: 'only integer scalar arrays can be converted to a scalar index'

Viewed 43

Imports

import numpy as np
from sklearn.linear_model import LogisticRegression # Architecture model
from sklearn.datasets import _olivetti_faces # Dataset
from sklearn.model_selection import train_test_split

### Loading and splitting the data
data = np.load("/content/Face_Recognition/olivetti_faces.npy")
Xtrain, Xtest, Ytrain, Ytest = train_test_split(data.data, test_size=0.3, random_state=0)
#Error to show if x and y rows mismatch
print(X.shape)
print(y.shape)
if X.shape[0] != y.shape[0]:

  print("X and y rows are mismatched, check dataset again")
1 Answers

Seems like you are using an outdated version of the dataset. You see the updated link here. The code you have will not work because you are asking for splits on data and target, while you are only providing target.

Something like this should work (on sklearn 0.24.1) :

from sklearn.datasets import fetch_olivetti_faces

data = fetch_olivetti_faces()
Xtrain, Xtest, Ytrain, Ytest = train_test_split(data.data, data.target, test_size=0.3, random_state=0)
Related