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.
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?