Pandas Undersampling for Imbalanced Binary Classification
An example of how to handle imbalanced data in Python. This is based on the titanic dataset. Here we split the main dataframe into separate survived and deceased dataframe. The deceased dataframe is the larger dataframe so we sample the same number of rows from this dataframe as there are in the survived dataframe to make them the same size. We then concat both data frames back together to create a dataframe that is balanced.