Nazmul Islam
Nazmul Islam

Reputation: 31

"ValueError: shapes not aligned" while doing OLS regression on a DataFrame

I was trying to run an OLS regression on a DataFrame I had but I got this error:

ValueError: shapes (48,34) and (48,34) not aligned: 34 (dim 1) != 48 (dim 0)

I'm not sure how to fix the alignment. I have included the OLS code I tried running and a picture of the DataFrame output. The entire DataFrame has 4 columns and 48 rows.

DataFrame output

import numpy as np
import statsmodels.formula.api as sm
result = sm.ols(formula="price ~ ownership + shipping + title", data=sold1).fit()
result.summary()

Upvotes: 3

Views: 3926

Answers (1)

Som Dubey
Som Dubey

Reputation: 131

Had the similar issue while running the linear regression in a loop for calculating the vif for factors. As mentioned by Josef in the comments, the reason was, i am having two columns as 'object' while rest were 'int'. Removed those two 'Object' column and it worked.

Upvotes: 2

Related Questions