Binary Logistic Regression Curve

51 ビュー (過去 30 日間)
Jonathan Moorman
Jonathan Moorman 2020 年 7 月 2 日
回答済み: Aditya Patil 2020 年 8 月 17 日
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 Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by