Binary Logistic Regression Curve

65 Ansichten (letzte 30 Tage)
Jonathan Moorman
Jonathan Moorman am 2 Jul. 2020
Beantwortet: Aditya Patil am 17 Aug. 2020
Hello! I am trying to create a logistical regression curve for my binary data in Figure 3. Is this possible to do in MATLAB, and if so, how could it be done? My code is below? Thanks
%Figure 2 Graphing
scatter(FactoredLength, FactoredAmplitude,5,'filled')
hold on
coefficients = polyfit(FactoredLength, FactoredAmplitude, 1);
xFit = linspace(min(FactoredLength), max(FactoredLength), 1000);
yFit = polyval(coefficients , xFit);
plot(xFit, yFit, 'r-', 'LineWidth', 2);
xlabel('Factored Length')
ylabel('Probability')
grid on;
hold off
figure
% Making data binary
Probability = ((exp(log10(FactoredAmplitude)))./(1+exp(log10(FactoredAmplitude))));
yHat(Probability > app.ThreshHoldValueEditField.Value) = 1;
yHat(Probability < app.ThreshHoldValueEditField.Value) = 0;
%Figure 3 Graphing
scatter(FactoredLength,yHat)
xlabel('Factored Length')
ylabel('Probability')

Akzeptierte Antwort

Aditya Patil
Aditya Patil am 17 Aug. 2020
Use the fitglm function to fit logistic regression model to data. Check the following code for example,
% Create random data
x = rand(100, 1);
y = x > 0.5;
y(1:50) = x(1:50) > 0.3; % To avoid perfect seperation
% Fit model
mdl = fitglm(x, y, "Distribution", "binomial");
xnew = linspace(0,1,1000)'; % test data
ynew = predict(mdl, xnew);
scatter(x, y);
hold on;
plot(xnew, ynew);
This will give following output.

Weitere Antworten (0)

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by