Skip to content

Discrete models fit_regularized save pickle fails #2685

Closed

Description

@kashif

saving a fit_regularized causes pickle to fail:

class TestRemoveDataPicklePoissonRegularized(RemoveDataPickle):

    def setup(self):
        #fit for each test, because results will be changed by test
        x = self.exog
        np.random.seed(987689)
        y_count = np.random.poisson(np.exp(x.sum(1) - x.mean()))
        model = sm.Poisson(y_count, x)  #, exposure=np.ones(nobs), offset=np.zeros(nobs)) #bug with default
        self.results = model.fit_regularized(method='l1', disp=0, alpha=10)


        #TODO: temporary, fixed in master
        self.predict_kwds = dict(exposure=1, offset=0)

gives:

Traceback (most recent call last):
  File "statsmodels/base/tests/test_shrink_pickle.py", line 290, in <module>
    tt.test_remove_data_pickle()
  File "statsmodels/base/tests/test_shrink_pickle.py", line 68, in test_remove_data_pickle
    res, l = check_pickle(results._results)
  File "statsmodels/base/tests/test_shrink_pickle.py", line 27, in check_pickle
    cPickle.dump(obj, fh, protocol=cPickle.HIGHEST_PROTOCOL)
cPickle.PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed

Activity

  1. changed the title [-]Discrete models fit_regularized save fails[/-] [+]Discrete models fit_regularized save pickle fails[/+] on Oct 30, 2015
  2. josef-pkt commented on Oct 30, 2015

    @josef-pkt
    Member

    @kashif Thanks for the report

    To clarify: Is TestRemoveDataPicklePoissonRegularized a unit test that you wrote?

    I don't see unit test for it, but I don't get this with master.
    (I have my statsmodels build messed up right now and could only test and adjusted version, not the unit tests.)

  3. kashif commented on Oct 30, 2015

    @kashif
    Author

    @josef-pkt yes its something i wrote locally, happy to send that as a pull request?

  4. kashif commented on Oct 30, 2015

    @kashif
    Author

    @josef-pkt the same issue occurs with other discrete models too not just Poisson

  5. josef-pkt commented on Oct 30, 2015

    @josef-pkt
    Member

    I don't find any record of recent changes that might have affected this.

    Can you test with master?

    I need to clean up my statsmodels build for testing or developement, and can add a unit test like this later.

    (just got your new comments)
    Yes please open a PR with this test case and we get TravisCI to check across python versions and dependency versions.

    most of the fit_regularized code is shared by all discrete models and will affect them the same way

  6. kashif commented on Oct 30, 2015

    @kashif
    Author

    yes I tested with master.

    ok sending pull request now...

  7. added this to the 0.8 milestone on Oct 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions