成功的使用AI,写出了一个matlab代码

提问

参考每年产废量、人口、焦炭等数据,建立预测模型,预测未来3年的产废量,程序用于matlab。运用matlab中`fitlm`函数来建立一个简单的线性回归模型进行预测

年份

工业固体废物产量(万吨)

人口数量(万人)

焦炭 (万吨)

2018

1526

1383

867.23

2019

1968

1385

899.2

2020

1738.8

1386.6

927.04

2021

1927.5

1373

740.09

2022

1946.1

1363

704.55

程序

data = [

2018, 1526, 1383, 867.23;

2019, 1968, 1385, 899.2;

2020, 1738.8, 1386.6, 927.04;

2021, 1927.5, 1373, 740.09;

2022, 1946.1, 1363, 704.55

];

% 将数据转换为表格

T = table(data(:,1), data(:,2), data(:,3), data(:,4), 'VariableNames', {'Year', 'SolidWaste', 'Population', 'Coke'});

% 提取预测因子和目标变量

X = [T.Year, T.Population];

Y = T.SolidWaste;

% 拟合线性回归模型

mdl = fitlm(X, Y);

% 显示模型摘要

disp(mdl);

% 假设未来3年的人口数量与2022年相同

futurePopulation = 1363;

% 创建未来年份的预测因子矩阵

futureX = [2023, futurePopulation; 2024, futurePopulation; 2025, futurePopulation];

% 使用模型进行预测

futureY = predict(mdl, futureX);

% 显示预测结果

disp(table(futureX(:,1), futureY, 'VariableNames', {'Year', 'PredictedSolidWaste'}));

运行结果

Linear regression model:

y ~ 1 + x1 + x2

Estimated Coefficients:

Estimate SE tStat pValue

__________ __________ _______ _______

(Intercept) -2.153e+05 2.3941e+05 -0.8993 0.4634

x1 104.29 108.65 0.95995 0.43838

x2 4.6777 17.224 0.27158 0.81141

Number of observations: 5, Error degrees of freedom: 2

Root Mean Squared Error: 194

R-squared: 0.469, Adjusted R-Squared -0.0625

F-statistic vs. constant model: 0.882, p-value = 0.531

Year PredictedSolidWaste

____ ___________________

2023 2063.4

2024 2167.7

2025 2272

还是挺好用,完全不懂的人,也能写出程序了。

天津
浏览 1712
收藏
4
分享
4 +1
1
+1
全部评论 1