Trying to get prediction scatter plot

2 vues (au cours des 30 derniers jours)
Nathaniel Porter
Nathaniel Porter le 20 Déc 2021
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
Nathaniel Porter le 21 Déc 2021
I noticed that the question was edited?
KSSV
KSSV le 21 Déc 2021
Ypredicted = predict(net, XTrain)
If you have the target/ output for XTrain. Then you can plot right?

Connectez-vous pour commenter.

Réponse acceptée

yanqi liu
yanqi liu le 21 Déc 2021
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';
%transposing insulin data
X2_T = X2';
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
train_X1 = X1_train(1:120,:);
train_Y1 = Y1(1:120);
%DataParts = zeros(size(Train_inputX1,1), size(Train_inputX1,2),1,2); %(4500,400,1,2)
%DataParts(:,:,:,1) = real(cell2mat(Train_inputX1));
%DataParts(:,:,:,2) = imag(cell2mat(Train_inputX1)) ;
XTrain=(reshape(train_X1', [2289,1,1,120])); %Train data
%Separating and partioning for validation data
val_X1 = X1_train(121:150,:);
val_Y1 = Y1(121:150);
XVal=(reshape(val_X1', [2289,1,1,30])); %Train data
%Separating and partioning for test data
test_X1 = X1_train(151:180,:);
test_Y1 = Y1(151:180);
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('adam', ...
'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;
testoutfinal = predict(net1,XTest, ...
'MiniBatchSize',miniBatchSize,...
'ExecutionEnvironment', 'cpu');
predictionError = testoutfinal(:) - test_Y1(:);
squares = predictionError.^2;
rmse = sqrt(mean(squares))
figure
scatter(test_Y1, round(testoutfinal),'+')
title ('True value vs Predicted Value')
xlabel ("True Value")
ylabel ("Predicted Value")
hold on; box on;
plot([1 6], [1 6], 'b--')

Plus de réponses (0)

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by