Reputation: 48
I am working on python3 jupyter notebook. I am creating a predictive model and I'm the following code at a particular step:
logit1 = sm.Logit(a, b).fit()
Here, a and b have exactly shame shape and type:
I am getting the following error at this step:
ValueError: The indices for endog and exog are not aligned.
I have already tried lookig for similar questions but cannot find anything with an answer that works.
Any help on this would be greatly appreciated
Upvotes: 0
Views: 10171
Reputation: 46
I had the same problem. In my case, both Series are the same length and the indices are visually equal but they didn't share the same location. So I made sure that both Series or DataFrames have exactly the same indices. I tried this and it solved the problem:
a.reindex(b.index)
Upvotes: 2
Reputation: 1
Sometimes even converting to list will result in error cannot perform reduce with flexible type. So it's better to convert it into numpy arrays. e.g.:
X_train, y_train -> np.array(y_train), np.array(X_train)
Upvotes: 0
Reputation: 345
Convert them to list type and then pass as argument to Logit() i.e logit1 = sm.Logit(list(a), list(b)).fit()
Upvotes: 0