scikit-learn-intelex icon indicating copy to clipboard operation
scikit-learn-intelex copied to clipboard

SVM models trained with sparse matrix cannot be serialized (pickled)

Open yappyjp opened this issue 3 years ago • 3 comments
trafficstars

Describe the bug SVC model trained with a scipy sparse matrix cannot be serialized (pickled).

To Reproduce

#!/usr/bin/env python

import sklearn.svm
from sklearn import datasets
import scipy.sparse
import pickle

X, y = datasets.load_iris(return_X_y=True)

## with numpy array
clf = sklearn.svm.SVC()
clf.fit(X, y)

## OK. no problem
s = pickle.dumps(clf)

## with Sparse matrix
X = scipy.sparse.csr_matrix(X)
clf = sklearn.svm.SVC()
clf.fit(X, y)

# Error 
s = pickle.dumps(clf)
Traceback (most recent call last):
  File "**.py", line 24, in <module>
    s = pickle.dumps(clf)
ValueError: Object is not serializable

Environment:

  • Intel distribution for Python 2022.2.0 (installed via dnf).

yappyjp avatar May 16 '22 06:05 yappyjp

Hi @yappyjp Thanks for pointing out this issue. I'll check what could be the cause and get back as soon as I can

PivovarA avatar May 23 '22 09:05 PivovarA

It appears that internal oneDAL model with sparse data usage is the reason. Trying to serialize clf._onedal_estimator._onedal_model will fail with same error.

Alexsandruss avatar Jul 29 '22 12:07 Alexsandruss

Same error without https://github.com/oneapi-src/oneDAL/pull/2122 fix will appear for any patched SVM model - NuSVC/NuSVR/SVC/SVR.

Alexsandruss avatar Aug 11 '22 09:08 Alexsandruss

Hi! Is there any update on this one? I saw the PR is approved but not merged yet?

doganMemory avatar Sep 29 '22 08:09 doganMemory

Hi @doganMemory, PR is waiting for additional approval and check

Alexsandruss avatar Sep 29 '22 09:09 Alexsandruss

@Alexsandruss The above PR is merged it seems. When can it be merged into the intelex package?

arijit-s avatar Dec 28 '22 17:12 arijit-s

@arijit-s - this have been released already - you can look for latest package on pypi/conda

napetrov avatar Dec 28 '22 17:12 napetrov