Handling imbalanced data by deleting over represented rows vs. adding under represented rows I am currently working with a very imbalanced data set
(frauded credit card data from kaggle, which has 492 rows of frauded cards and over 280,000 rows of non-frauded cards).

As much as I know, there are 2 ways to handle imbalanced data without adjusting penalty:


over-sampling the under-represented data - by creating a lot of copies of the frauded data
under-sampling the over-represented data - by not using a lot of the non-frauded data


Right now I go with under-sampling (since my computer is not that strong and I do not want to waste hours for answers).

Technically what I do, is create a 50-50 dataframe, which has all of the under-represented rows and randomly selected over-represented rows.

Problem is, every time I run the notebook, the algorithms use different random okay data and there are different results. When tweaking xgboost, there are different optimal parameters every time I run the notebook.

What should I do? Should I save as csv one of the balanced df I created and call it a day? Should I creat a lot of copies from the frauded cards? What is the best way to tackle the situation?
Technically what I do, is create a 50-50 dataframe, which has all of the under-represented rows and randomly selected over-represented rows.


You could use a random seed for the selection from the non-frauded cards dataset so that every time it selects the same rows. This way you are able to track and compare the results.

import numpy as np
from numpy import random

arr = np.arange(5)  # [0, 1, 2, 3, 4]
random.seed(1)  # Reset random state
random.shuffle(arr)  # Shuffle!
print(arr)


Just an example on how to use random seed from numpy, you'll have to come up with your own way to use it for your need (suggestion: create arr in range(0, len(frauded_card)) and shuffle it, then use arr as indexes for the frauded_card sample to use)