Effacer les filtres
Effacer les filtres

Plotting Classification Loss Functions

3 vues (au cours des 30 derniers jours)
johnny2
johnny2 le 12 Juil 2019
Réponse apportée : Meet le 1 Août 2024
How can I plot the logisitic loss function, MathWorks says that is supports loss functions that you can specify by using the 'LossFun' name-value pair argument. The value for this function is 'logit'. So is there a way that MatLab can automically generate this function for me?

Réponses (1)

Meet
Meet le 1 Août 2024
Hi Johnny,
MATLAB provides a function "fitclinear" that you can use to fit a logistic regression model. You can also specify the loss function, in your case, "logit".
Here is an example code for the same, where I have generated 100 samples for each class and labeled the data as "+1" and "1" for the two classes:
The "Learner", "logistic" argument specifies that we are using a logistic regression model.
The "LossFun", "logit" argument specifies that we are using the logistic loss function.
numSamples = 100;
X = [randn(numSamples, 2) + 1; randn(numSamples, 2) - 1]; % Features
y = [ones(numSamples, 1); -ones(numSamples, 1)]; % Output Binary labels: +1 and -1
% Plot the synthetic data
figure;
gscatter(X(:,1), X(:,2), y, 'rb', 'xo');
xlabel('Feature 1');
ylabel('Feature 2');
title('Synthetic Data');
legend('Class +1', 'Class -1');
grid on;
% Fit a Model using Logistic Loss
mdl = fitclinear(X, y, 'Learner', 'logistic', 'LossFun', 'logit');
disp(mdl);
For more information, you can refer to the following documentation link:

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by