You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
predict accepts a DataFrame but returns a numpy array (rather than Series) #1352
This loses any Index information on the input DataFrame.
This would not be an issue except for the fact that the shape of the input DataFrame does not match the returned numpy array which makes combining the two tricky.
This is because some of the data is dropped when performing the transform:
Do you have an example where the length of the returned prediction is different from the number of rows in the DataFrame?
I thought this should always be the same.
Is it the case if there are missing values in your predict exog? Or, is there a transform that changes the number of observations?
Here is a more fleshed out example of how this can be improved:
import pandas as pd
from statsmodels.formula.api import ols
from patsy import dmatrix
s = pd.Series(range(10),index=pd.date_range("2013-1-1", periods=10)).to_frame()
def shifter(x):
return x.shift()
model = "s ~ shifter(s)"
fit = ols(model, data=s).fit()
While I agree, my new rule is we need timings before discussing any timings. It's a concern, but I don't know how much yet. We're going to be able to remove some checks that are in there already that patsy would also do (more robustly), so the overhead might really be negligible. What's negligible for bootstrap? We decide when we have timings I guess.
A few ways forward that come to mind.
This magic goes in the Results.predict. Bootstrap relies on Model.predict, which Results.predict also calls. Everyone wins.
We provide the predict somehow in the wrapper classes and bootstrap relies on Results._results.predict.
I'm leaning towards 1. Seems simple and straight-forward.
I think we just need a simple type check; if types(exog) is np.array or something like that.
also what happens if exog is None and we calculate the fittedvalues, which are separately wrapped AFAIR, and should be arrays in _results.
I encountered this recently and ended up very confused about what was happening. I'm glad to see it's not just me. Including pandas index information in the results from predict (at least optionally), or preserving length (to match the length of predicts argument) would make predict much easier to use.
I started part of pandas handling in my branch for prediction intervals.
I want to remove all data/exog handling from predict and outsource it, which is another issue
We need design decision and helper functions, Kerby has also PRs for prediction.
Activity
josef-pkt commentedon Feb 4, 2014
Do you have an example where the length of the returned prediction is different from the number of rows in the DataFrame?
I thought this should always be the same.
Is it the case if there are missing values in your predict exog? Or, is there a transform that changes the number of observations?
cancan101 commentedon Feb 4, 2014
The default argument for
dmatrixisNA_action='drop'.I have a transform that can produce NaNs.
cancan101 commentedon Feb 4, 2014
Example:
cancan101 commentedon Mar 6, 2014
Here is a more fleshed out example of how this can be improved:
Current prediction:
New prediction:
jseabold commentedon Mar 6, 2014
Hmm, yes, I quite like this approach. It won't work for predict and forecast in TSA, but that should be overwritten already anyway.
jseabold commentedon Mar 6, 2014
I'll have to look at the speed penalty vs. pure arrays for bootstrapping, etc. but I doubt it's that substantial.
josef-pkt commentedon Mar 6, 2014
We need to avoid any non-numpy overhead for bootstrapping and cross-validation.
jseabold commentedon Mar 6, 2014
While I agree, my new rule is we need timings before discussing any timings. It's a concern, but I don't know how much yet. We're going to be able to remove some checks that are in there already that patsy would also do (more robustly), so the overhead might really be negligible. What's negligible for bootstrap? We decide when we have timings I guess.
A few ways forward that come to mind.
I'm leaning towards 1. Seems simple and straight-forward.
josef-pkt commentedon Mar 6, 2014
I think we just need a simple type check;
if types(exog) is np.arrayor something like that.also what happens if exog is None and we calculate the fittedvalues, which are separately wrapped AFAIR, and should be arrays in _results.
Timing: a simple LOO crossval would do it.
orome commentedon Mar 22, 2014
I encountered this recently and ended up very confused about what was happening. I'm glad to see it's not just me. Including pandas index information in the results from
predict(at least optionally), or preserving length (to match the length ofpredicts argument) would make predict much easier to use.josef-pkt commentedon Jan 11, 2015
I opened a SUMMary issue #2150 and started to look into prediction methods.
I'd like a general solution instead of patching code in various places.
josef-pkt commentedon Jan 12, 2015
see also #2145 as a more general duplicate
jseabold commentedon Jan 14, 2015
Putting this on my radar for 0.7. That's annoying.
josef-pkt commentedon Jan 14, 2015
I started part of pandas handling in my branch for prediction intervals.
I want to remove all data/exog handling from predict and outsource it, which is another issue
We need design decision and helper functions, Kerby has also PRs for prediction.
jseabold commentedon Jan 14, 2015
Ok, we have general wrapping code that I wrote for MixedLM, so it should be simple to just fix this issue without getting too far afield.
saroele commentedon Jan 29, 2015
+1
malcolm415-zz commentedon Jun 4, 2015
+1