Issue
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")
Solution
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)
Answered By - StupidWolf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.