最近在学习贝叶斯网络,当用K2算法建立了贝叶斯网络结构之后,用R语言工具可以很清楚地实现网络可视化。
例如,在泰坦尼克号数据集中,最后生成的贝叶斯网络结构如下:
age, sex
portembarked, sex
numparentschildren, age
numparentschildren, sex
passengerclass, age
passengerclass, portembarked
passengerclass, fare
passengerclass, sex
passengerclass, numsiblings
passengerclass, survived
sex, survived
numsiblings, age
numsiblings, numparentschildren
numsiblings, sex
利用R语言的networdD3包,可以有效地实现网络可视化。
关于networkD3包的介绍:http://christophergandrud.github.io/networkD3/#simple
实现上文的网络框架的代码:
# Load package
library(networkD3)
# Create fake data
src <- c("passengerclass","passengerclass", "passengerclass", "passengerclass","passengerclass","passengerclass",
"numsiblings","numsiblings","numsiblings",
"numparentschildren","numparentschildren",
"age","portembarked","sex")
target <- c("age","portembarked","fare","sex","numsiblings","survived",
"age","numparentschildren","sex",
"age","sex",
"sex","sex","survived")
networkData <- data.frame(src, target)
# Plot
simpleNetwork(networkData)
最终实现的网络图如下:
sugar~