# Best methods to solve class imbalance problem and why?

I have a data set where I need to detect fraud. 99% are not fraud and 1% are.

What methods can be used to solve problems where classes are imbalanced?

• There are a ton of methods and giving a review here would not make sense since you can find review articles easily by googling. If you are working in python I suggest you look at this package. contrib.scikit-learn.org/imbalanced-learn/stable – Keith Nov 20 '17 at 5:56

There are 2 Techniques:

1. Oversampling: There are many techniques under this, ROSE and SMOTE are the most famous techniques used for oversampling. In ROSE it just increases the minority classes. In SMOTE it synthetically generates more number of rare minority classes for balancing. Most of the Scenarios SMOTE gives better results than ROSE but you should try both. Other than that there is just another techniques which just duplicates the records to the make it equal n number. This Link, is for implemenation of SMOTE in Python.

2. UnderSampling: There are many techniques under this too, but this Link-1, Link-2 gives you better idea about undersampling. Generally I don't prefer Undersampling, as you would loose some infomation.

The reason why you need to use these techniques are, if we don't use then the model accuracy will be very high it will be able to predict with 99% accuracy correctly the cases which are not fraud, which we don't want. if it can predict with same accuracy to find out fraud, then that is a great insight. This can be achived only by using either of the above techniques.

Do have a look and Let me know if you have any additional questions.

There are several techniques

Random up-sampling

• Disadvantage->create duplicated and/or artificial instances which may introduce bias and /or noise to the original data

Random Down-Sampling

• Disadvantage -> not all data points are used. Potentially removing useful information. Better choice for data with very high class imbalance.

Repeated Sampling

• in this process, you identify few definite negatives from your data, along with definite positives.Train your model and classify all your sample data based upon this model.
• Repeat this process, and perform voting at the end to get the class labels for highly imbalanced datasets.

You can do following the two approaches.

1. As others mentioned already, you can change the distribution to 50-50 in the training dataset.
2. You can use weighted random forest algorithm for creating a balance between the two classes. In this algorithm, Random Forest itself adds weight to the two classes in order to achieve 50-50 percent weight.
• rf's are sensitive to the imbalancedness.. go for boosting models.. – Aditya May 12 '18 at 18:06

You can use some related parameters as cost function such as Kappa, CEN, and MCEN in all types of algorithms.

Disclaimer:

If you are using Python you can use PyCM module. This module after receiving the confusion matrix of your data can suggest some parameters which is suitable for evaluating your algorithm according to the characteristics of your dataset.

Here is a simple code to get the recommended parameters from this module:

>>> from pycm import *

>>> cm = ConfusionMatrix(matrix={"Class1": {"Class1": 1, "Class2":2}, "Class2": {"Class1": 0, "Class2": 5}})

>>> print(cm.recommended_list)
["Kappa", "SOA1(Landis & Koch)", "SOA2(Fleiss)", "SOA3(Altman)", "SOA4(Cicchetti)", "CEN", "MCEN", "MCC", "J", "Overall J", "Overall MCC", "Overall CEN", "Overall MCEN", "AUC", "AUCI", "G", "DP", "DPI", "GI"]