From 32c4f8169686240ca5c9eb7e523a8836045a0121 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Mon, 14 Jun 2021 16:39:18 -0500 Subject: [PATCH 01/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index fa23c44..6fc5ed8 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -2,7 +2,7 @@ import networkx as nx import numpy as np -from PyARMViz import Rule +from PyARMViz.Rule import Rule from typing import List import itertools @@ -436,4 +436,4 @@ def adjacency_scatter_plot(rules:List[Rule], notebook_flag:bool = False): )) fig.show() - return fig \ No newline at end of file + return fig From 9d443329f734ed45302a6fde9183773db0d359db Mon Sep 17 00:00:00 2001 From: nachigonz Date: Mon, 14 Jun 2021 16:50:26 -0500 Subject: [PATCH 02/17] Update __init__.py --- PyARMViz/datasets/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PyARMViz/datasets/__init__.py b/PyARMViz/datasets/__init__.py index 20ad8cf..3253a00 100644 --- a/PyARMViz/datasets/__init__.py +++ b/PyARMViz/datasets/__init__.py @@ -13,7 +13,7 @@ import pandas as pd from os.path import dirname, exists, expanduser, isdir, join, splitext -from bokeh.layouts import row +#from bokeh.layouts import row from PyARMViz.Rule import Rule, generate_rule_from_dict import json @@ -50,4 +50,4 @@ def load_shopping_rules() -> List[Rule]: shopping_rule_data_uri = join(module_path, 'Online_Retail_Rules.json') rule_dicts = json.load(open(shopping_rule_data_uri, 'r')) rules = list(map(lambda rule_dict: generate_rule_from_dict(rule_dict), rule_dicts)) - return rules \ No newline at end of file + return rules From 39239044b14b2dc5eaf0e4ed170cde0011a08873 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Mon, 14 Jun 2021 16:55:15 -0500 Subject: [PATCH 03/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index 6fc5ed8..91ddc6e 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -358,11 +358,6 @@ def adjacency_graph_plotly(rules:Rule): showlegend=False, hovermode='closest', margin=dict(b=20,l=5,r=5,t=40), - annotations=[ dict( - text="Python code: https://plotly.com/ipython-notebooks/network-graphs/", - showarrow=False, - xref="paper", yref="paper", - x=0.005, y=-0.002 ) ], xaxis=dict(showgrid=False, zeroline=False, showticklabels=False), yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)) ) From 1142360f48f35d233358bd33e41c53a6f6eed69c Mon Sep 17 00:00:00 2001 From: nachigonz Date: Mon, 14 Jun 2021 17:33:08 -0500 Subject: [PATCH 04/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index 91ddc6e..1931176 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -292,6 +292,22 @@ def _parallel_category_builder(rules:List, axis_count:int): return axis_objects +def is_number(s): + try: + float(s) + return True + except ValueError: + pass + + try: + import unicodedata + unicodedata.numeric(s) + return True + except (TypeError, ValueError): + pass + +return False + def adjacency_graph_plotly(rules:Rule): ''' This is the plotly version of the @@ -323,10 +339,11 @@ def adjacency_graph_plotly(rules:Rule): node_x = [] node_y = [] for node in graph.nodes(): - x, y = pos[node] - node_x.append(x) - node_y.append(y) - node_text.append(node) + if (not is_number(node)): ##Right Here Buddy ----------------- + x, y = pos[node] + node_x.append(x) + node_y.append(y) + node_text.append(node) node_trace = go.Scatter( From c11a2f20e4c10a0450bad5c58165127e5d336879 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Mon, 14 Jun 2021 17:36:03 -0500 Subject: [PATCH 05/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index 1931176..9bba726 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -306,7 +306,7 @@ def is_number(s): except (TypeError, ValueError): pass -return False + return False def adjacency_graph_plotly(rules:Rule): ''' From aa943811534092bce6de2dd511b96df4dd0e4fb9 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Mon, 14 Jun 2021 18:00:55 -0500 Subject: [PATCH 06/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index 9bba726..79da6a5 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -339,11 +339,10 @@ def adjacency_graph_plotly(rules:Rule): node_x = [] node_y = [] for node in graph.nodes(): - if (not is_number(node)): ##Right Here Buddy ----------------- - x, y = pos[node] - node_x.append(x) - node_y.append(y) - node_text.append(node) + x, y = pos[node] + node_x.append(x) + node_y.append(y) + node_text.append(node) node_trace = go.Scatter( @@ -403,15 +402,20 @@ def _adjacency_graph_generator(rules:List[Rule]): ''' graph = nx.DiGraph() for index, rule in enumerate(rules): - graph.add_node (index, Weight=int(rule.confidence*10), type="Association_Rule") - - for entity in rule.lhs: - graph.add_node(entity, Weight=1, type="Entity") - graph.add_edge(entity, index, Normalized_Lift=int(rule.lift*10)) - - for entity in rule.rhs: - graph.add_node(entity, Weight=1, type="Entity") - graph.add_edge(index, entity, Normalized_Lift=int(rule.lift*10)) +# graph.add_node (index, Weight=int(rule.confidence*10), type="Association_Rule") +# +# for entity in rule.lhs: +# graph.add_node(entity, Weight=1, type="Entity") +# graph.add_edge(entity, index, Normalized_Lift=int(rule.lift*10)) +# +# for entity in rule.rhs: +# graph.add_node(entity, Weight=1, type="Entity") +# graph.add_edge(index, entity, Normalized_Lift=int(rule.lift*10)) + for entity1 in rule.lhs: + graph.add_node(entity1, Weight=1, type="Entity") + for entity2 in rule.rhs: + graph.add_node(entity2, Weight=1, type="Entity") + graph.add_edge(entity1, entity2, Normalized_Lift=int(rule.lift*10)) logging.debug("Generated NetworkX graph for {} rules with {} nodes".format(len(rules), len(graph.nodes))) return graph From 22934e02c7396dd86fe1691760c28971b7263e81 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Mon, 14 Jun 2021 18:18:13 -0500 Subject: [PATCH 07/17] Update README.md --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 27c4511..a480b02 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,17 @@ Advanced Python Association Rule Visualization Library +# Changes: + +This Repo was forked and then changed to fix a bug in the original repo: + 1. Line 5 in PyARMViz throws a TypeError when the file is imported + 2. +Other changes: + 1. Removed annotation from network diagram graph + 2. Removed association rule type nodes from network diagram graph, instead connecting each antecedent with every consequent in a given association rule + +# For Original Repo, go to: https://github.com/mazeofthemind/PyARMViz + # Summary Loosely based on [ARulesViz](https://cran.r-project.org/web/packages/arulesViz/index.html) for R @@ -197,4 +208,4 @@ git clone https://github.com/Mazeofthemind/PyARMViz.git pip install poetry cd PyARMViz python -m poetry build -''' \ No newline at end of file +''' From 0481e675c92aaf255b32d71d674cfe247ffd8794 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Mon, 14 Jun 2021 18:18:40 -0500 Subject: [PATCH 08/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a480b02..e92d3e3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Advanced Python Association Rule Visualization Library This Repo was forked and then changed to fix a bug in the original repo: 1. Line 5 in PyARMViz throws a TypeError when the file is imported - 2. + Other changes: 1. Removed annotation from network diagram graph 2. Removed association rule type nodes from network diagram graph, instead connecting each antecedent with every consequent in a given association rule From 3d5d972291b070677db45b7bf84b5cc493289bf6 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Mon, 14 Jun 2021 18:22:23 -0500 Subject: [PATCH 09/17] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e92d3e3..fbf5ba9 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,9 @@ Advanced Python Association Rule Visualization Library # Changes: -This Repo was forked and then changed to fix a bug in the original repo: - 1. Line 5 in PyARMViz throws a TypeError when the file is imported +This Repo was forked and then changed to fix two bugs in the original repo: + 1. Line 5 in PyARMViz throws a TypeError when the file is imported, fixed class reference + 2. Line 16 throws an import error, line is commented out now Other changes: 1. Removed annotation from network diagram graph From 82462a193e90b27e68ec14a2fc0386daed9c8589 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Wed, 16 Jun 2021 16:52:22 -0500 Subject: [PATCH 10/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index 79da6a5..ddcca3f 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -348,7 +348,7 @@ def adjacency_graph_plotly(rules:Rule): node_trace = go.Scatter( x=node_x, y=node_y, mode='markers', - hoverinfo='text', + #hoverinfo='text', text=node_text, marker=dict( showscale=True, From ff6fcaa8d0d74f5628d167157ef6c716842044be Mon Sep 17 00:00:00 2001 From: nachigonz Date: Wed, 16 Jun 2021 16:56:22 -0500 Subject: [PATCH 11/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index ddcca3f..b6e0947 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -347,7 +347,7 @@ def adjacency_graph_plotly(rules:Rule): node_trace = go.Scatter( x=node_x, y=node_y, - mode='markers', + mode='text', #hoverinfo='text', text=node_text, marker=dict( From 74b6194415a910ead27de501e14828539e7dc597 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Wed, 16 Jun 2021 17:08:32 -0500 Subject: [PATCH 12/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index b6e0947..b6fd033 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -347,7 +347,7 @@ def adjacency_graph_plotly(rules:Rule): node_trace = go.Scatter( x=node_x, y=node_y, - mode='text', + mode='markers+text', #hoverinfo='text', text=node_text, marker=dict( From 4b899c2b454bee9f26b53d5a2c90deb424f94a93 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Wed, 16 Jun 2021 17:11:55 -0500 Subject: [PATCH 13/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 1 + 1 file changed, 1 insertion(+) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index b6fd033..81ed601 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -350,6 +350,7 @@ def adjacency_graph_plotly(rules:Rule): mode='markers+text', #hoverinfo='text', text=node_text, + textposition = "top center", marker=dict( showscale=True, # colorscale options From 2858e59df4649807119625890c155a6aeab85cf0 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Wed, 16 Jun 2021 17:16:04 -0500 Subject: [PATCH 14/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index 81ed601..074f131 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -348,7 +348,7 @@ def adjacency_graph_plotly(rules:Rule): node_trace = go.Scatter( x=node_x, y=node_y, mode='markers+text', - #hoverinfo='text', + hoverinfo='text', text=node_text, textposition = "top center", marker=dict( From a0513630b39537a0f33241847e2dac8d1fb09862 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Wed, 16 Jun 2021 17:33:50 -0500 Subject: [PATCH 15/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index 074f131..87996c8 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -344,12 +344,21 @@ def adjacency_graph_plotly(rules:Rule): node_y.append(y) node_text.append(node) + hover_text = [] + for node, adjacencies in enumerate(graph.adjacency()): + hover_text.append('\n# of Connections: '+str(len(adjacencies[1]))) + + nodeI = 0 + while nodeI < len(node_text): + hover_text[nodeI] = node_text[nodeI] + hover_text[nodeI] + nodeI = nodeI + 1 node_trace = go.Scatter( x=node_x, y=node_y, mode='markers+text', hoverinfo='text', text=node_text, + hovertext = hover_text, textposition = "top center", marker=dict( showscale=True, From 22c03d823722b058494b2368fa13a1a8163e58ae Mon Sep 17 00:00:00 2001 From: nachigonz Date: Wed, 16 Jun 2021 17:37:22 -0500 Subject: [PATCH 16/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index 87996c8..53104a4 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -346,7 +346,7 @@ def adjacency_graph_plotly(rules:Rule): hover_text = [] for node, adjacencies in enumerate(graph.adjacency()): - hover_text.append('\n# of Connections: '+str(len(adjacencies[1]))) + hover_text.append('--\n# of Connections: '+str(len(adjacencies[1]))) nodeI = 0 while nodeI < len(node_text): From 688dc5ba724414dbad4f131bb588e4786bcdda95 Mon Sep 17 00:00:00 2001 From: nachigonz Date: Wed, 16 Jun 2021 17:39:21 -0500 Subject: [PATCH 17/17] Update PyARMViz.py --- PyARMViz/PyARMViz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index 53104a4..9aa15b0 100644 --- a/PyARMViz/PyARMViz.py +++ b/PyARMViz/PyARMViz.py @@ -346,7 +346,7 @@ def adjacency_graph_plotly(rules:Rule): hover_text = [] for node, adjacencies in enumerate(graph.adjacency()): - hover_text.append('--\n# of Connections: '+str(len(adjacencies[1]))) + hover_text.append(' --\n# of Connections: '+str(len(adjacencies[1]))) nodeI = 0 while nodeI < len(node_text):