Created
February 18, 2024 20:21
-
-
Save smzn/f7d6d395defbed50afbd3aba7d78cee0 to your computer and use it in GitHub Desktop.
ベイジアンネットワークの作成
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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