ROC
# -*- coding: utf-8 -*-
# __author__ = "JieYao" from biocluster.agent import Agent
from biocluster.tool import Tool
import os
import string
import types
import subprocess
from biocluster.core.exceptions import OptionError class RocAgent(Agent):
"""
需要calc_roc.pl
version v1.1
author: JieYao
last_modifued:2016.08.22
""" def __init__(self, parent):
super(RocAgent, self).__init__(parent)
options = [
{"name": "mode", "type": "int", "default":1},
{"name": "genus_table", "type": "string"},
{"name": "group_table", "type": "string"},
{"name": "method", "type": "string", "default":""},
{"name": "name_table", "type": "string", "default":""},
{"name": "top_n", "type": "int", "default": 20}
]
self.add_option(options)
self.step.add_steps('RocAnalysis')
self.on('start', self.step_start)
self.on('end', self.step_end) def step_start(self):
self.step.RocAnalysis.start()
self.step.update() def step_end(self):
self.step.RocAnalysis.finish()
self.step.update() def check_options(self):
if not os.path.exists(self.option('genus_table')):
raise OptionError("必须提供Genus Table")
if not os.path.exists(self.option('group_table')):
raise OptionError("必须提供分组表格")
if self.option('method'):
if self.option('method') not in ['sum', 'average', 'median']:
raise OptionError("丰度计算方法只能选择sum,average,median之一")
if self.option('mode') == 2:
if not os.path.exists(self.option('name_table')):
raise OptionError("Mode 2 模式下必须提供物种名列表文件")
os.system('cat %s | awk -F "\t" \'{ print $1 }\' > tmp.txt' %(self.option('genus_table')))
genus_data = open("tmp.txt", "r").readlines()[1:]
os.remove('tmp.txt')
genus_data = map(string.rstrip, genus_data)
sample_data = open(self.option('genus_table'), "r").readline().strip().split()[1:] group_data = open(self.option('group_table'), "r").readlines()[1:]
group_data = map(string.strip, group_data)
for s in group_data:
if s.split()[0] not in sample_data:
raise OptionError("物种%s不在Genus Table中" % s.split()[0])
if s.split()[1] not in ['','']:
raise OptionError("物种分组只能有0和1!") if self.option('mode')==2:
name_data = open(self.option('name_table'), "r").readlines()[1:]
name_data = map(string.strip, name_data)
for s in name_data:
if s not in genus_data:
raise OptionError("物种%s不在Genus Table中" % s) if self.option('mode')==1:
if self.option('top_n')>len(genus_data):
raise OptionError("选择丰度前N高物种时,设定的N多于物种总数:%d>%d" %(self.option('top_n'), len(genus_data))) return True def set_resource(self):
"""
"""
self._cpu = 2
self._memory = '' def end(self):
result_dir = self.add_upload_dir(self.output_dir)
result_dir.add_relpath_rules([
[".", "", "ROC分析结果目录"],
["./roc_curve.pdf", "pdf", "ROC受试者工作特征曲线图"],
["./roc_auc.xls", "xls", "ROC受试者工作特征曲线-AUC VALUE"]
])
print self.get_upload_files()
super(RocAgent, self).end() class RocTool(Tool):
def __init__(self, config):
super(RocTool, self).__init__(config)
self._version = '1.0.1' def run(self):
"""
运行
"""
super(RocTool, self).run()
self.run_roc_perl() def run_roc_perl(self):
"""
运行calc_roc.perl
"""
os.system('export PATH=/mnt/ilustre/users/sanger-dev/app/gcc/5.1.0/bin:$PATH')
os.system('export LD_LIBRARY_PATH=/mnt/ilustre/users/sanger-dev/app/gcc/5.1.0/lib64:$LD_LIBRARY_PATH')
cmd = self.config.SOFTWARE_DIR + '/program/perl/perls/perl-5.24.0/bin/perl ' + self.config.SOFTWARE_DIR + '/bioinfo/meta/scripts/plot_roc.pl '
cmd += '-o %s ' %(self.work_dir + '/ROC/')
cmd += '-i %s ' %(self.option('genus_table'))
cmd += '-mode %d ' %(self.option('mode'))
cmd += '-group %s ' %(self.option('group_table'))
if self.option('mode')==2:
cmd += '-name %s ' %(self.option('name_table'))
if self.option('method'):
cmd += '-method %s ' %(self.option('method'))
if self.option('mode')==1:
cmd += '-n %d ' %(self.option('top_n'))
cmd += '-labels F '
self.logger.info('开始运行calc_roc.pl计算ROC相关数据') try:
subprocess.check_output(cmd, shell=True)
self.logger.info('生成 roc.cmd.r 成功')
except subprocess.CalledProcessError:
self.logger.info('生成 roc.cmd.r 失败')
self.set_error('无法生成 roc.cmd.r 文件')
try:
subprocess.check_output(self.config.SOFTWARE_DIR +
'/program/R-3.3.1/bin/R --restore --no-save < %s/roc.cmd.r' % (self.work_dir + '/ROC'), shell=True)
self.logger.info('ROC计算成功')
except subprocess.CalledProcessError:
self.logger.info('ROC计算失败')
self.set_error('R运行计算ROC失败')
raise "运行R脚本计算ROC相关数据失败"
self.logger.info('运行calc_roc.pl程序进行ROC计算完成')
allfiles = self.get_roc_filesname()
self.linkfile(self.work_dir + '/ROC/' + allfiles[0], 'roc_curve.pdf')
self.linkfile(self.work_dir + '/ROC/' + allfiles[1], 'roc_auc.xls')
self.end() def linkfile(self, oldfile, newname):
newpath = os.path.join(self.output_dir, newname)
if os.path.exists(newpath):
os.remove(newpath)
os.link(oldfile, newpath) def get_roc_filesname(self):
filelist = os.listdir(self.work_dir + '/ROC')
roc_curve = None
roc_auc = None
for name in filelist:
if 'roc_curve.pdf' in name:
roc_curve = name
elif 'roc_aucvalue.xls' in name:
roc_auc = name
if (roc_curve and roc_auc):
return [roc_curve, roc_auc]
else:
self.set_error("未知原因,ROC计算结果丢失")
#!/usr/bin/perl use strict;
use warnings;
use Getopt::Long;
my %opts;
my $VERSION = "v1.20160817"; GetOptions( \%opts,"mode=s","i=s","group=s","o=s","n=s","method=s","name=s","ncuts=i","labels=s","labelsize=s","rocci=s","siglevel=f","w=f","h=f","facet_wrap=s","theme=s");
my $usage = <<"USAGE";
Program : $
Discription:
Version : $VERSION
Usage :perl $ [options]
-mode * or or ; The Receiver:)The relative abundance of the top n Bacteria(could analysis with more than one group)
)The relative abundance of special bacteria(one or more)
)The receiver is any other factors
-i *Input genus table file(or other Taxonomic level) or any other factors(mode_3).
-group *Group name in mapping file .
-o *Output dir
-n (*mode_1)Top n genus or other taxonomic level(relative abundance)
-method (*mode_1)If you choose the mode_2 to analyze, you can also choose the analysis "methed". If you don't have a choice, you will make a separate analysis of them. Follow method are available:sum, average, median
-name (*mode_2)the name of Bacteria
-ncuts Number of cutpoints to display along each curve.Default:20
-labels Logical, display cutoff text labels:Default:F
-labelsize Size of cutoff text labels.Default:3
-rocci Confidence regions for the ROC curve.Default:F
-siglevel Significance level for the confidence regions.Default:0.05
-w default:6
-h default:5
-facet_wrap Logical,display group in different panel.Default:F
-theme themes for display roc.Follow themes are available:theme_bw,theme_classic,theme_dark,theme_gray,theme_light.Default:theme_bw
Example:$0 -mode 1 -i genus.xls -group group.txt -o output_dir -n 30 -labels F -method sum
$0 -mode 2 -i genus.xls -group group_1.txt -o output_dir -name name.txt -labels F -w 7.8
$0 -mode 2 -i genus.xls -group group_1.txt -o output_dir -name name.txt -labels F -method sum
$0 -mode 3 -i factor.txt -group group.txt -o output_dir -labels F -w 7.8 USAGE die $usage if(!($opts{mode}&&$opts{i}&&$opts{group}&&$opts{o}));
#die $usage if(!(($opts{mode}==F)&&$opts{i}&&$opts{group}&&$opts{o}&&$opts{name})); $opts{n}=defined $opts{n}?$opts{n}:"20";
$opts{method}=defined $opts{method}?$opts{method}:"chengchen.ye";
$opts{name}=defined $opts{name}?$opts{name}:"NULL";
$opts{ncuts}=defined $opts{ncuts}?$opts{ncuts}:20;
$opts{labels}=defined $opts{labels}?$opts{labels}:"F";
$opts{labelsize}=defined $opts{labelsize}?$opts{labelsize}:"3";
$opts{w}=defined $opts{w}?$opts{w}:6;
$opts{h}=defined $opts{h}?$opts{h}:5;
$opts{facet_wrap}=defined $opts{facet_wrap}?$opts{facet_wrap}:"F";
$opts{theme}=defined $opts{theme}?$opts{theme}:"";
$opts{rocci}=defined $opts{rocci}?$opts{rocci}:"F";
$opts{siglevel}=defined $opts{siglevel}?$opts{siglevel}:"0.05"; if(! -e $opts{o}){
`mkdir $opts{o}`;
} open CMD,">$opts{o}/roc.cmd.r"; print CMD "
library(plotROC) group <- read.table(\"$opts{group}\",header=T,check.names=F,comment.char=\"\")
otu_table <-read.table(\"$opts{i}\",sep=\"\t\",head=T,check.names = F,row.names=1)
y<-length(otu_table[1,]) ###The Receiver:A)The relative abundance of the Bacteria
if($opts{mode}==1){
group<-as.data.frame(group)
x<-length(group[1,])
###D
D<-group[,2] ####M
otu_table<-cbind(otu_table,rowsum=rowSums(otu_table))
otu_table<- otu_table[order(otu_table[,y+1],decreasing=T),]
otu_table_top20<- otu_table[1:$opts{n},]
####sum
if(\"$opts{method}\"==\"sum\" ){
v<-y+1
m<-data.frame(colSums(otu_table_top20))[-v,]
} ####average
if(\"$opts{method}\"==\"average\"){
v<-y+1
m<-data.frame(colSums(otu_table_top20)/$opts{n})[-v,]
} ####median
if(\"$opts{method}\"==\"median\"){
top20<-otu_table_top20[,1:y]
m<-as.matrix(as.matrix(top20[ceiling($opts{n}/2),])[1,])
} ###Z
Z<-c(rep(\"group1\",y))
i<-2 while (i <= x-1) {
###D
D<-c(D,group[,i+1])
###M
m<-c(m,m)
###Z
w<-paste(\"group\",i,sep=\"\")
Z<-c(Z,rep(w,y))
i <- i +1
}
#
M <- scale(m, center=T,scale=T) #标准化
if(x!=2){
rocdata<- data.frame(diagnosis = D, measure = M, group = Z)
p <- ggplot(rocdata, aes(m = measure , d = diagnosis ,color=group)) + geom_roc(labels=$opts{labels},labelsize=$opts{labelsize},n.cuts=$opts{ncuts}) + style_roc(major.breaks = c(0, 0.25, 0.5, 0.75, 1), theme=$opts{theme},xlab=\"1-Specificity\",ylab=\"Sensitivity\") if($opts{rocci}==T){
p <- p + geom_rocci(sig.level=$opts{siglevel})
} if($opts{facet_wrap}==T){
p <- p + facet_wrap(~ group) + theme(axis.text = element_text(size = 4))
} } if(x==2){ rocdata<- data.frame(diagnosis = D, measure = M)
p <- ggplot(rocdata, aes(m = measure , d = diagnosis )) + geom_roc(labels=$opts{labels},labelsize=$opts{labelsize},n.cuts=$opts{ncuts}) + style_roc(major.breaks = c(0, 0.25, 0.5, 0.75, 1), theme=$opts{theme},xlab=\"1-Specificity\",ylab=\"Sensitivity\") if($opts{rocci}==T){
p <- p + geom_rocci(sig.level=$opts{siglevel})
} }
x<-x-1
} ###The Receiver:2)The relative abundance of special bacteria.
if($opts{mode}==2){ if(\"$opts{method}\"==\"chengchen.ye\"){
name <- read.table(\"$opts{name}\",header=T,check.names=F,comment.char=\"\")
name<-as.data.frame(name)
x<-length(name[,1])
a<-as.character(name[1,1])
D<-group[,2]
m<-as.matrix(as.matrix(otu_table)[a,]) Z<-c(rep(a,y))
i<-2
while (i <= x) {
D<-c(D,group[,2])
a<-as.character(name[i,1])
m<-c(m,as.matrix(as.matrix(otu_table)[a,]))
a<-as.character(name[i,1])
Z<-c(Z,rep(a,y))
i <- i +1
} M <- scale(m, center=T,scale=T) #标准化
if(x!=1){
rocdata<- data.frame(diagnosis = D, measure = M, Bacteria = Z)
p <- ggplot(rocdata, aes(m = measure , d = diagnosis ,color=Bacteria)) + geom_roc(labels=$opts{labels},labelsize=$opts{labelsize},n.cuts=$opts{ncuts}) + style_roc(major.breaks = c(0, 0.25, 0.5, 0.75, 1), theme=$opts{theme},xlab=\"1-Specificity\",ylab=\"Sensitivity\") if($opts{rocci}==T){
p <- p + geom_rocci(sig.level=$opts{siglevel})
} if($opts{facet_wrap}==T){
p <- p + facet_wrap(~ group) + theme(axis.text = element_text(size = 4))
} } if(x==1){ rocdata<- data.frame(diagnosis = D, measure = M)
p <- ggplot(rocdata, aes(m = measure , d = diagnosis )) + geom_roc(labels=$opts{labels},labelsize=$opts{labelsize},n.cuts=$opts{ncuts}) + style_roc(major.breaks = c(0, 0.25, 0.5, 0.75, 1), theme=$opts{theme},xlab=\"1-Specificity\",ylab=\"Sensitivity\") if($opts{rocci}==T){
p <- p + geom_rocci(sig.level=$opts{siglevel})
}
}
}
######choose method
if(\"$opts{method}\"!=\"chengchen.ye\"){
name <- read.table(\"name.txt\",header=T,check.names=F,comment.char=\"\")
otu_table<-as.data.frame(otu_table)
nu<-length(name[,1]) genus<-otu_table[as.character(name[1,1]),]
i<-2
while (i <= nu) {
genus<-rbind(genus,otu_table[as.character(name[i,1]),])
i<-i+1
}
genus
group<-as.data.frame(group)
x<-length(group[1,])
###D
D<-group[,2] ####M
genus<-cbind(genus,rowsum=rowSums(genus))
genus<- genus[order(genus[,y+1],decreasing=T),] ####sum
if(\"$opts{method}\"==\"sum\" ){
hh<-y+1
m<-data.frame(colSums(genus))[-hh,]
} ####average
if(\"$opts{method}\"==\"average\"){
hh<-y+1
m<-data.frame(colSums(genus)/nu)[-hh,]
} ####median
if(\"$opts{method}\"==\"median\"){
genus_order<-genus[,1:y]
m<-as.matrix(as.matrix(genus_order[ceiling(nu/2),])[1,])
}
###Z
Z<-c(rep(\"group1\",y))
i<-2 while (i <= x-1) {
###D
D<-c(D,group[,i+1])
###M
m<-c(m,m)
###Z
w<-paste(\"group\",i,sep=\"\")
Z<-c(Z,rep(w,y))
i <- i +1
}
#
M <- scale(m, center=T,scale=T) #标准化
if(x!=2){
rocdata<- data.frame(diagnosis = D, measure = M, group = Z)
p <- ggplot(rocdata, aes(m = measure , d = diagnosis ,color=group)) + geom_roc(labels=$opts{labels},labelsize=$opts{labelsize},n.cuts=$opts{ncuts}) + style_roc(major.breaks = c(0, 0.25, 0.5, 0.75, 1), theme=$opts{theme},xlab=\"1-Specificity\",ylab=\"Sensitivity\") if($opts{rocci}==T){
p <- p + geom_rocci(sig.level=$opts{siglevel})
} if($opts{facet_wrap}==T){
p <- p + facet_wrap(~ group) + theme(axis.text = element_text(size = 4))
} } if(x==2){ rocdata<- data.frame(diagnosis = D, measure = M)
p <- ggplot(rocdata, aes(m = measure , d = diagnosis )) + geom_roc(labels=$opts{labels},labelsize=$opts{labelsize},n.cuts=$opts{ncuts}) + style_roc(major.breaks = c(0, 0.25, 0.5, 0.75, 1), theme=$opts{theme},xlab=\"1-Specificity\",ylab=\"Sensitivity\") if($opts{rocci}==T){
p <- p + geom_rocci(sig.level=$opts{siglevel})
} } x<-x-1 }
} ###The Receiver:3)The receiver is any other factors
if($opts{mode}==3){ factor <-read.table(\"$opts{i}\",sep=\"\t\",head=T,check.names = F,row.names=1)
x<-length(factor[1,]) D<-group[,2] m<-factor[,1]
####Z
factor_name <-read.table(\"$opts{i}\",sep=\"\t\",check.names = F,row.names=1)
name<-as.character(factor_name[1,1])
len<-length(factor[,1])
Z<-c(rep(name,len))
i<-2
while (i <= x) {
D<-c(D,D)
m<-c(m,factor[,i])
name<-as.character(factor_name[1,i])
Z<-c(Z,rep(name,len))
i <- i +1
}
M <- scale(m, center=T,scale=T) if(x!=1){
rocdata<- data.frame(diagnosis = D, measure = M, factor = Z)
p <- ggplot(rocdata, aes(m = measure , d = diagnosis ,color=factor)) + geom_roc(labels=$opts{labels},labelsize=$opts{labelsize},n.cuts=$opts{ncuts}) + style_roc(major.breaks = c(0, 0.25, 0.5, 0.75, 1), theme=$opts{theme},xlab=\"1-Specificity\",ylab=\"Sensitivity\") if($opts{rocci}==T){
p <- p + geom_rocci(sig.level=$opts{siglevel})
} if($opts{facet_wrap}==T){
p <- p + facet_wrap(~ group) + theme(axis.text = element_text(size = 4))
} } if(x==1){ rocdata<- data.frame(diagnosis = D, measure = M)
p <- ggplot(rocdata, aes(m = measure , d = diagnosis )) + geom_roc(labels=$opts{labels},labelsize=$opts{labelsize},n.cuts=$opts{ncuts}) + style_roc(major.breaks = c(0, 0.25, 0.5, 0.75, 1), theme=$opts{theme},xlab=\"1-Specificity\",ylab=\"Sensitivity\") if($opts{rocci}==T){
p <- p + geom_rocci(sig.level=$opts{siglevel})
} } } ### Caculate the Area under the ROC curve
p.auc <- calc_auc(p)
write.table(p.auc,\"$opts{o}/roc_aucvalue.xls\",col.names=T,row.names=F,sep=\"\t\",quote=F) if($opts{mode}==1){ ###paste AUC to graph
if(x==1){ test_auc<-paste(\"AUC=\",round(p.auc[1,3] * 100, 2),\"%\",sep = \"\") p<-p + geom_text(x=0.8,y=0.1,label=test_auc,size=4) } if(x==2){
test_auc1<-paste(\"AUC_group1=\",round(p.auc[1,3] * 100, 2),\"%\",sep = \"\")
test_auc2<-paste(\"AUC_group2=\",round(p.auc[2,3] * 100, 2),\"%\",sep = \"\")
p<-p + geom_text(x=0.8,y=0.21,label=test_auc1,size=4,colour=\"black\")
p<-p + geom_text(x=0.8,y=0.15,label=test_auc2,size=4,colour=\"black\") } if(x==3){
test_auc1<-paste(\"AUC_group1=\",round(p.auc[1,3] * 100, 2),\"%\",sep = \"\")
test_auc2<-paste(\"AUC_group2=\",round(p.auc[2,3] * 100, 2),\"%\",sep = \"\")
test_auc3<-paste(\"AUC_group3=\",round(p.auc[3,3] * 100, 2),\"%\",sep = \"\")
p<-p + geom_text(x=0.8,y=0.18,label=test_auc1,size=4,colour=\"black\")
p<-p + geom_text(x=0.8,y=0.12,label=test_auc2,size=4,colour=\"black\")
p<-p + geom_text(x=0.8,y=0.06,label=test_auc3,size=4,colour=\"black\")
} } if($opts{mode}==2){ if(\"$opts{method}\"==\"chengchen.ye\"){ ###auc_name
auc_name<-as.data.frame(sort(name[,1],decreasing=F)) ###paste AUC to graph
if(x==1){ test_auc<-paste(\"AUC=\",round(p.auc[1,3] * 100, 2),\"%\",sep = \"\") p<-p + geom_text(x=0.8,y=0.1,label=test_auc,size=4) } if(x==2){
test_auc1<-paste(\"AUC\(\",as.character(auc_name[1,1]),\"\)=\",round(p.auc[1,3] * 100, 2),\"%\",sep = \"\")
test_auc2<-paste(\"AUC\(\",as.character(auc_name[2,1]),\"\)=\",round(p.auc[2,3] * 100, 2),\"%\",sep = \"\")
p<-p + geom_text(x=Inf,y=-Inf,hjust=1.2,vjust=-4,label=test_auc1,size=4,colour=\"black\")
p<-p + geom_text(x=Inf,y=-Inf,hjust=1.2,vjust=-2,label=test_auc2,size=4,colour=\"black\") } if(x==3){
test_auc1<-paste(\"AUC\(\",as.character(auc_name[1,1]),\"\)=\",round(p.auc[1,3] * 100, 2),\"%\",sep = \"\")
test_auc2<-paste(\"AUC\(\",as.character(auc_name[2,1]),\"\)=\",round(p.auc[2,3] * 100, 2),\"%\",sep = \"\")
test_auc3<-paste(\"AUC\(\",as.character(auc_name[3,1]),\"\)=\",round(p.auc[3,3] * 100, 2),\"%\",sep = \"\")
p<-p + geom_text(x=Inf,y=-Inf,hjust=1.1,vjust=-6,label=test_auc1,size=4,colour=\"black\")
p<-p + geom_text(x=Inf,y=-Inf,hjust=1.1,vjust=-4,label=test_auc2,size=4,colour=\"black\")
p<-p + geom_text(x=Inf,y=-Inf,hjust=1.1,vjust=-2,label=test_auc3,size=4,colour=\"black\")
} } if(\"$opts{method}\"!=\"chengchen.ye\"){ ###paste AUC to graph
if(x==1){ test_auc<-paste(\"AUC=\",round(p.auc[1,3] * 100, 2),\"%\",sep = \"\") p<-p + geom_text(x=0.8,y=0.1,label=test_auc,size=4) } if(x==2){
test_auc1<-paste(\"AUC_group1=\",round(p.auc[1,3] * 100, 2),\"%\",sep = \"\")
test_auc2<-paste(\"AUC_group2=\",round(p.auc[2,3] * 100, 2),\"%\",sep = \"\")
p<-p + geom_text(x=0.8,y=0.3,label=test_auc1,size=4,colour=\"black\")
p<-p + geom_text(x=0.8,y=0.25,label=test_auc2,size=4,colour=\"black\") } if(x==3){
test_auc1<-paste(\"AUC_group1=\",round(p.auc[1,3] * 100, 2),\"%\",sep = \"\")
test_auc2<-paste(\"AUC_group2=\",round(p.auc[2,3] * 100, 2),\"%\",sep = \"\")
test_auc3<-paste(\"AUC_group3=\",round(p.auc[3,3] * 100, 2),\"%\",sep = \"\")
p<-p + geom_text(x=0.8,y=0.22,label=test_auc1,size=4,colour=\"black\")
p<-p + geom_text(x=0.8,y=0.16,label=test_auc2,size=4,colour=\"black\")
p<-p + geom_text(x=0.8,y=0.1,label=test_auc3,size=4,colour=\"black\")
}
}
} if($opts{mode}==3){ ###auc_name auc_name<-as.data.frame(sort(factor_name[1,],decreasing=F)) ###paste AUC to graph
if(x==1){ test_auc<-paste(\"AUC=\",round(p.auc[1,3] * 100, 2),\"%\",sep = \"\") p<-p + geom_text(x=0.8,y=0.1,label=test_auc,size=4) } if(x==2){
test_auc1<-paste(\"AUC_\",as.character(auc_name[1,1]),\"=\",round(p.auc[1,3] * 100, 2),\"%\",sep = \"\")
test_auc2<-paste(\"AUC_\",as.character(auc_name[1,2]),\"=\",round(p.auc[2,3] * 100, 2),\"%\",sep = \"\")
p<-p + geom_text(x=Inf,y=-Inf,hjust=1.2,vjust=-4,label=test_auc1,size=4,colour=\"black\")
p<-p + geom_text(x=Inf,y=-Inf,hjust=1.2,vjust=-2,label=test_auc2,size=4,colour=\"black\") } if(x==3){
test_auc1<-paste(\"AUC_\",as.character(auc_name[1,1]),\"=\",round(p.auc[1,3] * 100, 2),\"%\",sep = \"\")
test_auc2<-paste(\"AUC_\",as.character(auc_name[1,2]),\"=\",round(p.auc[2,3] * 100, 2),\"%\",sep = \"\")
test_auc3<-paste(\"AUC_\",as.character(auc_name[1,3]),\"=\",round(p.auc[3,3] * 100, 2),\"%\",sep = \"\")
p<-p + geom_text(x=0.8,y=0.18,label=test_auc1,size=4,colour=\"black\")
p<-p + geom_text(x=0.8,y=0.12,label=test_auc2,size=4,colour=\"black\")
p<-p + geom_text(x=0.8,y=0.06,label=test_auc3,size=4,colour=\"black\")
} } pdf(\"$opts{o}/roc_curve.pdf\",width=$opts{w},height=$opts{h})
p
dev.off() "; `R --restore --no-save < $opts{o}/roc.cmd.r`;
ROC的更多相关文章
- ROC曲线、PR曲线
在论文的结果分析中,ROC和PR曲线是经常用到的两个有力的展示图. 1.ROC曲线 ROC曲线(receiver operating characteristic)是一种对于灵敏度进行描述的功能图像. ...
- ROC & AUC笔记
易懂:http://alexkong.net/2013/06/introduction-to-auc-and-roc/ 分析全面但难懂:http://mlwiki.org/index.php/ROC_ ...
- 精确率与召回率,RoC曲线与PR曲线
在机器学习的算法评估中,尤其是分类算法评估中,我们经常听到精确率(precision)与召回率(recall),RoC曲线与PR曲线这些概念,那这些概念到底有什么用处呢? 首先,我们需要搞清楚几个拗口 ...
- 【数据挖掘】朴素贝叶斯算法计算ROC曲线的面积
题记: 近来关于数据挖掘学习过程中,学习到朴素贝叶斯运算ROC曲线.也是本节实验课题,roc曲线的计算原理以及如果统计TP.FP.TN.FN.TPR.FPR.ROC面积等等.往往运用 ...
- PR曲线,ROC曲线,AUC指标等,Accuracy vs Precision
作为机器学习重要的评价指标,标题中的三个内容,在下面读书笔记里面都有讲: http://www.cnblogs.com/charlesblc/p/6188562.html 但是讲的不细,不太懂.今天又 ...
- 如何利用Matlab进行ROC分析
ROC曲线基本知识: 判断分类器的工作效率需要使用召回率和准确率两个变量. 召回率:Recall,又称"查全率", 准确率:Precision,又称"精度".& ...
- 机器学习之分类器性能指标之ROC曲线、AUC值
分类器性能指标之ROC曲线.AUC值 一 roc曲线 1.roc曲线:接收者操作特征(receiveroperating characteristic),roc曲线上每个点反映着对同一信号刺激的感受性 ...
- [zz] ROC曲线
wiki https://zh.wikipedia.org/wiki/ROC%E6%9B%B2%E7%BA%BF 在信号检测理论中,接收者操作特征曲线(receiver operating chara ...
- ROC曲线、AUC、Precision、Recall、F-measure理解及Python实现
本文首先从整体上介绍ROC曲线.AUC.Precision.Recall以及F-measure,然后介绍上述这些评价指标的有趣特性,最后给出ROC曲线的一个Python实现示例. 一.ROC曲线.AU ...
- ROC曲线与AUC值
本文根据以下文章整理而成,链接: (1)http://blog.csdn.net/ice110956/article/details/20288239 (2)http://blog.csdn.net/ ...
随机推荐
- AspNet5 Changes to [Activate] in beta-5
最近在看AspNet Core相关的文章,其中有个TagHelper,看上善若水的博客“关于TagHelper的那些事”,其中有一句 下面来自上善若水的博客原文: 我们知道ASP.NET 5实现了依赖 ...
- Codeforces 455 B. A Lot of Games
\(>Codeforces \space 455 B. A Lot of Games<\) 题目大意 : 有两个人在玩游戏,一共玩 \(k\) 轮,每一轮的一开始有一个空串,双方每一回合需 ...
- HDU 6039 Gear Up(线段树+并查集)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6039 [题目大意] 给出一些齿轮,有些齿轮是边相连,也就是拥有相同的线速度, 有的齿轮是轴相连,也 ...
- BZOJ 1221 [HNOI2001] 软件开发(费用流)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1221 [题目大意] 每天对毛巾都有一定的需求ni,每天可以花f价值每条购买毛巾, 当天 ...
- 【模拟退火】poj1379 Run Away
题意:平面上找一个点,使得其到给定的n个点的距离的最小值最大. 模拟退火看这篇:http://www.cnblogs.com/autsky-jadek/p/7524208.html 这题稍有不同之处仅 ...
- python安装BeautifulSoup
1.先下载pip https://pypi.python.org/pypi/pip 安装pip cd到路径 python setuo.py install 2.添加目录到环境变量中 xxx\Pytho ...
- php中NULL、false、0、" "有何区别?
php中很多还不懂php中0,"",null和false之间的区别,这些区别有时会影响到数据判断的正确性和安全性,给程序的测试运行造成很多麻烦.先看一个例子: <? $str ...
- 8.8.8.8和8.8.4.4 DNS域名解析服务器
而Google表示推出免费DNS服务的主要目的就是为了改进网络浏览速度.改善网络用户的浏览体验,为此Google自行开发的软件对DNS服务器技术进行了改进,通过采用预获取技术提升性能,同时保证了DNS ...
- Docker从12升级到17ce
先卸载 yum remove docker* yum remove container-selinux--.el7.centos.x86_64 安装 sudo yum install -y yum-u ...
- python中常用的推导(字典推导和列表推导)
在python开发中经常需要书写这样的代码 result = list() for data in datas: if data not in ['a', 'b']: result.append(da ...