Exercise

NMF segmentation averages

Finally, you will visually explore the average values of the 3-segment solution built by NMF and can compare it to the K-means one. Here you will extract the features matrix W which we will use to extract the hard segment assignment by choosing the column value (segment) with highest associated value in this matrix for each customer.

We have loaded pandas library as pd and seaborn library as sns. The raw wholesale dataset has been imported, and the already fitted 3-segment NMF instance as nmf. The components dataset has been loaded as pandas DataFrame.

Instructions

100 XP
  • Create the W matrix by passing the transformed values as data, and components index as column values.
  • Assign the segment value by selecting the column name where the corresponding value is the largest.
  • Calculate the average column values per each segment.
  • Plot the average values as a heatmap.