matlab预测模型、Logistic 模型拟合和预测

2024-06-04 3213阅读

matlab

by lqx

预测模型的原理和方法

Logistic 模型拟合和预测

matlab预测模型、Logistic 模型拟合和预测 第1张

人口数量的拟合和预测
% 输入已知数据点的时间和人口数量
t = [1950, 1960, 1970, 1980, 1990, 2000, 2010]; % 年份
P = [2.5, 3.0, 3.7, 4.4, 5.3, 6.1, 7.0]; % 人口数量(单位:亿)
% 定义 Logistic 曲线方程
logistic = @(x, t) x(1) ./ (1 + x(2) * exp(-x(3) * (t - x(4))));
% 设置初始参数估计值
initial_guess = [8, 1, 0.1, 1950]; % [K, A, r, t0]
% 使用非线性最小二乘法拟合
x = lsqcurvefit(logistic, initial_guess, t, P);
% 生成预测的时间点
t_pred = 1950:2030;
% 进行人口数量预测
P_pred = logistic(x, t_pred);
% 绘制原始数据和预测曲线
plot(t, P, 'ro', 'MarkerSize', 8); % 原始数据点
hold on;
plot(t_pred, P_pred, 'b-', 'LineWidth', 2); % 预测曲线
xlabel('年份');
ylabel('人口数量(亿)');
legend('原始数据', '预测曲线');
grid on;

matlab预测模型、Logistic 模型拟合和预测 第2张

二分类问题
% 生成随机数据
rng(1);
X = [randn(100,2); randn(100,2)+2];
Y = [zeros(100,1); ones(100,1)];
% 拟合Logistic回归模型
model = fitglm(X,Y,'Distribution','binomial');
% 预测新的样本
newX = [randn(10,2); randn(10,2)+2];
pred = predict(model, newX);
disp(pred);
%结果展示
    0.0000
    0.0001
    0.0001
    0.0419
    0.0000
    0.0000
    0.1043
    0.0406
    0.0719
    0.0000
    0.7201
    0.9989
    0.9583
    1.0000
    0.9998
    1.0000
    0.3704
    0.9841
    0.0620
    1.0000

matlab预测模型、Logistic 模型拟合和预测 第3张

Logistic 人口模型微分方程

matlab预测模型、Logistic 模型拟合和预测 第4张

t=1997:1:2016;
x=[123626 124761 125786 126743 127627 128453 129227 129988 130756 131448 ...
132129 132802 133450 134091 134735 135404 136072 136782 137462 138271];
x1=[123626 124761 125786 126743 127627 128453 129227 129988 130756 131448 ...
132129 132802 133450 134091 134735 135404 136072 136782 137462];
x2=[124761 125786 126743 127627 128453 129227 129988 130756 131448 132129 ...
132802 133450 134091 134735 135404 136072 136782 137462 138271];
dx=(x2-x1)./x2;a=polyfit(x2,dx,1);
r=a(2),xm=-r/a(1)
x0=123626;
f=inline('xm./(1+(xm/x0-1)*exp(-r*(t-1997)))','t','xm','r','x0');
scatter(t,x,'k');
hold on;
plot(t,f(t,xm,r,x0),'r-');
xlabel('年份');
ylabel('人口数(万) ');
title('1997-2016 年实际人口与拟合值比较');
grid on;
x2017=f(2017,xm,r,x0),x2018=f(2018,xm,r,x0),x2023=f(2023,xm,r,x0)
x2028=f(2028,xm,r,x0),x2033=f(2033,xm,r,x0),x2038=f(2038,xm,r,x0)
x2043=f(2043,xm,r,x0),x2048=f(2048,xm,r,x0),x2053=f(2053,xm,r,x0)
x2058=f(2058,xm,r,x0),x2063=f(2063,xm,r,x0),x2068=f(2068,xm,r,x0)
z=2018:5:2068;y=[x2018,x2023,x2028,x2033,x2038,x2043,x2048,x2053,x2058,x2063,x2068];
hold on;
plot(z,y,'--r');xlabel('年份');ylabel('人口数(万) ');title('曲线拟合以及人口预测曲线')
grid on;

matlab预测模型、Logistic 模型拟合和预测 第5张


    免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

    目录[+]