yngvem/group-lasso

Saving LogisticGroupLasso models?

Closed this issue · 4 comments

Saving (pickle.dump) LogisticGroupLasso fitted model not possible:

_pickle.PicklingError: Can't pickle <function LogisticGroupLasso._unregularised_loss at 0x1a22114048>: it's not the same object as group_lasso._group_lasso.LogisticGroupLasso._unregularised_loss

If this is rather a pickle issue, and not from this package, please ignore. However, would be nice to know how to save it then :)

The problem very likely is related to this issue:

The most common reason for seeing that error is that the object (builtin.raw_input in this case) is not actually defined at that namespace and has been aliased there by some means. It's a very common pickling error, as object aliasing is done a lot. This is one of the reasons that python 3 introduced the qualname attribute. Source

Here, the problem is with _unregularised_loss, an abstract method... Apparently, fiddling around with imports often solves the problem. I didn't succeed to do this myself, however.

Note that the problem would be fixed if LogisticGroupLasso was a valid sklearn-estimator. Currently, the group-lasso objects fail the estimator checks.

@yngvem This is maybe a good occasion to remind you of pull request #16 :) It still needs some more fixes, I know! But the LogisticGroupLasso() object in that branch is serializable with pickle. I just tested it.

Ok, I've narrowed down the problem, it was caused by me storing the FISTAProblem instance in the BaseGroupLasso instance. This made it all unpicklable (probably because of how I deal with subsampling through some higher-order functions). Storing this instance was only useful for debugging purposes, so I'll likely push a new version where it isn't stored soon :)

This should be fixed now, and the latest version is on PyPI.