I am trying to apply a forecasted model with OLS regression to a test dataset, but when I use the .predict() method, I have this error:
ValueError: shapes (2938,4) and (1583,5) not aligned: 4 (dim 1) != 1583 (dim 0)I add this replicable example of the problem where I obtain the same error (with different shapes because dataset is different):
from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split import statsmodels.api as sm iris_data = load_iris() iris_dataframe = pd.DataFrame(iris_data.data, columns=iris_data.feature_names) X_train, X_test = train_test_split(iris_dataframe, test_size=0.2, random_state=1) X_train.head() X_test.head() model_test = sm.OLS(X_train["petal width (cm)"],X_train.iloc[:,0:3]) results_test=model_test.fit() print(results_test.summary()) test_preds=model_test.predict(X_test)As you can see, when I try to create test_preds, I have the sample error. I am using wrongly the .predict method? I am using as input the dataset X_test, that has the same columns number and names of the training dataset X_train.