How to change Neural Network performance from MSE to MAE?

3 views (last 30 days)
Is it possible to run a neural network that uses MAE instead of MSE?
I am trying to create a neural network that describes the relationship between numerous factors and the binary outcome. This is the code that I have written so far.
clear all; format compact
load ShotData;
num_reps=20; C=[2 4 6]; n=length(A);
I = A(1:n,C)'; T = B(1:n)';
tic; for k=1:num_reps
net = feedforwardnet(10,'trainscg'); net = train(net,I,T); a = net(I);
e = T - a; perf(1:num_reps) = mae(e)';
end
perf_final=mean(perf); z=toc;
I previously analyzed the data using logistic regression and then computed MAE. In order to be about to compare methods I need help to create a neural network that uses MAE.

Accepted Answer

Greg Heath
Greg Heath on 10 Feb 2014
clear all;
format compact
load ShotData; % Contains A and B.
%What are size(A) and size(B)?
[rA cA] = size(A)
[rB cB ] = size(B)
num_reps = 20;
C = [2 4 6];
n = length(A); % Improper syntax if A is 2-dimensional;
I = A(1:n,C)';
T = B(1:n)';
net = feedforwardnet(10,'trainscg');
net.performFcn = 'mae';
tic;
for k = 1:num_reps
net = configure(net,I,T); % Initialize weights
[ net tr a e ] = train(net,I,T);
%a = net(I); e = T - a; % Unnecessary see above
%perf(1:num_reps) = mae(e)'; % Improper syntax
perf(k,1) = mae(e);
end
perf_final = mean(perf);
z = toc;
% 1. You didn't take into account that some of the designs may have not converged to a low % minimum because of poor initial weights. Discard useless designs before taking mean. Can use % min, median, mean, std, and max to discard outliers.
% 2. You did not take into account the default trn/val/tst division. The corresponding indices % are contained in tr. Look at the results of the command
tr = tr
Thank you for formally accepting my answer
Greg

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!