Trying reduce overfitting of training plot

Previoulsy tried running network with two sets of data however was not succesful. Achieved progres with running one per dataset however want to know how I can reduce any overfitting even though the validation accuracy seems good.
clc; clear all; close all;
%Import/Upload data
load Projectdata.mat
% change to label vector
CS1 = categories(categorical(INS_output));
Z2 = [];
for i = 1 : length(INS_output)
Z2(i,1) = find(INS_output(i)==CS1);
end
Yo2 = INS_output;
INS_output = Z2;
%transposing insulin data
InsulinReadings_T = InsulinReadings';
rand('seed', 0)
ind = randperm(size(InsulinReadings_T, 1));
InsulinReadings_T = InsulinReadings_T(ind, :);
INS_output = INS_output(ind);
InsulinReadings_train = InsulinReadings_T;
train_InsulinReadings = InsulinReadings_train(1:84,:);
train_INS_output = INS_output(1:84);
InsulinReadingsTrain=(reshape(train_InsulinReadings',[1758,1,1,84]));
val_InsulinReadings = InsulinReadings_train(85:102,:);
val_INS_output = INS_output(85:102);
InsulinReadingsVal=(reshape(val_InsulinReadings', [1758,1,1,18]));
test_InsulinReadings = InsulinReadings_train(103:120,:);
test_INS_output = INS_output(103:120);
InsulinReadingsTest=(reshape(test_InsulinReadings', [1758,1,1,18]));
%% NETWORK ARCHITECTURE
layers = [imageInputLayer([1758 1 1]) % Creating the image layer
convolution2dLayer([102 1],3,'Stride',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
dropoutLayer
fullyConnectedLayer(1)
regressionLayer];
% Specify training options.
opts = trainingOptions('sgdm', ...
'MaxEpochs',500, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false, ...
'ValidationData',{InsulinReadingsVal,val_INS_output,},...
'LearnRateDropFactor',0.2,...
'LearnRateDropPeriod',5,...
'ExecutionEnvironment', 'cpu', ...
'ValidationPatience',Inf);
%% Train network
%net = trainNetwork(XTrain,Trainoutfinal,layers,opts);
yc1 = train_INS_output(:);
net2 = trainNetwork(InsulinReadingsTrain,yc1,layers,opts);
%% Compare against testing Data
INS_outputpredicted = predict(net2, InsulinReadingsTest)
predictionError = test_INS_output - INS_outputpredicted;
squares = predictionError.^2;
rmse = sqrt(mean(squares))
figure
scatter(INS_outputpredicted, test_INS_output,'+')
title ('True value vs Predicted Value')
xlabel ("Predicted Value")
ylabel ("True Value")
hold on
plot([-3 3], [-7 7], 'b--')

3 Commenti

Why do you think there was a over fit?
Due to the significant gap found between the validation line and training line.
Your train and validation sets should be non-overlapping, and if this is the case here (as should be), your model is protected against overfitting simply because train/validation sets never met each other.

Accedi per commentare.

 Risposta accettata

yanqi liu
yanqi liu il 7 Mar 2022
may be set dropoutLayer(value) to reduce more parameters during training

1 Commento

Is a 0.5 dropout layer value good or should increase and determine if it helps

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Deep Learning Toolbox in Centro assistenza e File Exchange

Prodotti

Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by