Trying to get prediction scatter plot
Afficher commentaires plus anciens
clc; clear all; close all;
%Import/Upload data
load generated_data.mat
% change to label vector
CS = categories(categorical(Y1));
Z1 = []; Z2 = [];
for i = 1 : length(Y1)
Z1(i,1) = find(Y1(i)==CS);
end
for i = 1 : length(Y2)
Z2(i,1) = find(Y2(i)==CS);
end
Yo1 = Y1;
Yo2 = Y2;
Y1 = Z1;
Y2 = Z2;
%transposing glucose data
X1_T = X1';
%Shuffling data to take randomly
rand('seed', 0)
ind = randperm(size(X1_T, 1));
X1_T = X1_T(ind, :);
Y1 = Y1(ind);
%Separating data in training, validation and testing data
X1_train = X1_T;
%Partioning data for training 70%
train_X1 = X1_train(1:120,:);
%Corresponding X(input) data to Y(output) data
train_Y1 = Y1(1:120);
%reshaping data into 4D array
XTrain=(reshape(train_X1', [2289,1,1,120]));
%Separating and partioning for validation data 15%
val_X1 = X1_train(121:150,:);
%Corresponding X(input) data to Y(output) data
val_Y1 = Y1(121:150);
%reshaping data into 4D array
XVal=(reshape(val_X1', [2289,1,1,30])); %Train data
%Separating and partioning for test data 15%
test_X1 = X1_train(151:180,:);
%Corresponding X(input) data to Y(output) data
test_Y1 = Y1(151:180);
%reshaping data into 4D array
XTest=(reshape(test_X1', [2289,1,1,30])); %Train data
%% NETWORK ARCHITECTURE
layers = [imageInputLayer([2289 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',1500, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false, ...
'ValidationData',{XVal,val_Y1},...
'ExecutionEnvironment', 'cpu', ...
'ValidationPatience',Inf);
%% Train network
%net = trainNetwork(XTrain,Trainoutfinal,layers,opts);
yc = train_Y1(:);
net1 = trainNetwork(XTrain,yc,layers,opts);
%% Compare against testing Data
miniBatchSize =27;
YPred = predict(net1,XTest, ...
'MiniBatchSize',miniBatchSize,...
'ExecutionEnvironment', 'cpu');
Ypredicted = predict(net, XTrain)
predictionError = double(testoutfinal) - test_Y1(:);
squares = predictionError.^2;
rmse = sqrt(mean(squares))
figure
scatter(Ypredicted, double(testoutfinal),'+')
title ('True value vs Predicted Value')
xlabel ("Predicted Value")
ylabel ("True Value")
hold on
plot([-3 3], [-3 3], 'b--')
2 commentaires
Nathaniel Porter
le 21 Déc 2021
KSSV
le 21 Déc 2021
Ypredicted = predict(net, XTrain)
If you have the target/ output for XTrain. Then you can plot right?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Deep Learning Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
