You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SVM dual_coef_ is forcefully set as sparse but would never have zeros #35600
This issue is not yet ready for a PR. If you are interested in contributing to scikit-learn, please have a look at our contributing guidelines, and in particular the sections for new contributors and the "Needs triage" label.
Introduce yourself
No response
Describe the bug and give evidence about its user-facing impact
In SVM classes, when the input is sparse, the support vectors (attribute support_vectors_) will also be sparse, since they are taken from the same data.
These support vectors have an associated coefficient in the dual problem formulation, kept in attribute dual_coef_. By definition, a support vector would have to be a point with an impact in the decision function, hence entries in dual_coef_ should be non-zeros, or otherwise the point would not be a support vector.
The underlying LibSVM that scikit-learn uses produces dual_coef_ as a dense array, but scikit-learn will forcefully cast that into a sparse format when the support vectors are sparse and then extract the .data attribute when passing that data to LibSVM, which doesn't sound logical.
There was some discussion around this topic when the code was first introduced: #576 (comment)
But it was never addressed in that or the follow-up PRs.
Hi, is this issue still free? I would like to work on it if so. My read is the fix is to stop forcing dual_coef_ into a sparse format when the support vectors are sparse and keep it as the dense array LibSVM returns, then add a small test with a sparse input to check the type. Please let me know if that direction sounds right.
Activity
Duke2nuke commentedon Dec 2, 2026
Hi, is this issue still free? I would like to work on it if so. My read is the fix is to stop forcing dual_coef_ into a sparse format when the support vectors are sparse and keep it as the dense array LibSVM returns, then add a small test with a sparse input to check the type. Please let me know if that direction sounds right.