title: Process for oversampling data for imbalanced binary classification
body: <p>I have about a 30% and 70% for class 0 (minority class) and class 1 (majority class). Since I do not have a lot of data, I am planning to oversample the minority class to balance out the classes to become a 50-50 split. I was wondering if oversampling should be done before or after splitting my data into train and test sets. I have generally seen it done before splitting in online examples, like this:</p>
  
  <pre><code>df_class0 = train[train.predict_var == 0]
  df_class1 = train[train.predict_var == 1]
  df_class1_over = df_class1.sample(len(df_class0), replace=True)
  df_over = pd.concat([df_class0, df_class1_over], axis=0)
  </code></pre>
  
  <p>However, wouldn't that mean that the test data will likely have duplicated samples from the training set (because we have oversampled the training set)? This means that testing performance wouldn't necessarily be on new, unseen data. I am fine doing this, but I would like to know what is considered good practice. Thank you!</p>