Skip to content

Instantly share code, notes, and snippets.

@suhaskv
Created December 23, 2020 11:35
Show Gist options
  • Save suhaskv/fec0977939c71c9af504f799ae602168 to your computer and use it in GitHub Desktop.
Save suhaskv/fec0977939c71c9af504f799ae602168 to your computer and use it in GitHub Desktop.
VSB Power Line Blog - Get the distribution of the target data
splot = sns.countplot(x='target', data=metadata_train)
# https://github.com/mwaskom/seaborn/issues/1582
for ind, p in enumerate(splot.patches):
percent = np.round((metadata_train[metadata_train['target']==ind].shape[0]/metadata_train['target'].shape[0])*100, 2)
splot.annotate(str(metadata_train[metadata_train['target']==ind].shape[0]) + f" ({percent}%)",
(p.get_x()+p.get_width()/2, p.get_height()))
plt.title("Distribution of target classes")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment