Please i need help on how to determine R squared for training, validation, testing and ALL in neural network with a simple code.

28 次查看(过去 30 天)
Please how can I determine the correlation coefficient of training, validation, testing and ALL in neural net with a simple code.Each time I click on plotregression, I see thier R2 but would like to include it in my code and view only the values.
load ('t.mat');
load ('x.mat');
x = input';
t = Target';
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
% Levenberg-Marquardt backpropagation.
trainFcn = 'trainlm';
%% Create a Fitting Network
hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize,trainFcn);
%% Setup Division of Data for Training, Validation, Testing
[trainInd,valInd,testInd] = divideint(x,0.70,0.15,0.15);
%% Train the Network
net.performParam.regularization = 0.0001;
[net,tr] = train(net,x,t);
%% Number of validation checks
net.trainParam.min_grad
nntraintool
%%
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y);
perf = mse(net, t, y, 'regularization', 0.01);
perf = crossentropy(net,t,y,{1},'regularization',0.01);
%% Calculate network perfomance on test
tInd = tr.testInd
tsty = net(x(:,tInd))
tstPerform = perform(net,t(:,tInd),tsty)
%% Check train records
tr
%% View the Network diagram
view(net)
%% Plots
% Uncomment these lines to enable various plots.
trOut = y(tr.trainInd)
vOut = y(tr.valInd)
tsOut = y(tr.testInd)
trTarg = t(tr.trainInd)
vTarg = t(tr.valInd)
tsTarg = t(tr.testInd)
%% performance figure,
figure
plotperform(tr);
%% trainstate figure,
figure
plottrainstate(tr);
%% Errorhistogram figure,
figure
ploterrhist(e);
%% Regression figure,
figure
plotregression(trTarg, trOut, 'Train', vTarg, vOut, 'Validation', tsTarg, tsOut, 'Test', t,y, 'All');
  3 个评论

请先登录,再进行评论。

采纳的回答

fred  ssemwogerere
fred ssemwogerere 2020-2-18
"..........Each time I click on plotregression, I see thier R2......"
Hello, point of correction; regression plots of your modeled network show the correlation coefficient,"R" (a measure of the magnitude and direction of linear association between the defined variables), but not the coefficient of determination, "Rsquared / R2" (a measure of the magnitude of variability modeled by the network in your output,'y'). However, R=squareroot(R2). Added to that, a number of answers have been previously given on how to obtain this correlation coefficient you desire. Please refer to the links below:
Alternatively you could refer to the matlab documentation in the link below, with an example of obtaining the correlation coefficient from the general or "All" plot:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by