wrapper (sub)classes

18 views
Skip to first unread message

josef...@gmail.com

unread,
Oct 4, 2012, 12:42:49 PM10/4/12
to pystatsmodels
Quick question before I did into it (in vain)

There was a comment initially by Skipper or Wes that the wrappers
don't work with subclasses.
Does the following look like a case that needs a separate wrapper
class, even though it will be empty?

>>> poisson_l1_res.cov_params()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-all-new\statsmodels\statsmodels\base\wrapper.py",
line 89, in wrapper
return data.wrap_output(func(results, *args, **kwargs), how)
TypeError: unbound method cov_params() must be called with
CountResults instance as first argument (got L1CountResults instance
instead)

Currently an error in the L1 regularization branch. we return
L1CountResults instead of CountResults inside the wrapper

>>> poisson_l1_res.__class__
<class 'statsmodels.discrete.discrete_model.CountResultsWrapper'>
>>> poisson_l1_res._results.__class__
<class 'statsmodels.discrete.discrete_model.L1CountResults'>


class CountResultsWrapper(lm.RegressionResultsWrapper):
pass
wrap.populate_wrapper(CountResultsWrapper, CountResults)

looks like we cannot cheat

Josef

Skipper Seabold

unread,
Oct 4, 2012, 12:51:30 PM10/4/12
to pystat...@googlegroups.com

Can you post a link to the code?

Skipper

josef...@gmail.com

unread,
Oct 4, 2012, 1:03:18 PM10/4/12
to pystat...@googlegroups.com
fit_regularized
https://github.com/josef-pkt/statsmodels/blob/langmore_l1regularized_rebased_2/statsmodels/discrete/discrete_model.py#L671

L1 results class
https://github.com/josef-pkt/statsmodels/blob/langmore_l1regularized_rebased_2/statsmodels/discrete/discrete_model.py#L2107

example is in examples_discrete.py

I don't understand the inheritance structure with the wrappers yet,
but I could just copy the pattern of the existing wrapped results.

Josef

>
> Skipper
>

Skipper Seabold

unread,
Oct 4, 2012, 1:10:09 PM10/4/12
to pystat...@googlegroups.com

Ah, ok. I didn't see the CountModel.fit_regularized in the other l1 rebased branch. Yeah, you'll need to define an empty wrapper here and use it since CountResultsWrapper wraps CountResults. If you need to wrap any other results, you'll need to define them. It's a bit more work but it's not so bad. There may be a way to code it for sub-classes using __base__.

Note that the doc copied over for fit_regularized is not the right one.

josef...@gmail.com

unread,
Oct 4, 2012, 1:19:46 PM10/4/12
to pystat...@googlegroups.com
Thanks,

two lines of boilerplate is faster than to continue staring at the
wrapper code that creates the exception.

Josef

josef...@gmail.com

unread,
Oct 4, 2012, 2:26:40 PM10/4/12
to pystat...@googlegroups.com
There is still something strange

I had the failure with poisson in the interpreter, but the tests had
passed before.
Now it still works with

>>> logit_res3.__class__
<class 'statsmodels.discrete.discrete_model.BinaryResultsWrapper'>
>>> logit_res3._results.__class__
<class 'statsmodels.discrete.discrete_model.L1BinaryResults'>

>>> logit_res3.cov_params()
GPA TUCE PSI const
GPA NaN NaN NaN NaN
TUCE NaN 0.012548 NaN -0.284208
PSI NaN NaN NaN NaN
const NaN -0.284208 NaN 6.584961

------
I do have
class BinaryResultsWrapper(lm.RegressionResultsWrapper):
pass
wrap.populate_wrapper(BinaryResultsWrapper, BinaryResults)

class L1BinaryResultsWrapper(lm.RegressionResultsWrapper):
pass
wrap.populate_wrapper(L1BinaryResultsWrapper, L1BinaryResults)

but fit_regularized still returns a BinaryResultsWrapper not yet the
L1BinaryResultsWrapper


magic, but for another day.

Josef

Skipper Seabold

unread,
Oct 4, 2012, 5:18:51 PM10/4/12
to pystat...@googlegroups.com
Something funny going on there then. Don't know that it has to do with the wrappers. Just noticed that we use one wrapper for OLSResults and RegressionResults in linear_model.

Skipper
Reply all
Reply to author
Forward
0 new messages