plotroc.m
function out1 = plotroc(varargin)
%PLOTROC Plot receiver operating characteristic.
%
% <a href="matlab:doc plotroc">plotroc</a>(targets,outputs) takes target data in 1-of-N form (each column
% vector is all zeros with a single 1 indicating the class number), and
% output data and generates a receiver operating characteristic plot.
%
% The best classifications will show the receiver operating line hugging
% the left and top sides of the plots axis.
%
% <a href="matlab:doc plotroc">plotroc</a>(targets,1,outputs1,'name1',targets2,outputs2,names2,...)
% generates a variable number of confusion plots in one figure.
%
% Here a pattern recognition network is trained and its accuracy plotted:
%
% [x,t] = <a href="matlab:doc simpleclass_dataset">simpleclass_dataset</a>;
% net = <a href="matlab:doc patternnet">patternnet</a>(10);
% net = <a href="matlab:doc train">train</a>(net,x,t);
% y = net(x);
% <a href="matlab:doc plotroc">plotroc</a>(t,y);
%
% See also roc, plotconfusion, ploterrhist, plotregression. % Copyright 2010-2012 The MathWorks, Inc. %% =======================================================
% BOILERPLATE_START
% This code is the same for all Transfer Functions. persistent INFO;
if isempty(INFO), INFO = get_info; end
if nargin == 0
fig = nnplots.find_training_plot(mfilename);
if nargout > 0
out1 = fig;
elseif ~isempty(fig)
figure(fig);
end
return;
end
in1 = varargin{1};
if ischar(in1)
switch in1
case 'info',
out1 = INFO;
case 'suitable'
[args,param] = nnparam.extract_param(varargin,INFO.defaultParam);
[net,tr,signals] = deal(args{2:end});
update_args = standard_args(net,tr,signals);
unsuitable = unsuitable_to_plot(param,update_args{:});
if nargout > 0
out1 = unsuitable;
elseif ~isempty(unsuitable)
for i=1:length(unsuitable)
disp(unsuitable{i});
end
end
case 'training_suitable'
[net,tr,signals,param] = deal(varargin{2:end});
update_args = training_args(net,tr,signals,param);
unsuitable = unsuitable_to_plot(param,update_args{:});
if nargout > 0
out1 = unsuitable;
elseif ~isempty(unsuitable)
for i=1:length(unsuitable)
disp(unsuitable{i});
end
end
case 'training'
[net,tr,signals,param] = deal(varargin{2:end});
update_args = training_args(net,tr,signals);
fig = nnplots.find_training_plot(mfilename);
if isempty(fig)
fig = figure('visible','off','tag',['TRAINING_' upper(mfilename)]);
plotData = setup_figure(fig,INFO,true);
else
plotData = get(fig,'userdata');
end
set_busy(fig);
unsuitable = unsuitable_to_plot(param,update_args{:});
if isempty(unsuitable)
set(0,'CurrentFigure',fig);
plotData = update_plot(param,fig,plotData,update_args{:});
update_training_title(fig,INFO,tr)
nnplots.enable_plot(plotData);
else
nnplots.disable_plot(plotData,unsuitable);
end
fig = unset_busy(fig,plotData);
if nargout > 0, out1 = fig; end
case 'close_request'
fig = nnplots.find_training_plot(mfilename);
if ~isempty(fig),close_request(fig); end
case 'check_param'
out1 = ''; % TODO
otherwise,
try
out1 = eval(['INFO.' in1]);
catch me, nnerr.throw(['Unrecognized first argument: ''' in1 ''''])
end
end
else
[args,param] = nnparam.extract_param(varargin,INFO.defaultParam);
update_args = standard_args(args{:});
if ischar(update_args)
nnerr.throw(update_args);
end
[plotData,fig] = setup_figure([],INFO,false);
unsuitable = unsuitable_to_plot(param,update_args{:});
if isempty(unsuitable)
plotData = update_plot(param,fig,plotData,update_args{:});
nnplots.enable_plot(plotData);
else
nnplots.disable_plot(plotData,unsuitable);
end
set(fig,'visible','on');
drawnow;
if nargout > 0, out1 = fig; end
end
end function set_busy(fig)
set(fig,'userdata','BUSY');
end function close_request(fig)
ud = get(fig,'userdata');
if ischar(ud)
set(fig,'userdata','CLOSE');
else
delete(fig);
end
drawnow;
end function fig = unset_busy(fig,plotData)
ud = get(fig,'userdata');
if ischar(ud) && strcmp(ud,'CLOSE')
delete(fig);
fig = [];
else
set(fig,'userdata',plotData);
end
drawnow;
end function tag = new_tag
tagnum = 1;
while true
tag = [upper(mfilename) num2str(tagnum)];
fig = nnplots.find_plot(tag);
if isempty(fig), return; end
tagnum = tagnum+1;
end
end function [plotData,fig] = setup_figure(fig,info,isTraining)
PTFS = nnplots.title_font_size;
if isempty(fig)
fig = get(0,'CurrentFigure');
if isempty(fig) || strcmp(get(fig,'nextplot'),'new')
if isTraining
tag = ['TRAINING_' upper(mfilename)];
else
tag = new_tag;
end
fig = figure('visible','off','tag',tag);
if isTraining
set(fig,'CloseRequestFcn',[mfilename '(''close_request'')']);
end
else
clf(fig);
set(fig,'tag','');
set(fig,'tag',new_tag);
end
end
set(0,'CurrentFigure',fig);
ws = warning('off','MATLAB:Figure:SetPosition');
plotData = setup_plot(fig);
warning(ws);
if isTraining
set(fig,'nextplot','new');
update_training_title(fig,info,[]);
else
set(fig,'nextplot','replace');
set(fig,'name',[info.name ' (' mfilename ')']);
end
set(fig,'NumberTitle','off','toolbar','none');
plotData.CONTROL.text = uicontrol('parent',fig,'style','text',...
'units','normalized','position',[0 0 1 1],'fontsize',PTFS,...
'fontweight','bold','foreground',[0.7 0 0]);
set(fig,'userdata',plotData);
end function update_training_title(fig,info,tr)
if isempty(tr)
epochs = '0';
stop = '';
else
epochs = num2str(tr.num_epochs);
if isempty(tr.stop)
stop = '';
else
stop = [', ' tr.stop];
end
end
set(fig,'name',['Neural Network Training ' ...
info.name ' (' mfilename '), Epoch ' epochs stop]);
end % BOILERPLATE_END
%% ======================================================= function info = get_info
info = nnfcnPlot(mfilename,'Receiver Operating Characteristic',7.0,[]);
end function args = training_args(net,tr,data)
yall = nncalc.y(net,data.X,data.Xi,data.Ai);
y = {yall};
t = {gmultiply(data.train.mask,data.T)};
names = {'Training'};
if ~isempty(data.val.enabled)
y = [y {yall}];
t = [t {gmultiply(data.val.mask,data.T)}];
names = [names {'Validation'}];
end
if ~isempty(data.test.enabled)
y = [y {yall}];
t = [t {gmultiply(data.test.mask,data.T)}];
names = [names {'Test'}];
end
if length(t) >= 2
t = [t {data.T}];
y = [y {yall}];
names = [names {'All'}];
end
args = {t y names};
end function args = standard_args(varargin)
if nargin < 2
args = 'Not enough input arguments.';
elseif (nargin > 2) && (rem(nargin,3) ~= 0)
args = 'Incorrect number of input arguments.';
elseif nargin == 2
% (t,y)
t = { nntype.data('format',varargin{1}) };
y = { nntype.data('format',varargin{2}) };
names = {''};
args = {t y names};
else
% (t1,y1,name1,...)
% TODO - Check data is consistent
count = nargin/3;
t = cell(1,count);
y = cell(1,count);
names = cell(1,count);
for i=1:count
t{i} = nntype.data('format',varargin{i*3-2});
y{i} = nntype.data('format',varargin{i*3-1});
names{i} = varargin{i*3};
end
param.outputIndex = 1;
args = {t y names};
end
end function plotData = setup_plot(fig)
plotData.numSignals = 0;
end function fail = unsuitable_to_plot(param,t,y,names)
fail = '';
t1 = t{1};
if numsamples(t1) == 0
fail = 'The target data has no samples to plot.';
elseif numtimesteps(t1) == 0
fail = 'The target data has no timesteps to plot.';
elseif sum(numelements(t1)) == 0
fail = 'The target data has no elements to plot.';
end
end function plotData = update_plot(param,fig,plotData,tt,yy,names) t = tt{1};
numSignals = length(names);
numClasses = size(t{1},1); % Rebuild figure
if (plotData.numSignals ~= numSignals) || (plotData.numClasses ~= numClasses)
set(fig,'nextplot','replace');
plotData.numSignals = numSignals;
plotData.numClasses = numClasses;
plotData.axes = zeros(1,numSignals);
colors = nncolor.ncolors(numClasses);
plotcols = ceil(sqrt(numSignals));
plotrows = ceil(numSignals/plotcols);
for plotrow=1:plotrows
for plotcol=1:plotcols
i = (plotrow-1)*plotcols+plotcol;
if (i<=numSignals)
a = subplot(plotrows,plotcols,i);
cla(a)
set(a,'dataaspectratio',[1 1 1]);
set(a,'xlim',[0 1]);
set(a,'ylim',[0 1]);
hold on
axisdata = [];
axisdata.lines = zeros(1,numClasses);
for j=1:numClasses
c = colors(j,:);
line([0 1],[0 1],'linewidth',2,'color',[1 1 1]*0.8);
axisdata.lines(j) = line([0 1],[0 1],'linewidth',2,'Color',c);
end
if ~isempty(names{1})
titleStr = [names{i} ' ROC'];
else
titleStr = 'ROC';
end
title(a,titleStr);
xlabel(a,'False Positive Rate');
ylabel(a,'True Positive Rate');
plotData.axes(i) = a;
set(a,'userdata',axisdata);
if (i==1) && (numClasses > 1)
labels = cell(1,numClasses);
for ii=1:numClasses, labels{ii} = ['Class ' num2str(ii)]; end
legend(axisdata.lines,labels{:})
end
end
end
end
screenSize = get(0,'ScreenSize');
screenSize = screenSize(3:4);
windowSize = 700 * [1 (plotrows/plotcols)];
pos = [(screenSize-windowSize)/2 windowSize];
set(fig,'position',pos);
end % Update details
for i=1:numSignals
y = yy{i}; if iscell(y), y = cell2mat(y); end
t = tt{i}; if iscell(t), t = cell2mat(t); end
[tpr,fpr] = roc(t,y);
if ~iscell(tpr)
tpr = {tpr};
fpr = {fpr};
end
a = plotData.axes(i);
axisdata = get(a,'userdata');
for j=1:numClasses
set(axisdata.lines(j),'xdata',[0 fpr{j} 1],'ydata',[0 tpr{j} 1]);
end
end
end
plotroc.m的更多相关文章
- svm训练显示信息说明
现简单对屏幕回显信息进行说明: #iter 为迭代次数, nu 与前面的操作参数 -n nu 相同, obj 为 SVM 文件转换为的二次规划求解得到的最小值, rho 为判决函数的常数项 b ...
- 机器学习实战4:Adaboost提升:病马实例+非均衡分类问题
Adaboost提升算法是机器学习中很好用的两个算法之一,另一个是SVM支持向量机:机器学习面试中也会经常提问到Adaboost的一些原理:另外本文还介绍了一下非平衡分类问题的解决方案,这个问题在面试 ...
- ROC曲线绘制
ROC 曲线绘制 个人的浅显理解:1.ROC曲线必须是针对连续值输入的,通过选定不同的阈值而得到光滑而且连续的ROC曲线,故通常应用于Saliency算法评价中,因为可以选定0~255中任意的值进行阈 ...
- 从TP、FP、TN、FN到ROC曲线、miss rate、行人检测评估
从TP.FP.TN.FN到ROC曲线.miss rate.行人检测评估 想要在行人检测的evaluation阶段要计算miss rate,就要从True Positive Rate讲起:miss ra ...
- paper 75:使用MATLAB的神经网络工具箱创建神经网络
% 生成训练样本集 clear all; clc; P=[110 0.807 240 0.2 15 1 18 2 1.5; 110 2.865 240 0.1 15 2 12 1 2; 110 2.5 ...
- MATLAB画ROC曲线,及计算AUC值
根据决策值和真实标签画ROC曲线,同时计算AUC的值 步骤: 根据决策值和真实标签画ROC曲线,同时计算AUC的值: 计算算法的决策函数值deci 根据决策函数值deci对真实标签y进行降序排序,得到 ...
- Linux下的Libsvm使用历程录
原文:http://blog.csdn.net/meredith_leaf/article/details/6714144 Linux下的Libsvm使用历程录 首先下载Libsvm.Python和G ...
- MATLAB的神经网络工具箱介绍
一.使用matlab2010b以后的版本会有完整的神经网络工具箱,使用nnstart可以调出toolbox,然后选择需要的功能,导入数据,选择训练参数和每层神经元个数,最后训练会输出网络与结果. 二. ...
- 【机器学习实战】第7章 集成方法 ensemble method
第7章 集成方法 ensemble method 集成方法: ensemble method(元算法: meta algorithm) 概述 概念:是对其他算法进行组合的一种形式. 通俗来说: 当做重 ...
随机推荐
- 实例测试java的Integer转String的效率问题1.8
原文链接:https://blog.csdn.net/chicaohun7473/article/details/100851373 查看String源码时,读到源码的toString方法时,打算探究 ...
- C++给组合框控件(Combo box)加变量后不能运行
是一个BUG,找出你程序存储的位置,打开一个Debug的文件夹,将除.res文件之外的所有文件删除,然后运行,就可以了!!
- FPFH+ICP点云配准
A, UniformSampling降噪 B, ISS计算关键点, FPFH特征 在FeatureCloud::setInputCloud中读入点云,并调用processInput进行处理: proc ...
- 解决使用mybatis模糊查询为空的问题
解决方法: 在数据库配置的url后添加?useUnicode=true&characterEncoding=utf-8 参考: https://blog.csdn.net/IT_private ...
- Luogu P1401 城市(二分+网络流)
P1401 城市 题意 题目描述 N(2<=n<=200)个城市,M(1<=m<=40000)条无向边,你要找T(1<=T<=200)条从城市1到城市N的路,使得最 ...
- scanf读入有空格字符串
当不支持gets时,getline又比较慢,可以使用scarf("%[^\n]s", str);来读入以换行表示读完的字符串,其中[^char]表示以char为结束.
- html常用标签详解3-a标签
a标签 1.a标签的属性 a标签属于行内元素标签,双标签<a></a> href:a标签的跳转地址 target:打开方式(_self自身:_blank:新窗口) title: ...
- 第五章 Odoo 12开发之导入、导出以及模块数据
大多数Odoo 模块的定义,如用户界面和安全规则,实际是存储在对应数据表中的数据记录.模块中的 XML 和 CSV 文件不是 Odoo 应用运行时使用,而是载入数据表的手段.正是因为这个原因,Odoo ...
- sql join 的一次小使用
表为: 列名:站号,模式名,偏差,日期,要素 试图查询每个站中最小的那个偏差的模式名 create table B as SELECT stationid,min(abserror) as minab ...
- c语言学习笔记 关于double
今天做了个简单的例子,由于没有使用正确的数据类型导致出错,下面是记录 #include <stdio.h> int main(void){ int i; double sum; doubl ...