Skip to content

Instantly share code, notes, and snippets.

@smzn
Created February 18, 2024 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smzn/f7d6d395defbed50afbd3aba7d78cee0 to your computer and use it in GitHub Desktop.
Save smzn/f7d6d395defbed50afbd3aba7d78cee0 to your computer and use it in GitHub Desktop.
ベイジアンネットワークの作成
import networkx as nx
import matplotlib.pyplot as plt
# ベイジアンネットワークの有向グラフを作成
G = nx.DiGraph()
# ノードを追加
G.add_node("W")
G.add_node("S")
G.add_node("R")
G.add_node("G")
# エッジを追加
G.add_edge("W", "S")
G.add_edge("W", "R")
G.add_edge("S", "G")
G.add_edge("R", "G")
# ベイジアンネットワークを描画
pos = nx.spring_layout(G) # グラフをレイアウト
nx.draw(G, pos, with_labels=True, node_size=3000, node_color="skyblue", font_size=15, font_weight="bold") # グラフを描画
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment