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
KSSV
2022년 3월 4일
Why do you think there was a over fit?
Nathaniel Porter
2022년 3월 4일
Ive J
2022년 3월 5일
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!