Skip to content

Instantly share code, notes, and snippets.

@suhaskv
Created December 23, 2020 11:38
Show Gist options
  • Save suhaskv/879088406058aaed340dc052b28756f7 to your computer and use it in GitHub Desktop.
Save suhaskv/879088406058aaed340dc052b28756f7 to your computer and use it in GitHub Desktop.
VSB Power Line Blog - Get the imbalance ratio in each phase
# Store the imbalance ratio values of each phase
avg_imb = []
for phase in metadata_train['phase'].unique():
num_0 = metadata_train[(metadata_train.phase==(phase)) & (metadata_train.target==0)].shape[0]
num_1 = metadata_train[(metadata_train.phase==(phase)) & (metadata_train.target==1)].shape[0]
imbalance_ratio = num_0/num_1
avg_imb.append(imbalance_ratio)
print(f"Imbalance ratio - phase {phase}: {imbalance_ratio}")
print(f"Average imbalance ratio: {np.round(np.sum(avg_imb)/len(avg_imb), 2)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment