Binary Logistic Regression Curve

51 次查看(过去 30 天)
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')

采纳的回答

Aditya Patil
Aditya Patil 2020-8-17
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by