Skip to content

Instantly share code, notes, and snippets.

@a-agmon
Created September 6, 2020 06:01
Show Gist options
  • Save a-agmon/22a7f1d58e9259b527023d8ac4bd4046 to your computer and use it in GitHub Desktop.
Save a-agmon/22a7f1d58e9259b527023d8ac4bd4046 to your computer and use it in GitHub Desktop.
# assign each vector the cluster withwhich it is most associated
df_avg['cluster'] = np.argmax(lda.transform(df_avg), axis=1)
#chart the different clusters
fig, axs = plt.subplots(3, 1, sharex=True, sharey=True)
df_avg.iloc[:,:-1].loc[df_avg.cluster == 0].mean().plot.bar(ax=axs[0])
axs[0].set_title('Category - 0 (Evening/Night)')
df_avg.iloc[:,:-1].loc[df_avg.cluster == 1].mean().plot.bar(ax=axs[1])
axs[1].set_title('Category - 1 (Normal Day)')
df_avg.iloc[:,:-1].loc[df_avg.cluster == 2].mean().plot.bar(ax=axs[2])
axs[2].set_title('Category - 2 (Late Night/Early Morning)')
for ax in axs.flat:
ax.set(xlabel='hours', ylabel='views')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment