2
$\begingroup$

I have an imbalanced dataset. I am looking to under-sample. Even though, the oversampling process takes less time, the model training takes a lot of time. I have taken a look at imbalanced-learn website. There are several under sampling methods. I am looking at method that tries to undersample the classes with much as possible information intact. I tried .ClusterCentroids() methods and found it takes way too long to balance the classes.

I have tried other methods that have been mentioned in the website. However, even with sampling_strategy to equal values eg: sampling_strategy={0: 2000, 1: 2000, 2: 2000} The resulting dataset is not balanced. Such as in .CondensedNearestNeighbour() and .AllKNN() methods. Would anyone be able to help me create a class balanced dataset using these methods.

Thanks

Michael

$\endgroup$

1 Answer 1

2
$\begingroup$

If you're looking for a fast workaround to solve this you have to increase n_neighbors parameter in AllKNN, but I wouldn't recommend using this type of undersampling algorithm for what you want to do!


Explanation:

AllKN is an under-sampling technique based on Edited Nearest Neighbors. These techniques try to under-sample your majority classes by removing samples that are close to the minority class, in order to make your classes more separable. The way they work is that they remove samples from the majority class that have at least 1 nearest neighbor in the minority class. The thing is that if the classes are separable enough and the majority samples have no minority nearest neighbors, they can't be removed!

If you want a technique that undersamples your data in order to get exactly the same number of samples from the minority and the majority class, I'd recommend using a different technique (e.g. ClusterCentroids, which you've used is such). ENN-based undersampling techniqes aren't built for that. You can also read this tutorial which compares different resampling algorithms imblearn.

As a final remark, if possible, I'd recommend oversampling...

$\endgroup$
2
  • 1
    $\begingroup$ Hi @Djib2011, Ok thanks for the insightful answer. It helped me a lot $\endgroup$ Apr 19, 2019 at 12:45
  • $\begingroup$ You're welcome! :D $\endgroup$
    – Djib2011
    Apr 19, 2019 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.