matlab
by lqx
预测模型的原理和方法
偏最小二乘回归模型
plsregress 函数
% 示例数据
X = [4.0 2.0 0.6;
4.2 2.1 0.59;
3.9 2.0 0.58;
4.3 2.1 0.62];
Y = [1.0 0.8;
0.9 0.7;
1.2 0.95;
1.1 0.78];
% 设置主成分数目
ncomp = 2;
% 构建 PLSR 模型并进行预测
[XL, YL, XS, YS, BETA, PCTVAR, MSE, stats] = plsregress(X, Y, ncomp);
% 进行预测
Xnew = [4.1 2.05 0.6];
Ypred = [1, Xnew] * BETA;
disp('预测结果:');
disp(Ypred);
% 示例数据集
X = [1500, 3, 1; % 特征矩阵 X
2000, 4, 2;
1200, 2, 1;
1800, 3, 1;
2500, 4, 2];
Y = [200000; 250000; 180000; 220000; 280000]; % 因变量 Y
% 拟合偏最小二乘回归模型
num_components = 2; % 提取的偏最小二乘回归系数的数量
[XL, YL, XS, YS, BETA, PCTVAR, MSE, stats] = plsregress(X, Y, num_components);
% 输出结果
disp('解释的方差量:');
disp(PCTVAR);
disp('均方误差:');
disp(MSE);
disp('系数矩阵:');
disp(BETA);
disp('回归性能统计:');
disp(stats);
% 使用模型进行预测
newX = [1900, 3, 1]; % 新样本特征
pred = [1, newX] * BETA; % 预测因变量值
disp('预测结果:');
disp(pred);