Why testing accuracy is 0.000?

1 次查看(过去 30 天)
I am attaching the matlab code and input file. This code is not giving any error and running very smoothly. However, It is giving testing accuracy 0.000
Out-of-Bag Error: 0.0412
Out-of-Bag Classification Error: 0.6729
Training Accuracy: 0.9588
Testing Accuracy: 0.0000
is it okey or some problem in computing testing error?
please suggest me.
Sanchit

采纳的回答

Aniketh
Aniketh 2023-7-9
Hi Sanchit,
It seems the problem in your code is in the respective datatypes of y_test.Var11 and y_pred.
To address this problem, let's examine the code and make the necessary corrections. In the original code, the line test_accuracy = sum(strcmp(y_pred, y_test.Var11)) / numel(y_test.Var11); is used to calculate the testing accuracy. However, based on the given information, it appears that y_test.Var11 contains numeric values, while y_pred contains cell arrays of strings.
y_test_str = cellfun(@num2str, num2cell(y_test.Var11), 'UniformOutput', false);
test_accuracy = sum(strcmp(y_pred, y_test_str)) / numel(y_test_str);
fprintf('Testing Accuracy: %.4f\n', test_accuracy);
With this change testing accuracy is being printed correctly, you could employ other methods as well to change the datatypes.
Hope this helped!
  3 个评论
Sanchit
Sanchit 2023-7-10
I am using below matlab code for mean square error. It is giving mse 0.000 for three different data sets. Therefore, there is some error in code. I request you to kindly have a look on it and suggest me how to fix it.
Sanchit
% Create a Random Forest classifier
rf_classifier = TreeBagger(100, X_train, y_train, 'OOBPrediction', 'On');
predicted = predict(rf_classifier, X_train);
YY = categorical(predicted)
ZZ = str2num(char(YY(:)))
Z = table2array(y_train)
oob_mse = immse(Z,ZZ);
disp(sprintf('Out-of-Bag Mean Square Error: %.4f', oob_mse(end)));
Aniketh
Aniketh 2023-7-10
You're welcome! I'm glad to hear that the solution worked for you.
An equivalent of mse can be done in MATLAB as:
y_train_pred = predict(rf_classifier, X_train);
oob_mse = mean((y_train - y_train_pred).^2);
For the sceond part can't say for sure without looking at the complete code but if you are evaluating on the same dataset that you used for training, it is possible the classifier has learned to predict the training data very well and you are getting a loss as 0.000

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by