# Found input variables with inconsistent numbers of samples

I would appreciate if you could let me know how to resolve this error:

Code:

X = np.array(pd.read_csv('my_X_table1-1c.csv',header=None).values)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=7)

def Ridgecv(alpha):
return cross_val_score(Ridge(alpha=float(alpha), random_state=2),
X_train, y_train, 'mae', cv=5).mean()


The error is related to X_train, y_train:

ValueError: Found input variables with inconsistent numbers of samples: [1052, 1052, 3]

• what's the result for X_train.shape and y_train.shape? – oW_ Jan 31 '17 at 20:47
• @oW_ Thanks. They respectively are (1052, 60) and (1052, ). – ebrahimi Jan 31 '17 at 21:11
• Try y_train.reshape((1052,1)) – oW_ Jan 31 '17 at 21:16
• @oW_ Thanks. I tried y_train.reshape(len(y_train),1) but unfortunately the same error is reported. – ebrahimi Feb 1 '17 at 5:53

It seems that I missed the word "scoring". In fact, the extra 3 was related to the number of characters of 'mae'.

def Ridgecv(alpha):
return cross_val_score(Ridge(alpha=float(alpha), random_state=2),
X_train, y_train, scoring='mae', cv=5).mean()

• Wow had the same bug ... hard one to spot! Thanks for posting this. – tdc Sep 4 '18 at 14:39

It should be in sequence:

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test=train_test_split(X,Y,random_state=101,test_size=0.3)


and then it should be in fit method(x_train,y train)

• sorry, the error is related to how to define parameters of cross_val_score. – ebrahimi Jul 29 '19 at 17:49