Heatmaps with lift
The founder likes the heatmap you've produced for her streaming service. After discussing the project further, however, you decide that that it is important to examine other metrics before making a final decision on which movies to license. In particular, the founder suggests that you select a metric that tells you whether the support values are higher than we would expect given the films' individual support values.
You recall that lift does this well and decide to use it as a metric. You also remember that lift has an important threshold at 1.0 and decide that it is important to replace the colorbar with annotations, so you can determine whether a value is greater than 1.0. Note that the rules from the previous exercise are available to you as rules
.
This exercise is part of the course
Market Basket Analysis in Python
Exercise instructions
- Import
seaborn
under its standard alias. - Transform the
DataFrame
containing rules into a matrix using the lift metric. - Generate a heatmap with annotations on and the colorbar off.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import seaborn under its standard alias
____
# Transform the DataFrame of rules into a matrix using the lift metric
pivot = rules.____(index = 'consequents',
columns = 'antecedents', values= '____')
# Generate a heatmap with annotations on and the colorbar off
sns.heatmap(pivot, annot = ____, ____)
plt.yticks(rotation=0)
plt.xticks(rotation=90)
plt.show()