diff --git a/PyARMViz/PyARMViz.py b/PyARMViz/PyARMViz.py index fa23c44..9aa15b0 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 @@ -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 @@ -328,12 +344,22 @@ 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', + mode='markers+text', hoverinfo='text', text=node_text, + hovertext = hover_text, + textposition = "top center", marker=dict( showscale=True, # colorscale options @@ -358,11 +384,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)) ) @@ -391,15 +412,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 @@ -436,4 +462,4 @@ def adjacency_scatter_plot(rules:List[Rule], notebook_flag:bool = False): )) fig.show() - return fig \ No newline at end of file + return fig 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 diff --git a/README.md b/README.md index 27c4511..fbf5ba9 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,18 @@ Advanced Python Association Rule Visualization Library +# Changes: + +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 + 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 +209,4 @@ git clone https://github.com/Mazeofthemind/PyARMViz.git pip install poetry cd PyARMViz python -m poetry build -''' \ No newline at end of file +'''