Visualizing metrics
1. Visualizing metrics
Let's now create some visualizations for the different metrics used in Market Basket Analysis.2. Interactive table with metrics
Back to the Grocery store. Remember that we used the "arules" package to call the "apriori" function. The "inspect" function allowed us to either retrieve the frequent itemsets or the set of extracted rules. We often mentioned that one of the challenge of Market Basket Analysis is to deal with the potentially large number of extracted rules. The package "arulesViz" enables us in particular to create an HTML based table of all extracted rules. This is very convenient as rules can be interactively filtered and sorted. The "InspectDT" function generates an HTML widget which allows to play interactively with the set of extracted rules.3. Scatter plots introduction
For the example of the grocery store, if we inspect the rules, we get the 6 following extracted rules. Is it possible to get a visualization of these rules? Yes, it is possible! A straight-forward visualization of association rules is to use a scatterplot using the "plot" function of the "arulesViz" package. The plot shows "Support" and "Confidence" on the x and y axis respectively. One point on the plot represents exactly one rule. The lift associated to the rule is used by default as color coding.4. Flexible arules plots
However, the "plot" function of the arulesViz package has much more flexibility. There are four main arguments to the function. The "rulesObject" is the object you created using the apriori function (this could be the set of all rules or a subset of rules). The "measure" argument controls the metrics that are plotted whereas the "shading" argument controls the color coding of the plot. Finally and most importantly, you can choose the type of plot you want with the "method" argument; by default, it is a scatterplot but as we will see later, many other plots can be produced. In the example shown here, we use the standard scatterplot and plot the confidence and lift on the x and y axis respectively; the support is used as color coding.5. Other arules plots
So, which other plots can be created? First of all, let's create a so-called "two-key plot". The two-key plot uses support and confidence on x and y-axis respectively. It uses "order" for coloring. The order, which you can see in the legend of the plot represents the number of items included in the rule. For instance, the rule "Bread implies Butter" is of order 2 as it includes 2 items. All rules displayed on the plot are of order 2.6. Jittering your plots
As the number of rules may be large, plots can become difficult to read. This is why you should consider in some cases the option of "jittering" on your plot. For instance, on the "two-key plot" on the left, you may think that there are only 5 rules. However, when jittering points, we notice there are 6 rules. Jittering allows you to know where the density of points on your plot really is.7. Interactive arules plots
Having hundreds or thousand of points on a plot may be cumbersome to read. Having an interactive version of the plot would be cool, wouldn't it? An amazing interactive plot can be used to present your rules - it uses the packages "arulesViz" and "plotly". You can hover over each rule and view all quality measures (support, confidence and lift). You can as well select specific points on the plot, zoom in and zoom out. On the right hand side, you have a screenshot of how it looks like. If we hover on one of the rules, we see the rule "Bread implies Butter".8. Let's visualize metrics!
Now, it's your turn to visualize the different metrics for the Online Retail dataset.Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.