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) 概述 概念:是对其他算法进行组合的一种形式. 通俗来说: 当做重 ...
随机推荐
- 懒散惯了,该收收心了,两天了,封装了一个R0下注册表类
写得乱七八糟. 看着自己写的代码,感觉都不像自己了. 我写的代码,风格这么差了么?思路这么乱了么? 我写代码这么累么? 不像以前的我了... 这段时间,太懒散了... 该继续努 ...
- 怎么解决VirtualBox无法安装增强工具
点击「设备」-「安装增强功能」,然后就弹出下面这个东西,百度和 bing 了很久,终于解决啦~ Unable to insert the virtual optical disk D:\Program ...
- pandas一些基本操作(DataFram和Series)_3
import pandas as pd;import numpy as np#通过一维数组创建Chinese = np.array([89,87,86])print(Chinese)print(pd. ...
- python基础-三元表达式/列表推导式/生成器表达式
1.三元表达式:如果成立返回if前的内容,如果不成立返回else的内容 name=input('姓名>>: ') res='SB' if name == 'alex' else 'NB' ...
- Werkzeug库——wrappers模块
Werkzeug库中的wrappers模块主要对request和response进行封装.request包含了客户端发往服务器的所有请求信息,response包含了web应用返回给客户端的所有信息.w ...
- 通过url方式传递中文参数时出现的中文乱码问题的处理
1.通过url将参数[会有中文的情况]传递到另外一个页面: window.location.href = "/XXXX/XXXX?searchcontent=" + Content ...
- PHP基于openssl实现的非对称加密操作
使用非对称加密主要是借助openssl的公钥和私钥,用公钥加密私钥解密,或者私钥加密公钥解密. 1.安装openssl和php的openssl扩展 2.生成私钥:openssl genrsa 用于生成 ...
- vim编辑器操作②
本文主要介绍vim的常用编辑命令: 字符编辑: x:删除光标所在处的字符: #x:删除光标所在处起始的#个字符: 替换命令: r:替换光标所在处的字符: rCHAR; 例如:替换list中的l为大写L ...
- LUOGU P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper
题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better k ...
- ssh 连接vps
默认端口22 ssh root@194.10.10.10 特定端口xxx 上面命令后面加上 "-p xxx" 就可以了