Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only BaselineOnly algo can be dumped #441

Closed
SaschaAtOmina opened this issue Sep 27, 2022 · 2 comments
Closed

Only BaselineOnly algo can be dumped #441

SaschaAtOmina opened this issue Sep 27, 2022 · 2 comments

Comments

@SaschaAtOmina
Copy link

Description

Most algorithms cannot be pickled/dumped (only BaselineOnly can and is actually tested). This is because Cython does not provide trivial pickling.

Steps/Code to Reproduce

In test_dump.py, replace BaselineOnly by KNNBasic for instance.

Expected Results

The test_dump test in test_dump.py should pass when used with others algorithms than BaselineOnly.

Actual Results

========================================================================================================================================================================================================================================== FAILURES ==========================================================================================================================================================================================================================================
_________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ test_dump __________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

u1_ml100k = <surprise.dataset.DatasetUserFolds object at 0x10583f250>

    def test_dump(u1_ml100k):
        """Train an algorithm, compute its predictions then dump them.
        Ensure that the predictions that are loaded back are the correct ones, and
        that the predictions of the dumped algorithm are also equal to the other
        ones."""
    
        random.seed(0)
    
        trainset, testset = next(PredefinedKFold().split(u1_ml100k))
    
        algo = KNNBasic()
        algo.fit(trainset)
        predictions = algo.test(testset)
    
        with tempfile.NamedTemporaryFile() as tmp_file:
>           dump.dump(tmp_file.name, predictions, algo)

tests/test_dump.py:26: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
venv/lib/python3.9/site-packages/scikit_surprise-1.1.2-py3.9-macosx-10.9-universal2.egg/surprise/dump.py:28: in dump
    pickle.dump(dump_obj, open(file_name, "wb"), protocol=pickle.HIGHEST_PROTOCOL)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   TypeError: no default __reduce__ due to non-trivial __cinit__

Versions

macOS-12.5-arm64-arm-64bit

Python 3.9.13 (v3.9.13:6de2ca5339, May 17 2022, 11:37:23)
[Clang 13.0.0 (clang-1300.0.29.30)]

surprise 1.1.2

@NicolasHug
Copy link
Owner

I released 1.1.3 this weekend with a bugfix. Please feel free to reopen an issue if you still have problems with 1.1.3.

@SaschaAtOmina
Copy link
Author

I released 1.1.3 this weekend with a bugfix. Please feel free to reopen an issue if you still have problems with 1.1.3.

Thank you, I did it differently in a PR where I translate typed memory views to numpy arrays back and forth, but it's too late I assume :-)

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

No branches or pull requests

2 participants