Skip to content

Instantly share code, notes, and snippets.

@suhaskv
Created December 23, 2020 11:37
Show Gist options
  • Save suhaskv/3204137c23ea9612f476fa3864b9214f to your computer and use it in GitHub Desktop.
Save suhaskv/3204137c23ea9612f476fa3864b9214f to your computer and use it in GitHub Desktop.
VSB Power Line Blog - Get the target distribution phase wise
splot = sns.countplot(x="phase", data=metadata_train, hue="target")
# Get the total number of signals present in each phase
total_phases = metadata_train[metadata_train['phase']==0].shape[0]
num_points = []
# https://github.com/mwaskom/seaborn/issues/1582
for ind, p in enumerate(splot.patches):
# Phase=[0,1,2] for indices [0,1,2] and indices [3,4,5] respectively
phase = ind%3
# target=[0,1] for indices [0,1], [2,3], [4,5] respectively
tar = ind//3
# Store the number of data points for the respective phase and target
num_points.append(metadata_train.loc[(metadata_train['target']==tar) & (metadata_train['phase']==phase)]['phase'].shape[0])
# Get the percentage of the number of data points
num_phase_percent = np.round((num_points[-1]/total_phases)*100, 2)
# Annotate the bar plot
splot.annotate(str(num_points[-1])+f" ({num_phase_percent}%)", (p.get_x(), p.get_height()))
plt.title("Distribution of classes with respect to each phase")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment