R语言做贝叶斯网络结构学习
文章目录
本文使用pcalg包做贝叶斯网络结构的学习
#实例分析
##pcalg包的安装
安装pcalg包时由于有些依赖包已经被CRAN撤掉,所以安装起来有些技巧。
以下是安装代码:
install.packages('BiocManager', repos = 'https://mirrors.tuna.tsinghua.edu.cn/CRAN')
options('BioC_mirror'='https://mirrors.tuna.tsinghua.edu.cn/bioconductor/')
BiocManager::install(c('graph','RBGL','Rgraphviz'))
install.packages(c('kpcalg'), repos = 'https://mirrors.tuna.tsinghua.edu.cn/CRAN')
##贝叶斯网络结构学习
###iris数据集
我们使用iris数据集进行学习,这是一个针对连续变量的结构学习的例子:
suffStat <-list(C = cor(iris[,1:4]), n = nrow(iris))
pc.fit <- pc(suffStat, indepTest = gaussCItest,alpha = 0.01,labels =names(iris[1:4]),verbose = TRUE)
pc.fit
plot(pc.fit)
###Adult数据集
该数据从美国1994年人口普查数据库抽取而来,可以用来预测居民收入是否超过50K/year。该数据集类变量为年收入是否超过50k$,属性变量包含年龄,工种,学历,职业,人种等重要信息,值得一提的是,14个属性变量中有7个类别型变量。
- age – The age of the individual
- type_employer – The type of employer the individual has. Whether they are government, military, private, an d so on.
- fnlwgt – The # of people the census takers believe that observation - represents. We will be ignoring this variable
- education – The highest level of education achieved for that individual
- education_num – Highest level of education in numerical form
- marital – Marital status of the individual
- occupation – The occupation of the individual
- relationship – A bit more difficult to explain. Contains family relationship values like husband, father, and so on, but only contains one per observation. I’m not sure what this is supposed to represent
- race – descriptions of the individuals race. Black, White, Eskimo, and so on
- sex – Biological Sex
- capital_gain – Capital gains recorded
- capital_loss – Capital Losses recorded
- hr_per_week – Hours worked per week
- country – Country of origin for person
- income – Boolean Variable. Whether or not the person makes more than $50,000 per annum income.
对于离散数据,我们使用 G 2 G^2 G2统计量来检验条件独立性。
接来下探索一下,教育,婚姻状态,职业,收入的关系是怎样的:
url <- "http://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data"
adult <- read.csv(url, strip.white = TRUE, header = FALSE,col.names=c("age", "type_employer", "fnlwgt", "education", "education_num","marital", "occupation", "relationship", "race","sex","capital_gain", "capital_loss", "hr_per_week","country", "income"))> adult<-adult[,c(4,6,7,15)]
> head(adult)education marital occupation income
1 Bachelors Never-married Adm-clerical <=50K
2 Bachelors Married-civ-spouse Exec-managerial <=50K
3 HS-grad Divorced Handlers-cleaners <=50K
4 11th Married-civ-spouse Handlers-cleaners <=50K
5 Bachelors Married-civ-spouse Prof-specialty <=50K
6 Masters Married-civ-spouse Exec-managerial <=50K
adult2<-sapply(adult,function(x){temp<-as.integer(factor(x))-1
})
nlev<-sapply(adult,function(x){temp<-factor(x)length(levels(temp))
})
adult2<-as.data.frame(adult2)
suffStat <- list(dm = adult2, nlev = nlev, adaptDF = FALSE)pc.fit <- pc(suffStat, indepTest = disCItest,alpha = 0.01,labels =names(adult2),verbose = TRUE)
pc.fitplot(pc.fit)
该包的详细说明:
Causal Inference using Graphical Models with the Package pcalg
Package ‘pcalg’
作为分享主义者(sharism),本人所有互联网发布的图文均遵从CC版权,转载请保留作者信息并注明作者a358463121专栏:http://blog.csdn.net/a358463121,如果涉及源代码请注明GitHub地址:https://github.com/358463121/。商业使用请联系作者。
R语言做贝叶斯网络结构学习相关推荐
- 贝叶斯网络结构学习之K2算法(基于FullBNT-1.0.4的MATLAB实现)
题目:贝叶斯网络结构学习之K2算法(基于FullBNT-1.0.4的MATLAB实现) 有关贝叶斯网络结构学习的一基本概念可以参考:贝叶斯网络结构学习方法简介 有关函数输入输出参数的解释可以参考:贝叶 ...
- 贝叶斯网络结构学习之连续参数处理方法
题目:贝叶斯网络结构学习之连续参数处理方法 注:本文有更新,参见<有关属性离散化算法CACC的补充说明>和<有关属性离散化算法CACC的再次补充说明>.以下为原文: 首先必须说 ...
- 贝叶斯网络结构学习若干问题解释
题目:贝叶斯网络结构学习若干问题解释 本篇主要为后续讲解具体结构学习算法打基础,共解释以下几个问题: 1.用于贝叶斯网络结构学习的数据集如何存储? 2.学得的贝叶斯网络结构如何存储? 3.什么是节点顺 ...
- 贝叶斯网络结构学习(基于BDAGL工具箱的MATLAB实现)
题目:贝叶斯网络结构学习(基于BDAGL工具箱的MATLAB实现) 有关贝叶斯网络结构学习的一基本概念可以参考:贝叶斯网络结构学习方法简介 有关函数输入输出参数的解释可以参考:贝叶斯网络结构学习若干问 ...
- 基于搜索的贝叶斯网络结构学习算法-K2
部分内容取自:[Cooper and Herskovits, 1991] Cooper, G. and Herskovits, E. (January, 1991). A Bayesian metho ...
- 概率图模型基于R语言(一)贝叶斯模型
概率图模型基于R语言[一]贝叶斯模型 条件概率 贝叶斯模型 R 参考书:<概率图模型基于R语言> 记录一些代码和自己的想法和目前版本代码的写法(书中有一些无法用了) 随时更新 条件概率 熟 ...
- R语言的贝叶斯网络模型教程
在现代的生态.环境以及地学研究中,变量和变量间的因果关系推断占据了非常重要的地位.在实践中,变量间的因果关系研究往往求助于昂贵的实验,但所得结果又经常与天然环境中的实际因果联系相差甚远.统计学方法是研 ...
- R语言用贝叶斯线性回归、贝叶斯模型平均 (BMA)来预测工人工资
最近我们被客户要求撰写关于贝叶斯线性回归的研究报告,包括一些图形和统计输出. 视频:线性回归中的贝叶斯推断与R语言预测工人工资数据案例 贝叶斯推断线性回归与R语言预测工人工资数据 ,时长09:58 背 ...
- R语言实现贝叶斯分位数回归、lasso和自适应lasso贝叶斯分位数回归分析
最近我们被客户要求撰写关于分位数回归的研究报告,包括一些图形和统计输出. 摘要 贝叶斯回归分位数在最近的文献中受到广泛关注,本文实现了贝叶斯系数估计和回归分位数(RQ)中的变量选择,带有lasso和自 ...
最新文章
- Listen error 错误和 limit of inotify watches was reached
- caffe安装,编译(包括CUDA和cuDNN的安装),并训练,测试自己的数据(caffe使用教程)
- maven搭建多模块项目和管理
- 2021年中国现制茶饮行业洞察报告
- Android开发4: Notification编程基础、Broadcast的使用及其静态注册、动态注册方式...
- 常用的HTML5和CSS3标签及用法(入门篇)
- 关于Spring Cloud Netflix
- 【Codeforces Round #585 (Div. 2) E】Marbles【状压DP】
- 《深入解析windows操作系统第6版下册》第10章:内存管理(第三部分译文与图片)...
- Axure基础教程:产品流程图的制作方法详解
- 稀疏编码(Sparse Coding)
- [音频处理]傅里叶变换去噪
- 实用小软件实现Mac读写ntfs U盘 移动硬盘
- dpkg: dependency problems prevent configuration in Ubuntu Linux问题解决
- 《漫游》之《绝代双骄3》
- Minecraft mod制作简易教程(五)——本地化和国际化
- 白话机器学习-Encoder-Decoder框架
- 深信服 华为路由器 ipsce对接
- Qt运行程序弹出异常窗口解释
- carla Engine crash handling finished; re-raising signal 11 for the default handler. Good bye.
热门文章
- HBuilder实现App icon右上角数字小红点BadgeNumber
- 获得华为手机刘海屏幕刘海高度宽度与虚拟按键背景颜色修改
- 1.4_3 Axure RP 9 for mac 高保真原型图 - 案例2 【旋转的唱片】
- 广西 高校 职称计算机考试成绩查询,广西人事考试网报名入口、成绩查询
- 【原创分析】从技术角度分析陈冠希事件的必然性
- 史上最全数据分析师资料免费下载[Python]
- PHP计算百分比,保留指定位小数,保留整数
- 2021国考计算机专业可以报财务类的岗吗,哪些专业可以报2021年国考?
- 鸿蒙系统延期,华为P50Pro搭载鸿蒙系统正式亮相:3+1全新四摄,推迟到秋季发布...
- vue excel上传判断(解决mac上传type为空的问题)