- Notifications
You must be signed in to change notification settings - Fork1.3k
Fix: Found array with 0 sample(s)#743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Symptom: When using SVMSMOTE on dataset which contains a minority class which has very few samples (may be < 10), it'll raise error `ValueError: Found array with 0 sample(s) (shape=(0, 600)) while a minimum of 1 is required.`Root cause:The line `noise_bool = self._in_danger_noise(...)` will find noise data according to `kneighbors` estimator's `n_neighbors` attribute, this value is equal to `m_neighbors` attribute of `SVMSMOTE` class. If we set a very large number to `m_neighbors` to initialize `SVMSMOTE`, for example: `SVMSMOTE(m_neighbors=1000)`, this error will be gone. This is because the range of neighbor searches is large enough to contain another minority class data point, therefore the center data point will not be treated as noise according to this line `n_maj == nn_estimator.n_neighbors - 1`. But when `m_neighbors` is small (default is 10), and the minority class has very few sample, it may treat whole minority class data as noise data, cause returned `noise_bool` with all true, then in _safe_indexing(...) will remove all these data, resulted in zero number of support_vector data.Solution: Save `support vector` before trimming noise data point. When after trimmed noise data, check whether the length of support vector is zero, if true, then restore previous saved `support vector`, this enforce every minority data point used as `support_vector`.
pep8speaks commentedAug 11, 2020
Hello@allenyllee! Thanks for opening this PR. We checked the lines you've touched forPEP 8 issues, and found:
|
You will need to correct the PEP8 issue. I think that we should raise a warning as well because we are not strictly performing the algorithm which is expected (but we are in a corner case). |
We will need a non-regression test (that you posted in the issue) and an entry in what's new as well since it would impact the end-user |
Symptom:
When using SVMSMOTE on dataset which contains a minority class which has very few samples (may be < 10), it'll raise error
ValueError: Found array with 0 sample(s) (shape=(0, 600)) while a minimum of 1 is required.
Reference Issue
#742
What does this implement/fix? Explain your changes.
Root cause:
The line
noise_bool = self._in_danger_noise(...)
will find noise data according tokneighbors
estimator'sn_neighbors
attribute, this value is equal tom_neighbors
attribute ofSVMSMOTE
class. If we set a very large number tom_neighbors
to initializeSVMSMOTE
, for example:SVMSMOTE(m_neighbors=1000)
, this error will be gone. This is because the range of neighbor searches is large enough to contain another minority class data point, therefore the center data point will not be treated as noise according to this linen_maj == nn_estimator.n_neighbors - 1
. But whenm_neighbors
is small (default is 10), and the minority class has very few sample, it may treat whole minority class data as noise data, cause returnednoise_bool
with all true, then in _safe_indexing(...) will remove all these data, resulted in zero number of support_vector data.Solution:
Save
support vector
before trimming noise data point. When after trimmed noise data, check whether the length of support vector is zero, if true, then restore previous savedsupport vector
, this enforce every minority data point used assupport_vector
.Any other comments?