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!