% Weird data set:
The data does not represent points from reasonable function. The target says" Regardless of the input, if the output is 0, your error will only be 3.33%".
Looking at an escalation of models (H=0:9) shows that the Linear model (H=0, NN with no hidden layer) is the best with a coefficient of determination (Wikipedia/R-squared) of only 0.0264. It is only slightly better than the constant output = 0 model.
close all, clear all, clc
N =30
input = [0 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1];
target = [ 1, zeros( 1,N-1)];
% The simplest model is the constant output model that outputs the mean of the target regardless of the input.
y00 = (1/N)*ones(1,N);
e00 = target-y00; ;
MSE00 = mse(target-y00)
% The next simplest is the linear model
W0 = target/[ ones(1,N) ; input ]
y0 = W0 * [ ones(1,N) ; input ];
e0 = target-y0; ;
MSE0 = mse(target-y0)
R20 = 1 - MSE0/MSE00
% Neural Model
[ I N ] = size(input)
[ O N ] = size(target)
Neq = N*O
% No overfitting Neq > Nw==> H <= Hub (upper bound)
Hub = -1+ceil( (Neq-O) / ( I+O+1) )
Hmax = 9
dH = 1
Hmin = 0
numH = length(Hmin:dH:Hmax)
Ntrials = 10
rng(0)
j=0
for h=Hmin:dH:Hmax
j=j+1
if h==0
net = patternnet([]);
Nw = (I+1)*O
else
net = patternnet(h);
Nw = (I+1)*h+(h+1)*O
end
for i=1:Ntrials
net = configure(net, input,target);
net.divideFcn = 'dividetrain';
[net tr y e ] = train(net,input,target);
R2(i,j) = 1 - mse(e)/MSE00;
end
end
R2 = R2
Hope this helps.
*Thank you for formally accepting my answer *
Greg
Best Answer