I am fitting a regression model on randomly generated X1,x2 and Y be the sum of x1, x2 but I am getting this error

ValueError: Found input variables with inconsistent numbers of samples: [2, 10000000]

Note:- I am doing this only for learning purposes

My code:-

X = np.random.random_integers(100000000,size=(2,10000000))
X=(X-(100000000/2))/(100000000/2) # Scaling [-1,1]
Y = X[0]+X[1]

regr = linear_model.LinearRegression()
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, 

1 Answer 1


You need the shape of your training data to be (num_samples, num_features) or in your case (10000000, 2). An easy way to fix this is to transpose X before feeding it to the train test split:

X_train, X_test, y_train, y_test = train_test_split(X.T, Y, test_size=0.2, random_state=0)
regr.fit(X_train, y_train)  # <-- also 'y_train' not 'Y_train' here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.