# How to calculate the coefficient of determination R^2 of a Neural Network?

조회 수: 47(최근 30일)
Bob 2022년 12월 4일
답변: the cyclist 2022년 12월 4일
I want to calculate the coefficient of determination R^2 of a Neural Network by myself.
This is the Regression plot that Neural Network Training Tool: but I want to calculate it in a way so I can "confirm" what I see on NN Training Tool.
As you can see below I have plot the Target (X) and the Prediction (Y) as Y = A*X
but the Regression Plot is way different, Prediction (Y) = 0.99*Target+0.0044 as Y=A*X+B
I understand that Weights and Biases are A and B respectively, but how can I find it and do it by myself, since they are Weights on Input Layer and Hidden Layer as well.
Also how can I draw the line that represents the middle of my data points?
figure;
plot(Output_Train,pFNN40_Train,'x');
title('Coefficient of Determination R^2');
legend('Train');
xlabel('Target');
ylabel('Prediction');
axis auto;
grid on; 댓글을 달려면 로그인하십시오.

### 채택된 답변

the cyclist 2022년 12월 4일
The formula is in the documentation here (for fitlm).It is not always the best goodness-of-fit measure for all models, but you should always be able to calculate it like this:
% Some pretend predicted and actual Y values
y_actual = [2.1; 3.2; 5.3; 7.1; 11.9];
y_predicted = [2.9; 2.7; 5.0; 7.2; 11.1];
% Plot them
plot(y_actual,y_predicted,'o') % Sum of squared residuals
SSR = sum((y_predicted - y_actual).^2);
% Total sum of squares
TSS = sum(((y_actual - mean(y_actual)).^2));
% R squared
Rsquared = 1 - SSR/TSS
Rsquared = 0.9726

댓글을 달려면 로그인하십시오.

### 범주

Find more on Deep Learning with Time Series and Sequence Data in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!