横截面数据分类——基于R
参考资料:
《复杂数据统计方法》&网络&帮助文件
适用情况:在因变量为分类变量而自变量含有多个分类变量或分类变量水平较多的情况。
一.
(一)概论和例子
数据来源:http://archive.ics.uci.edu/ml/datasets/Cardiotocography
自变量:LB - FHR baseline (beats per minute)
AC - # of accelerations per second
FM - # of fetal movements per second
UC - # of uterine contractions per second
DL - # of light decelerations per second
DS - # of severe decelerations per second
DP - # of prolongued decelerations per second
ASTV - percentage of time with abnormal short term variability
MSTV - mean value of short term variability
ALTV - percentage of time with abnormal long term variability
MLTV - mean value of long term variability
Width - width of FHR histogram
Min - minimum of FHR histogram
Max - Maximum of FHR histogram
Nmax - # of histogram peaks
Nzeros - # of histogram zeros
Mode - histogram mode
Mean - histogram mean
Median - histogram median
Variance - histogram variance
Tendency - histogram tendency
CLASS - FHR pattern class code (1 to 10)
因变量:
NSP - fetal state class code (N=normal; S=suspect; P=pathologic)
(二)产生交叉验证数据集
1.十折交叉验证 概念(百度百科)
英文名叫做10-fold cross-validation,用来测试算法准确性。是常用的测试方法。将数据集分成十分,轮流将其中9份作为训练数据,1份作为测试数据,进行试验。每次试验都会得出相应的正确率(或差错率)。10次的结果的正确率(或差错率)的平均值作为对算法精度的估计,一般还需要进行多次10折交叉验证(例如10次10折交叉验证),再求其均值,作为对算法准确性的估计。
之所以选择将数据集分为10份,是因为通过利用大量数据集、使用不同学习技术进行的大量试验,表明10折是获得最好误差估计的恰当选择,而且也有一些理论根据可以证明这一点。但这并非最终诊断,争议仍然存在。而且似乎5折或者20折与10折所得出的结果也相差无几。
Fold=function(Z=,w,D,seed=){
n=nrow(w)
d=:n
dd=list()
e=levels(w[,D])
T=length(e)
set.seed(seed)
for(i in :T){
d0=d[w[,D]==e[i]]
j=length(d0)
ZT=rep(:Z,ceiling(j/Z))[:j]
id=cbind(sample(ZT,length(ZT)),d0)
dd[[i]]=id}
mm=list()
for(i in :Z){u=NULL;
for(j in :T)u=c(u,dd[[j]][dd[[j]][,]==i,])
mm[[i]]=u}
return(mm)}
#读入数据
w=read.csv("CTG.NAOMIT.csv")
#因子化最后三个哑元变量
F=: #三个分类变量的列数
for(i in F)
w[,i]=factor(w[,i])
D= #因变量的位置
Z= #折数
n=nrow(w)#行数
mm=Fold(Z,w,D,)
二.决策树分类(分类树)
library(rpart.plot)
(a=rpart(NSP~.,w))#用决策树你和全部数据并打印输出
rpart.plot(a,type=,extra=)
rpart.plot参数解释:
x :
An rpart object. The only required argument.
type:
Type of plot. Five possibilities:
0 The default. Draw a split label at each split and a node label at each leaf.
1 Label all nodes, not just leaves. Similar to text.rpart's all=TRUE.
2 Like 1 but draw the split labels below the node labels. Similar to the plots in the CART book.
3 Draw separate split labels for the left and right directions.
4 Like 3 but label all nodes, not just leaves. Similar to text.rpart's fancy=TRUE. See also clip.right.labs.
extra :
Display extra information at the nodes. Possible values:
0 No extra information (the default).
1 Display the number of observations that fall in the node (per class for class objects; prefixed by the number of events for poisson and exp models). Similar to text.rpart's use.n=TRUE.
2 Class models: display the classification rate at the node, expressed as the number of correct classifications and the number of observations in the node. Poisson and exp models: display the number of events.
3 Class models: misclassification rate at the node, expressed as the number of incorrect classifications and the number of observations in the node.
4 Class models: probability per class of observations in the node (conditioned on the node, sum across a node is 1).
5 Class models: like 4 but do not display the fitted class.
6 Class models: the probability of the second class only. Useful for binary responses.
7 Class models: like 6 but do not display the fitted class.
8 Class models: the probability of the fitted class.
9 Class models: the probabilities times the fraction of observations in the node (the probability relative to all observations, sum across all leaves is 1).
branch:
Controls the shape of the branch lines. Specify a value between 0 (V shaped branches) and 1 (square shouldered branches). Default is if(fallen.leaves) 1 else .2.
branch=0
branch=1
digits :
The number of significant digits in displayed numbers. Default 2.
rpart.plot(a,extra=,digits=)
横截面数据分类——基于R的更多相关文章
- 统计学习导论:基于R应用——第二章习题
目前在看统计学习导论:基于R应用,觉得这本书非常适合入门,打算把课后习题全部做一遍,记录在此博客中. 第二章习题 1. (a) 当样本量n非常大,预测变量数p很小时,这样容易欠拟合,所以一个光滑度更高 ...
- 基于R树索引的点面关系判断以及效率优化统计
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 在之前的博客中,我分别介绍了基于网格的空间索引(http:// ...
- 概率图模型 基于R语言 这本书中的第一个R语言程序
概率图模型 基于R语言 这本书中的第一个R语言程序 prior <- c(working =0.99,broken =0.01) likelihood <- rbind(working = ...
- 基于R语言的时间序列指数模型
时间序列: (或称动态数列)是指将同一统计指标的数值按其发生的时间先后顺序排列而成的数列.时间序列分析的主要目的是根据已有的历史数据对未来进行预测.(百度百科) 主要考虑的因素: 1.长期趋势(Lon ...
- 基于R语言的ARIMA模型
A IMA模型是一种著名的时间序列预测方法,主要是指将非平稳时间序列转化为平稳时间序列,然后将因变量仅对它的滞后值以及随机误差项的现值和滞后值进行回归所建立的模型.ARIMA模型根据原序列是否平稳以及 ...
- Twitter基于R语言的时序数据突变检测(BreakoutDetection)
Twitter开源的时序数据突变检测(BreakoutDetection),基于无参的E-Divisive with Medians (EDM)算法,比传统的E-Divisive算法快3.5倍以上,并 ...
- (数据科学学习手札10)系统聚类实战(基于R)
上一篇我们较为系统地介绍了Python与R在系统聚类上的方法和不同,明白人都能看出来用R进行系统聚类比Python要方便不少,但是光介绍方法是没用的,要经过实战来强化学习的过程,本文就基于R对2016 ...
- 递归函数之阶乘和字符串反转-基于R和Python
Python课第五周开始讲函数了.递归函数.递归在python中不能超过900多层,否则报错内存溢出什么的.同样在R中递归太深也会报错,阈值和python中大概一样,900多次就报错了. error ...
- R学习:《机器学习与数据科学基于R的统计学习方法》中文PDF+代码
当前,机器学习和数据科学都是很重要和热门的相关学科,需要深入地研究学习才能精通. <机器学习与数据科学基于R的统计学习方法>试图指导读者掌握如何完成涉及机器学习的数据科学项目.为数据科学家 ...
随机推荐
- centos中NAT模式下静态IP连接外网
使用linux虚拟机时,通常会用到yum命令来安装软件,然而这个命令需要连外网下载软件,用maven下载jar包也需要外网.虚拟机在内网可以互相ping通,然而ping不了外网,于是通过试验,终于找到 ...
- .NetCore+Jexus代理+Redis模拟秒杀商品活动
开篇叙 本篇将和大家分享一下秒杀商品活动架构,采用的架构方案正如标题名称.NetCore+Jexus代理+Redis,由于精力有限所以这里只设计到商品添加,抢购,订单查询,处理队列抢购订单的功能:有不 ...
- DDD理论学习系列(9)-- 领域事件
DDD理论学习系列--案例及目录 1. 引言 A domain event is a full-fledged part of the domain model, a representation o ...
- IBM Security AppScan Standard 用外部设备录制脚本(手机端应用、app、微信等)进行安全测试
一.打开AppScan,选择外部设备/客户机,点击下一步 二.记录代理设置,可以手动输入需要的端口号,也可以自动选择,记住端口号以及PC电脑的ip地址,手机端如何设置对应的端口跟ip可以参考 Jmet ...
- maven(二) maven项目构建ssh工程(父工程与子模块的拆分与聚合)
前一节我们明白了maven是个什么玩意,这一节就来讲讲他的一个重要的应用场景,也就是通过maven将一个ssh项目分割为不同的几个部分独立开发,很重要,加油 --WH 一.maven父工程与子模块的拆 ...
- 在ashx和静态文件中使用Session
在ashx页面中如果想使用可读可写的Session,必须要实现一个接口“IRequiresSessionState”,在这个接口中没有定义任何方法,这样的接口被称为“标识接口”. public int ...
- Linux下安装openvpn
工作上常常要通过vpn访问内网环境,最近一直在linux上搞东西,为了方便起见在linux上也安装了openvpn. 本次安装的openvpn不是把它当做服务端,而仅仅是以客户端来使用,所以没有那些服 ...
- 数据结构3——浅谈zkw线段树
线段树是所有数据结构中,最常用的之一.线段树的功能多样,既可以代替树状数组完成"区间和"查询,也可以完成一些所谓"动态RMQ"(可修改的区间最值问题)的操作.其 ...
- python编程快速上手之第4章实践项目参考答案
#!/usr/bin/env python3.5 # coding:utf-8 # 假定有一个列表,编写函数以一个列表值作为参数,返回一个字条串 # 该字符串包含所有表项,之间以逗号和空格分隔,并在最 ...
- 详解equals()方法和hashCode()方法
前言 Java的基类Object提供了一些方法,其中equals()方法用于判断两个对象是否相等,hashCode()方法用于计算对象的哈希码.equals()和hashCode()都不是final方 ...