MrWednesday
MrWednesday

Reputation: 27

Linear Regression fitting

I have first done a train/test split then fitted that data to a LinearRegression model shown below

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.4, random_state = 101)

Log_m = LinearRegression()

Log_m.fit(X_train,y_train)

predictions = Log_m.predict(X_test)

I have been given another test data frame and wanted to fit that to the Log_m model which has been created. So I did

predictions_t = Log_m.predict(fin_df1_t)

But I get the error message :

ValueError: shapes (1450,262) and (282,) not aligned: 262 (dim 1) != 282 (dim 0)

These are the shapes of dataframes

fin_df1_t (1450,262)

X_test (556,282)

X_train (834,282)

y_test (556,)

y_train (834,)

Upvotes: 0

Views: 48

Answers (1)

Muhammad Shahzad
Muhammad Shahzad

Reputation: 381

The feature columns of new test data (262) are not equal to feature columns of Xtrain and Xtest (282), so it will always give an error. Both should have the same feature columns. For example, Xtrain and Xtest have the same columns (282), so there is no error at that step.

Upvotes: 1

Related Questions