Computational-Psychiatry / 3DI

5 stars 2 forks source link

relying on a very specific version of scikit-learn #11

Closed birkantunc closed 6 months ago

birkantunc commented 8 months ago

With the estimation of localized expressions coefficients (_compute_local_expcoefficients.py), a .npy file that was created using scikit-learn==1.1.3, is loaded. When the install scikit-learn version is different we get the following warning.

InconsistentVersionWarning: Trying to unpickle estimator DictionaryLearning from version 1.1.3 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations
sariyanidi commented 8 months ago

I'm not sure what to do about this. It will always be specific to a version I guess. Any ideas @birkantunc ?

birkantunc commented 7 months ago

here is another problem related to this one and a possible solution: Issue: After loading the learned dictionary using np.load()

basis_set = np.load(localized_basis_file, allow_pickle=True).item()
dictionary = basis_set[feat]

you cannot set any parameters, for example, to increase the number of iterations for transform() dictionary.set_params(transform_max_iter=2000) This gives the following error: AttributeError: 'DictionaryLearning' object has no attribute 'callback' After further investigation, I realized the loaded object was not an instance of the class sklearn.decomposition.DictionaryLearning but instead sklearn.decomposition._dict_learning.DictionaryLearning That is, there might be an issue with serialization. Possible Solution: How about instead of dumping the object into disk, dumping all relevant attributes (coefficients, etc.) and then after loading them from the disk, you can create a new sklearn.decomposition.DictionaryLearning object and set all the attributes back?

sariyanidi commented 6 months ago

We can access the basis matrix with basis_set[feat].components_ even when we get the callback error when we try to access basis_set[feat]. For now we'll leave this here, hoping that this version compatibility won't lead to severe errors. In the future we'll likely implement the sparse dictionary learning ourselves, otherwise we may always have version-related issues.