资源简介
绘制roc曲线求AUC值,用以评价分类指标
代码片段和文件信息
function auc = plotroc(yxparams)
%plotroc draws the recevier operating characteristic(ROC) curve.
%
%auc = plotroc(training_label training_instance [ libsvm_options -v cv_fold])
% Use cross-validation on training data to get decision values and plot ROC curve.
%
%auc = plotroc(testing_label testing_instance model)
% Use the given model to predict testing data and obtain decision values
% for ROC
%
% Example:
%
% load(‘heart_scale.mat‘);
% plotroc(heart_scale_label heart_scale_inst‘-v 5‘);
%
% [yx] = libsvmread(‘heart_scale‘);
% model = svmtrain(yx);
% plotroc(yxmodel);
rand(‘state‘0); % reset random seed
if nargin < 2
help plotroc
return
elseif isempty(y) | isempty(x)
error(‘Input data is empty‘);
elseif sum(y == 1) + sum(y == -1) ~= length(y)
error(‘ROC is only applicable to binary classes with labels 1 -1‘); % check the trainig_file is binary
elseif exist(‘params‘) && ~ischar(params)
model = params;
[predict_labelmsedeci] = svmpredict(yxmodel); % the procedure for predicting
auc = roc_curve(deci*model.Label(1)y);
else
if ~exist(‘params‘)
params = [];
end
[paramfold] = proc_argv(params); % specify each parameter
if fold <= 1
error(‘The number of folds must be greater than 1‘);
else
[decilabel_y] = get_cv_deci(yxparamfold); % get the value of decision and label after cross-calidation
auc = roc_curve(decilabel_y); % plot ROC curve
end
end
end
function [resufold] = proc_argv(params)
resu=params;
fold=5;
if ~isempty(params) && ~isempty(regexp(params‘-v‘))
[fold_valfold_startfold_end] = regexp(params‘-v\s+\d+‘‘match‘‘start‘‘end‘);
if ~isempty(fold_val)
[temp1fold] = strread([fold_val{:}]‘%s %u‘);
resu([fold_start:fold_end]) = [];
else
error(‘Number of CV folds must be specified by “-v cv_fold“‘);
end
end
end
function [decilabel_y] = get_cv_deci(prob_yprob_xparamnr_fold)
l=length(prob_y);
deci = ones(l1);
label_y = ones(l1);
rand_ind = randperm(l);
for i=1:nr_fold % Cross training : folding
test_ind=rand_ind([floor((i-1)*l/nr_fold)+1:floor(i*l/nr_fold)]‘);
train_ind = [1:l]‘;
train_ind(test_ind) = [];
model = svmtrain(prob_y(train_ind)prob_x(train_ind:)param);
[predict_labelmsesubdeci] = svmpredict(prob_y(test_ind)prob_x(test_ind:)model);
deci(test_ind) = subdeci.*model.Label(1);
label_y(test_ind) = prob_y(test_ind);
end
end
function auc = roc_curve(decilabel_y)
[valind] = sort(deci‘descend‘);
roc_y = label_y(ind);
stack_x = cumsum(roc_y == -1)/sum(roc_y == -1);
stack_y = cumsum(roc_y == 1)/sum(roc_y == 1);
auc = sum((stack_x(2:length(roc_y)1)-stack_x(1:length(roc_y)-11)).*stack_y(2:length(roc_y)1))
%Comment the above lines if using perfcurve of statistics toolbox
%[stack_xstack_ythreauc]=perfcurve(label_ydeci1);
len=length(stack_x);
l=1;
for i=1:10:len
stack_x1(l)= st
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3217 2013-06-01 16:30 plotroc.m
----------- --------- ---------- ----- ----
3217 1
- 上一篇:标准四步相移条纹
- 下一篇:异步电机矢量控制仿真
相关资源
- Duda模式分类Pattern Classification MATLAB 代
- Matlab分类准确率代码
- 遗传算法用于模式分类的特征选择
- 多类分类 目标检测
- 水果识别和分类
- Analysis of micro Doppler signatures 微多普勒
- AdaBoost 分类器训练学习
- signal processing matlab 信号处理中需要的
- BP Classification 基于matlab神经网络的遥
- FCM for EEG 模糊C均值脑电分类并使用了
- radar process toolbox 雷达信号处理的mat
- PRACHDETECTION
- face recognition 稀疏表示人脸分类与识别
- svm分类器的汉语声调识别
- 神经网络与adaboost的强分类器
- 正态分布模式的贝叶斯分类
- pso优化bp神经网络
- 随机子空间集成分类器
- ELM kernel 基于极限学习机的不平衡数据
- BP神经网络的算法实现分类功能
- 卷积神经网络的模式分类器
- 支持向量机SVM机器学习方法
- Digital signal processing
- 基于半监督的svm的图像分类
- 基于多任务联合稀疏表示的的视觉分
- 计算聚类算法评价指标之一
- matlab植物叶片分类
- LBP方法
- ELM算法进行遥感图像分类
- 极化SAR图像分类数据
评论
共有 条评论