confusion matrix from the classification learner app.

17 ビュー (過去 30 日間)
Alyaa
Alyaa 2024 年 8 月 9 日
コメント済み: Alyaa 2024 年 8 月 13 日
how can i calculate metrics from the trained model with classification learner
  1 件のコメント
Umar
Umar 2024 年 8 月 10 日

Hi @Alyaa,

I would use the predict function to make predictions on new data and then evaluate the model's performance using various metrics such as accuracy, precision, recall, F1-score, and confusion matrix. Please click the link below to find out more about using this function,

https://www.mathworks.com/help/stats/linearmodel.predict.html

Here is example code snippet,

% Load your trained model

load('trainedModel.mat');

% Make predictions on new data

predictions = predict(trainedModel, newData);

% Evaluate the model

metrics = confusionmat(newDataLabels, predictions);

accuracy = sum(diag(metrics)) / sum(metrics, 'all');

precision = metrics(2,2) / sum(metrics(:,2));

recall = metrics(2,2) / sum(metrics(2,:));

f1Score = 2 * (precision * recall) / (precision + recall);

disp(['Accuracy: ', num2str(accuracy)]);

disp(['Precision: ', num2str(precision)]);

disp(['Recall: ', num2str(recall)]);

disp(['F1-Score: ', num2str(f1Score)]);

disp('Confusion Matrix:');

disp(metrics);

So, this example code snippet first loads a pre-trained model from a file named 'trainedModel.mat'. It then uses this model to make predictions on new data, calculating metrics like accuracy, precision, recall, and F1-score based on the predictions and the true labels of the new data. Finally, it displays these metrics along with the confusion matrix to assess the model's performance.

Hope this answers your question, please let me know if you have any further questions.

サインインしてコメントする。

採用された回答

Umar
Umar 2024 年 8 月 10 日

Hi @Alyaa,

I would use the predict function to make predictions on new data and then evaluate the model's performance using various metrics such as accuracy, precision, recall, F1-score, and confusion matrix. Please click the link below to find out more about using this function,

https://www.mathworks.com/help/stats/linearmodel.predict.html

Here is example code snippet,

% Load your trained model

load('trainedModel.mat');

% Make predictions on new data

predictions = predict(trainedModel, newData);

% Evaluate the model

metrics = confusionmat(newDataLabels, predictions);

accuracy = sum(diag(metrics)) / sum(metrics, 'all');

precision = metrics(2,2) / sum(metrics(:,2));

recall = metrics(2,2) / sum(metrics(2,:));

f1Score = 2 * (precision * recall) / (precision + recall);

disp(['Accuracy: ', num2str(accuracy)]);

disp(['Precision: ', num2str(precision)]);

disp(['Recall: ', num2str(recall)]);

disp(['F1-Score: ', num2str(f1Score)]);

disp('Confusion Matrix:');

disp(metrics);

So, this example code snippet first loads a pre-trained model from a file named 'trainedModel.mat'. It then uses this model to make predictions on new data, calculating metrics like accuracy, precision, recall, and F1-score based on the predictions and the true labels of the new data. Finally, it displays these metrics along with the confusion matrix to assess the model's performance.

Hope this answers your question, please let me know if you have any further questions.

  1 件のコメント
Alyaa
Alyaa 2024 年 8 月 13 日
Thank you, it's been a great help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeClassification Learner App についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by