-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprt_plot_prediction_errors.m
More file actions
91 lines (79 loc) · 2.85 KB
/
Copy pathprt_plot_prediction_errors.m
File metadata and controls
91 lines (79 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function prt_plot_prediction_errors(PRT, model, fold, marker_size, axes_handle)
% Function to plot the prediction error plot that appears on prt_ui_results.
%
% FORMAT prt_plot_prediction_errors(PRT, model, fold, marker_size, axes_handle)
% Inputs:
% PRT - data/design/model structure (it needs to contain
% at least one estimated model).
% model - the number of the model that will be ploted
% fold - the number of the fold
% marker_size - (Optional) the size of the markers in the plot,
% the default is 7
% axes_handle - (Optional) axes where the plot will be displayed
%
% Output:
% None
%__________________________________________________________________________
% Copyright (C) 2018 Machine Learning & Neuroimaging Laboratory
% Written by J. Schrouff based prt_plot_prediction by M.J. Rosa
% $Id: prt_plot_prediction.m 706 2013-06-07 14:33:34Z cphillip $
nfold = length(PRT.model(model).output.fold);
fVals = [];
targets = [];
for f = 1:nfold
targets = [targets;PRT.model(model).output.fold(f).targets];
fVals = [fVals;PRT.model(model).output.fold(f).predictions];
end
predErr = targets - fVals ;
% Keep scale consistent across folds
maxErr = max(predErr);
minErr = min(predErr);
%Defined the marker size, if no value is given
if ~exist('marker_size', 'var') || isempty(marker_size)
marker_size = 7;
end
%If no axes_handle is given, create a new window
if ~exist('axes_handle', 'var')
figure;
axes_handle = axes;
else
set(axes_handle, 'XScale','linear');
end
% Prepare axes
cla(axes_handle, 'reset');
rotate3d off
colorbar('peer',axes_handle,'off')
set(axes_handle,'Color',[1,1,1])
hold on
% Plot prediction errors
if fold == 1
foldlabels = 1:nfold;
for f = 2:nfold+1
targets = PRT.model(model).output.fold(f-1).targets;
fVals = PRT.model(model).output.fold(f-1).predictions;
predError = targets - fVals;
yc = (f-1)*ones(length(predError),1);
pl = plot(axes_handle,predError,yc,'kx','MarkerSize',marker_size);
end
else
foldlabels = fold-1;
targets = PRT.model(model).output.fold(foldlabels).targets;
fVals = PRT.model(model).output.fold(foldlabels).predictions;
predError = targets - fVals;
yc = (fold-1)*ones(length(predError),1);
pl = plot(axes_handle,predError,yc,'kx','MarkerSize',marker_size);
end
y = [0:nfold+1]';
x = zeros(nfold+2,1);
plot(axes_handle,x,y,'--','Color',[1 1 1]*.6);
xlim(axes_handle,[minErr-0.1*(abs(minErr)) maxErr-0.1*(abs(maxErr))]);
ylim(axes_handle,[0 nfold+1.3]);
xlabel(axes_handle,'Prediction Errors','FontWeight','bold');
h=ylabel(axes_handle,'fold','FontWeight','bold');
set(h,'Rotation',90)
set(axes_handle,'YTick',foldlabels)
hold(axes_handle,'off');
set(axes_handle,'Color',[1,1,1],'Visible','on')
title(axes_handle,'')
hold off
end