我正在尝试在 C# 中执行偏最小二乘回归分析。在 MATLAB 中执行的 pls 技术使用提供 beta(回归系数矩阵)的 SIMPLS 算法。
我不明白为什么两种情况下的矩阵都不同,我将输入传递给 C# 版本的方式是否有一些错误?
此外,两者的输入相同,并且参考了此处包含的论文。
最小的工作示例:
MATLAB:遵循 Hervé Abdi 的小例子(Hervé Abdi,偏最小二乘回归)。参考资料:PDF
clear all;
clc;
inputs = [7, 7, 13, 7; 4, 3, 14, 7; 10, 5, 12, 5; 16, 7, 11, 3; 13, 3, 10, 3];
outputs = [14, 7, 8; 10, 7, 6; 8, 5, 5; 2, 4,7; 6, 2, 4];
[XL,yl,XS,YS,beta,PCTVAR] = plsregress(inputs,outputs, 1);
disp 'beta'
beta
disp 'beta size'
size(beta)
yfit = [ones(size(inputs,1),1) inputs]*beta;
residuals = outputs - yfit;
% stem(residuals)
% xlabel('Observation');
% ylabel('Residual');
beta =
1.0484e+01 6.1899e+00 6.2841e+00
-6.3488e-01 -3.0405e-01 -7.2608e-02
2.1949e-02 1.0512e-02 2.5102e-03
1.9226e-01 9.2078e-02 2.1988e-02
2.8948e-01 1.3864e-01 3.3107e-02
雅阁网:
double[][] inputs = new double[][]
{
// Wine | Price | Sugar | Alcohol | Acidity
new double[] { 7, 7, 13, 7 },
new double[] { 4, 3, 14, 7 },
new double[] { 10, 5, 12, 5 },
new double[] { 16, 7, 11, 3 },
new double[] { 13, 3, 10, 3 },
};
double[][] outputs = new double[][]
{
// Wine | Hedonic | Goes with meat | Goes with dessert
new double[] { 14, 7, 8 },
new double[] { 10, 7, 6 },
new double[] { 8, 5, 5 },
new double[] { 2, 4, 7 },
new double[] { 6, 2, 4 },
};
var pls = new PartialLeastSquaresAnalysis()
{
Method = AnalysisMethod.Center,
Algorithm = PartialLeastSquaresAlgorithm.NIPALS
};
var regression = pls.Learn(inputs, outputs);
double[][] coeffs = regression.Weights;
>>
-1.69811320754717 -0.0566037735849056 0.0707547169811322
1.27358490566038 0.29245283018868 0.571933962264151
-4 1 0.5
1.17924528301887 0.122641509433962 0.159198113207547