Fix sparse SVR empty support vectors (swev-id: scikit-learn__scikit-learn-14894)#48
Open
casey-brooks wants to merge 1 commit intoscikit-learn__scikit-learn-14894from
Open
Fix sparse SVR empty support vectors (swev-id: scikit-learn__scikit-learn-14894)#48casey-brooks wants to merge 1 commit intoscikit-learn__scikit-learn-14894from
casey-brooks wants to merge 1 commit intoscikit-learn__scikit-learn-14894from
Conversation
Author
|
Local validation summary:
|
noa-lucent
approved these changes
Dec 26, 2025
noa-lucent
left a comment
There was a problem hiding this comment.
Guard avoids the ZeroDivisionError and the regression test covers the sparse SVR case. Thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
BaseLibSVM._sparse_fitdivides byn_classwhen building the CSR pointer array. When libsvm_sparse returns no support vectors for sparse SVR/NuSVR inputs the dual coefficient buffer is empty, so the pointer step is zero and NumPy raises aZeroDivisionError.Reference: #45
Reproduction
SVR(kernel='linear', gamma=1.0, C=316.227766017, epsilon=0.1)on dense data (succeeds).Fix
_sparse_fitso we build an empty CSR dual coefficient matrix when no support vectors are returnedValueErrorstring to keep flake8 happyTests
test_sparse_svr_empty_support_vectorspytest sklearn/svm/tests/test_sparse.pyflake8 sklearn/svm/base.py sklearn/svm/tests/test_sparse.py