Hi,
I was playing with the genetic programming commands, notably gp.graph. It looks to me like the example commands provided in the documentation and notebook do not work.
Block 16 of this notebook generates the error "module networkx has no attribute graphviz_layout". Indeed, these packages apparently changed, and graphviz_layout can no longer be called like this.
Code examples in the documentation of the function deap.gp.graph here had a few issues when I tried to run it with the symbolic regression example. Both documentation examples use the line
nodes, edges, labels = graph(expr)
Which gives the error "graph is not a callable object"
One modified code that worked for me to plot the genetic programming trees works as follows:
import matplotlib.pyplot as pltimport networkximport pygraphviz as pgvnodes, edges, labels = gp.graph(expr)graph = networkx.Graph()graph.add_nodes_from(nodes)graph.add_edges_from(edges)pos = graphviz_layout(graph, prog='dot')plt.figure(figsize=(7,7))networkx.draw_networkx_nodes(graph, pos, node_size=900, node_color="w")networkx.draw_networkx_edges(graph, pos)networkx.draw_networkx_labels(graph, pos, labels)plt.axis("off")plt.show()
It seems that installing both networkx and pygraphviz is necessary. Main changes in my workaround: 1) using gp.graph instead of graph, and 2) graphviz_layout instead of networkx.graphviz_layout.
Hi, I was playing with the genetic programming commands, notably gp.graph. It looks to me like the example commands provided in the documentation and notebook do not work.
nodes, edges, labels = graph(expr)
Which gives the error "graph is not a callable object"One modified code that worked for me to plot the genetic programming trees works as follows:
import matplotlib.pyplot as plt
import networkx
import pygraphviz as pgv
nodes, edges, labels = gp.graph(expr)
graph = networkx.Graph()
graph.add_nodes_from(nodes)
graph.add_edges_from(edges)
pos = graphviz_layout(graph, prog='dot')
plt.figure(figsize=(7,7))
networkx.draw_networkx_nodes(graph, pos, node_size=900, node_color="w")
networkx.draw_networkx_edges(graph, pos)
networkx.draw_networkx_labels(graph, pos, labels)
plt.axis("off")
plt.show()
It seems that installing both networkx and pygraphviz is necessary. Main changes in my workaround: 1) using gp.graph instead of graph, and 2) graphviz_layout instead of networkx.graphviz_layout.
Hope this can be of help. Best, Aymeric