gpt4 book ai didi

matlab - MatLab 中的简单逻辑回归 - 需要初学者帮助

转载 作者:行者123 更新时间:2023-12-04 19:37:25 24 4
gpt4 key购买 nike

我正在尝试在 MatLab 中进行简单的逻辑回归分析。

X = [103.4843 103.4843 100.3871 101.8535 101.7658 101.9658];
Y = [120.9189 107.3617 122.5506 96.9701 101.9798 118.3035];
B = mnrfit(X,Y)

我一直收到这个错误:

If Y is a column vector, it must contain positive integer category numbers.

我不确定为什么。有人可以帮忙吗?谢谢!

最佳答案

请阅读mnrfit的文档:

https://www.mathworks.com/help/stats/mnrfit.html#btmaowv-Y

尝试使用表,然后让 Y 成为分类数组。

比如我的代码:

%% Multinomial Logistic Regression

% read csv file and create table
% header = {'Year','Abortion','DowJones','Incarceration','Crime_Rate'};

data = csvread("E:\code\project\regression.csv",1,0);
year = data(:,1);
abortion = data(:,2);
dowjones = data(:,3);
incarceration = data(:,4);
crime_rate = data(:,5);
T = table(year,abortion,dowjones,incarceration,crime_rate);

% multinomial logistic regression
X = [abortion,dowjones,incarceration];
Y = categorical(crime_rate);

% B: coefficicent estimates
% dev: deviance of the fit
% stats: model statistics

[B,dev,stats] = mnrfit(X,Y,'Model','ordinal','link','logit');

希望这对您有所帮助。

关于matlab - MatLab 中的简单逻辑回归 - 需要初学者帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23751606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com