Get startedGet started for free

From rules to graph based visualizations

1. From rules to graph based visualizations

From the set of thousands of rules, how can we visualize rules effectively and efficiently? We would need an easy and intuitive way to visualize and understand rules. This can be achieved with graphs. So, how do we visualize extracted rules using graphs?

2. Visualizing rules

We can use again the "plot" function with graph as a method. By adding the "engine" as "htmlwidget", we will bring rules to life! Graph-based techniques visualize association rules using vertices and edges where vertices are labeled with item names, and item sets or rules are represented as a second set of vertices. Items are connected with item-sets/rules using directed arrows. Arrows pointing from items to rule vertices indicate LHS items and an arrow from a rule to an item indicates the RHS. The size and color of vertices represent interest measures such as "lift" and "support". In this example, rule 1 has a high lift but a lower support compared to rules 5 and 6. By hovering a rule or an item, more information is displayed. Finally, you may want to save the graph you just produced such that it can be reused at a later stage. Calling the "saveWidget" function from "htmlwidgets" package does the trick. Just add the object you just created and a file name.

3. Selecting items and rules from the graph

The dropdown menu in the top left corner of the graph allows you to select either a rule or an item. By selecting for instance "Bread", the item "Bread" and all associated rules are highlighted on the graph. Likewise, by selecting rule 3, this rule is highlighted as well as all associated items. This way of filtering items and rules can be useful, especially when the number of rules is very large.

4. Graphs and subgraphs (1)

Graphs are a great way to visualize rules but tend to become congested as the number of rules increases. So it is better to visualize less number of rules with graph-based visualizations. For instance, we previously saw how to sort rules according to a specific metric and keep only the first few records. In this case, let's sort rules by confidence and consider only the first 4 rules. Plotting the graph with the engine as "htmlwidget" yields the following graph. Have you noticed that colors and sizes of vertices are adjusted depending on the set of rules?

5. Graphs and subgraphs (2)

Remember that we previously extracted rules that contained "Cheese" on the right hand side. Similar to before, we can visualize these two rules using a graph. As a good practice, remember that you should rather only plot the rules or subset of rules that are of interest to you.

6. Save as Graph

Association rules can be exported in the "GraphML" format or as a "Graphviz dot-file". These can be further processed with tools like "Gephi", which is a visualization and exploration software for all kinds of graphs and networks. GraphML is an XML-based file format for graphs. The GraphML file format uses the ".graphml" extension and is XML structured. It supports attributes for nodes and edges, hierarchical graphs and benefits from a flexible architecture. In R, use the function "saveAsGraph" with the rule object as first input and the file name as second input.

7. Let's rule!

Let's visualize as graphs the rules you extracted from the Online Retail dataset.