I have a dataframe
where I am trying to run the statsmodel.api
OLS regression.
It is printing out the summary. But when I am using the predict()
function, it is giving me an error -
shapes (75,7) and (6,) not aligned: 7 (dim 1) != 6 (dim 0)
My code is:
X = newdf.loc[:, newdf.columns != 'V-9'].values
y = newdf.iloc[:,3].values
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size =
0.2,random_state=0)
import statsmodels.formula.api as sm
model = sm.OLS(y_train,X_train[:,[0,1,2,3,4,6]])
result = model.fit()
print(result.summary())`
Error comes on running this:
y_pred = result.predict(X_test)
Shape of my X_train
is - (297,7)
Shape of my X_test
is - (75,7)
dtype
is numpy.ndarray
This question has been asked before. I have followed some posts on stackoverflow.com and tried to solve it using reshape
function. However, it didnt help me. Can anyone explain why I am getting this error? and what is the solution?
7(dim1)!+6(dim0)
y_pred = result.predict(X_test[:,[0,1,2,3,4,6]])