Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@liannewriting
Created October 13, 2021 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liannewriting/8292d07b7cb853824d09496097b0acb9 to your computer and use it in GitHub Desktop.
Save liannewriting/8292d07b7cb853824d09496097b0acb9 to your computer and use it in GitHub Desktop.
python imbalanced data machine learning classification
msk = df_train['Class'] == 1
num_to_oversample = len(df_train) - 2*msk.sum()
df_positive_oversample = df_train[msk].sample(n=num_to_oversample, replace=True, random_state=888)
df_train_oversample = pd.concat([df_train, df_positive_oversample])
df_train_oversample['Class'].value_counts()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment