Я пытаюсь найти шаблон покупки из определенного набора данных. Сейчас я делаю визуализацию результата, который я получаю от Apriori, Правила ассоциации. Однако у меня возникла эта ошибка TypeError с кодами.
Я пытаюсь определить функцию draw_graph, а затем вызываю функцию graph для рисования моих правил.
def draw_graph(rules, rules_to_show):
import networkx as nx
G1 = nx.DiGraph()
color_map = []
N = 50
colors = np.random.rand(N)
strs=['R0','R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8', 'R9', 'R10', 'R11']
for i in range(rules_to_show):
G1.add_nodes_from(["R"+str(i)])
for a in rules.iloc[i]['antecedants']:
G1.add_nodes_from([a])
G1.add_edge(a,"R"+str(i),color=colors[i],weight = 2)
for c in rules.iloc[i]['consequents']:
G1.add_node_from([c])
G1.add_edge("R"+str(i),c,color=colors[i], weight = 2)
for node in G1:
found_a_string=False
for item in strs:
if node==item:
found_a_string = True
if found_a_string:
color_map.append('yellow')
else:
color_map.append('green')
edges = G1.edges()
colors = [G1[u][v]['color'] for u,v in edges]
weights = [G1[u][v]['weight'] for u,v in edges]
pos = nx.spring_layout(G1, k=16, scale=1)
nx.draw(G1, pos, edges = edges, node_color = color_map, edge_color = colors, width=weights, font_size=16, with_labels=False)
for p in pos:
pos[p][1] += 0.07
nx.draw_networkx_labels(G1,pos)
plt.show()
support = rules.values(columns=['support'])
confidence = rules.values(columns=['confidence'])
import seaborn as sns1
for i in range (len(support)):
support[i] = support[i]
confidence[i] = confidence[i]
plt.title('Association Rules')
plt.xlabel('support')
plt.ylabel('confidence')
sns1.regplot(x=support,y=confidence,fit_reg=False)
plt.gcf().clear()
draw_graph(rules,10)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-41-279d477166f6> in <module>
----> 1 support = rules.values(columns=['support'])
2 confidence = rules.values(columns=['confidence'])
3
4 import seaborn as sns1
5
TypeError: 'numpy.ndarray' object is not callable
Если есть какая-либо помощь по это было бы здорово. Спасибо