Draw Perceptron graph by graphviz
Libraries¶
In [1]:
from graphviz import Digraph
Create a node list and dictionary for the edges¶
In [12]:
# List of nodes
l_nodes = ['1', 'x0', 'x1', 'y']
# Dictionary mapping from label name to the edge between two nodes
d_edges = {'b': ('1', 'y'),
'w0': ('x0', 'y'),
'w1': ('x1', 'y')}
Visualize a graph for perceptron¶
In [13]:
# Create Digraph object
dot = Digraph()
dot.attr(rankdir='LR')
# Add nodes
for n in l_nodes:
dot.node(n)
# Add edges
for label, edges in d_edges.items():
dot.edge(edges[0], edges[1], label=label)
# Fill node 1 by gray
dot.node('1', style='filled')
# Visualize the graph
dot
Out[13]: