Skip to content

Pickle tests - #1669

Closed
FedericoV wants to merge 18 commits into
scikit-learn:masterfrom
FedericoV:pickle_tests
Closed

FedericoV wants to merge 18 commits into
scikit-learn:masterfrom
FedericoV:pickle_tests

Conversation

@FedericoV

Copy link
Copy Markdown
Contributor

I added simple pickle tests for transformers, classifiers, and regressors to check to see whether, after a particular model is trained, it gives the same answer before and after it is pickled and unpickled.

@amueller

Copy link
Copy Markdown
Member

Thanks for the PR :) I'll have a look now.

Comment thread sklearn/tests/test_common.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just use dumps and loads, then you don't need the StringIO.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this currently fails. You imported the class StringIO, not the module, so you can do StringIO() directly here.

@amueller

Copy link
Copy Markdown
Member

hum the test error is caused by a bug in DictionaryLearning. I'm just trying to figure out why that wasn't caught by test_estimators_overwrite_params. OMG horrible bug. I'll fix. Then you can rebase onto master, ok?

@amueller

Copy link
Copy Markdown
Member

Ok so it seems like you need to wait for #1670 to be merged for the tests to run through. Sorry, my fault. Good that you caught it :)

@FedericoV

Copy link
Copy Markdown
Contributor Author

That is ok, I am glad that the test I wrote was already useful somehow. I
have to read up on rebasing though!

On Sunday, February 10, 2013, Andreas Mueller wrote:

Ok so it seems like you need to wait for #1670https://github.com/scikit-learn/scikit-learn/issues/1670to be merged for the tests to run through. Sorry, my fault. Good that you
caught it :)

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1669#issuecomment-13350341..

@amueller

Copy link
Copy Markdown
Member

Once my pr is merged, you go to your master branch, do git pull upstream master (assuming the main github repo is called upstream), then git checkout pickle_tests, git rebase master. And cross fingers that there won't be a conflict ;)

@FedericoV

Copy link
Copy Markdown
Contributor Author

I rebased the changes I made on master. I ran the tests, and got the following errors:

ERROR: Test different base estimators.

Traceback (most recent call last):
File "/home/federicov/epd-python/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/federicov/epd-python/lib/python2.7/site-packages/sklearn/ensemble/tests/test_weight_boosting.py", line 214, in test_base_estimator
clf.fit(X, y)
File "/home/federicov/epd-python/lib/python2.7/site-packages/sklearn/ensemble/weight_boosting.py", line 876, in fit
return super(AdaBoostRegressor, self).fit(X, y, sample_weight)
File "/home/federicov/epd-python/lib/python2.7/site-packages/sklearn/ensemble/weight_boosting.py", line 116, in fit
sample_weight)
File "/home/federicov/epd-python/lib/python2.7/site-packages/sklearn/ensemble/weight_boosting.py", line 929, in _boost
X[bootstrap_idx], y[bootstrap_idx]).predict(X)
File "/home/federicov/epd-python/lib/python2.7/site-packages/sklearn/svm/base.py", line 145, in fit
raise ValueError("The number of classes has to be greater than"
ValueError: The number of classes has to be greater than one.

ERROR: sklearn.tests.test_common.test_configure

Traceback (most recent call last):
File "/home/federicov/epd-python/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/federicov/epd-python/lib/python2.7/site-packages/sklearn/tests/test_common.py", line 656, in test_configure
execfile('setup.py', dict(name='main'))
File "setup.py", line 114, in
raise ValueError('did not find HDF5 headers')
ValueError: did not find HDF5 headers
-------------------- >> begin captured stdout << ---------------------

HDF5_DIR environment variable not set, checking some standard locations ..
checking /home/federicov ...
checking /usr/local ...
checking /sw ...
checking /opt ...
checking /opt/local ...
checking /usr ...

--------------------- >> end captured stdout << ----------------------

FAIL: sklearn.tests.test_common.test_regressors_train

Traceback (most recent call last):
File "/home/federicov/epd-python/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/federicov/epd-python/lib/python2.7/site-packages/sklearn/tests/test_common.py", line 637, in test_regressors_train
assert_true(succeeded)
AssertionError: False is not true
-------------------- >> begin captured stdout << ---------------------
CCA(copy=True, max_iter=500, n_components=2, scale=True, tol=1e-06)
singular matrix

--------------------- >> end captured stdout << ----------------------


Ran 1356 tests in 139.853s

FAILED (SKIP=10, errors=2, failures=1)

@amueller

Copy link
Copy Markdown
Member

Sorry, I probably wasn't very clear. I just merged the fixes. Please rebase again.

@amueller

Copy link
Copy Markdown
Member

Also, there is a list called 'dont_test'. Please don't test the estimators that are in don't test. Also, I guess you can skip CCA and also the PLS related ones for the moment if they give you trouble.

@amueller

Copy link
Copy Markdown
Member

Oh, I just saw your comment was probably after I merged? Sorry, didn't look at the time stamp and didn't expect you to be so fast ;)

@FedericoV

Copy link
Copy Markdown
Contributor Author

No worries. What about the test failures though?

On Mon, Feb 11, 2013 at 5:23 PM, Andreas Mueller
[email protected]:

Oh, I just saw your comment was probably after I merged? Sorry, didn't
look at the time stamp and didn't expect you to be so fast ;)

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1669#issuecomment-13387929..

@amueller

Copy link
Copy Markdown
Member

have you run make in the main folder?

@amueller

Copy link
Copy Markdown
Member

Also could you please push your current branch to github? You need to force push it because of the rebase.

@FedericoV

Copy link
Copy Markdown
Contributor Author

I didn't run make,I ran python setup.py build, then python setup.py install.

I thought I did push the repo to github, if I look at:

https://github.com/FedericoV/scikit-learn/tree/pickle_tests

I see the very last version of the code. Is there something I should be
doing after I rebase?

On Mon, Feb 11, 2013 at 5:52 PM, Andreas Mueller
[email protected]:

Also could you please push your current branch to github? You need to
force push it because of the rebase.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1669#issuecomment-13389596.

@amueller

Copy link
Copy Markdown
Member

oh, never mind, it should be ok.

@amueller

Copy link
Copy Markdown
Member

Below your description of the PR you can see a link for travis that will also tell you the status of the tests btw.

@amueller

Copy link
Copy Markdown
Member

On your branch, I get

======================================================================
ERROR: sklearn.tests.test_common.test_transformers_pickle
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/andy/checkout/scikit-learn/sklearn/tests/test_common.py", line 423, in test_transformers_pickle
    trans.fit(X, y_)
  File "/home/andy/checkout/scikit-learn/sklearn/feature_extraction/dict_vectorizer.py", line 94, in fit
    for f, v in six.iteritems(x):
  File "/home/andy/checkout/scikit-learn/sklearn/externals/six.py", line 268, in iteritems
    return iter(getattr(d, _iteritems)())
AttributeError: 'numpy.ndarray' object has no attribute 'iteritems'

======================================================================
ERROR: sklearn.tests.test_common.test_regressor_pickle
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/andy/checkout/scikit-learn/sklearn/tests/test_common.py", line 771, in test_regressor_pickle
    reg.fit(X, y_)
  File "/home/andy/checkout/scikit-learn/sklearn/isotonic.py", line 175, in fit
    self._check_fit_data(X, y, weight)
  File "/home/andy/checkout/scikit-learn/sklearn/isotonic.py", line 146, in _check_fit_data
    raise ValueError("X should be a vector")
ValueError: X should be a vector

======================================================================
FAIL: sklearn.tests.test_common.test_classifiers_pickle
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/andy/checkout/scikit-learn/sklearn/tests/test_common.py", line 648, in test_classifiers_pickle
    assert_raises(ValueError, clf.fit, X, y[:-1])
AssertionError: ValueError not raised

After rebasing again on current master...

@FedericoV

Copy link
Copy Markdown
Contributor Author

Grr, how did those errors crop up when they weren't there before?

Let me dive into it a bit.

On Mon, Feb 11, 2013 at 7:11 PM, Andreas Mueller
[email protected]:

On your branch, I get

ERROR: sklearn.tests.test_common.test_transformers_pickle

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/andy/checkout/scikit-learn/sklearn/tests/test_common.py", line 423, in test_transformers_pickle
trans.fit(X, y_)
File "/home/andy/checkout/scikit-learn/sklearn/feature_extraction/dict_vectorizer.py", line 94, in fit
for f, v in six.iteritems(x):
File "/home/andy/checkout/scikit-learn/sklearn/externals/six.py", line 268, in iteritems
return iter(getattr(d, _iteritems)())
AttributeError: 'numpy.ndarray' object has no attribute 'iteritems'

ERROR: sklearn.tests.test_common.test_regressor_pickle

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/andy/checkout/scikit-learn/sklearn/tests/test_common.py", line 771, in test_regressor_pickle
reg.fit(X, y_)
File "/home/andy/checkout/scikit-learn/sklearn/isotonic.py", line 175, in fit
self._check_fit_data(X, y, weight)
File "/home/andy/checkout/scikit-learn/sklearn/isotonic.py", line 146, in _check_fit_data
raise ValueError("X should be a vector")
ValueError: X should be a vector

FAIL: sklearn.tests.test_common.test_classifiers_pickle

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/andy/checkout/scikit-learn/sklearn/tests/test_common.py", line 648, in test_classifiers_pickle
assert_raises(ValueError, clf.fit, X, y[:-1])
AssertionError: ValueError not raised

After rebasing again on current master...

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1669#issuecomment-13393738.

@amueller

Copy link
Copy Markdown
Member

The new errors were my fault and cause by the rebasing. I changed the meaning of dont_test. I'm fixing it right now.

@amueller amueller mentioned this pull request Feb 16, 2013
@amueller

Copy link
Copy Markdown
Member

My changes are in #1686.

@amueller

amueller commented Mar 9, 2013

Copy link
Copy Markdown
Member

I merged all the commits that where in the PR, therefore closing. Thanks for your work @FedericoV :)

@amueller amueller closed this Mar 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants