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

标签 matlab

我正在尝试在 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/

相关文章:

从 Java 调用时,Matlab 在库初始化时崩溃

matlab - 对所有矩阵元素应用函数

matlab - .aac 音频文件的内容是什么?

c++ - 如何将已经写入xml文件的OpenCV Mat转换回图像?

matlab - 手工计算伪逆

matlab - 使用经过训练的高斯混合模型标记新数据

matlab - Matlab 开关/案例中的空语句?

python - 有没有办法在 VSCode 中显示所有变量的列表和一个小摘要?

matlab - matlab中循环中矩阵子集的平均值

algorithm - 创建一个沿行和列具有常量和的二维二进制矩阵