MATLAB和C#(Accord.NET)中的PLS回归系数
我试图在C#中执行偏最小二乘回归分析。在MATLAB中执行的pls技术使用SIMPLS算法,该算法提供了beta(回归系数矩阵)MATLAB和C#(Accord.NET)中的PLS回归系数,c#,matlab,regression,accord.net,pls,C#,Matlab,Regression,Accord.net,Pls,我试图在C#中执行偏最小二乘回归分析。在MATLAB中执行的pls技术使用SIMPLS算法,该算法提供了beta(回归系数矩阵) 我不明白为什么两种情况下矩阵都不同,我将输入传递到C版本的方式是否有错误 此外,两者的输入是相同的,并且参考了此处包含的文件 最小工作示例: MATLAB:遵循HervéAbdi的小示例(HervéAbdi,偏最小二乘回归)。参考资料: 雅阁网: double[][] inputs = new double[][] { // Wi
- 我不明白为什么两种情况下矩阵都不同,我将输入传递到C版本的方式是否有错误
- 此外,两者的输入是相同的,并且参考了此处包含的文件
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
我认为在调用MATLAB和Accord.NET版本PLS的方式之间至少存在三个差异
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 },
};
// Create the Partial Least Squares Analysis
var pls = new PartialLeastSquaresAnalysis()
{
Method = AnalysisMethod.Center,
Algorithm = PartialLeastSquaresAlgorithm.SIMPLS, // First change: use SIMPLS
};
// Learn the analysis
pls.Learn(inputs, outputs);
// Second change: Use just 1 latent factor/component
var regression = pls.CreateRegression(factors: 1);
// Third change: present results as in MATLAB
double[][] w = regression.Weights.Transpose();
double[] b = regression.Intercepts;
// Add the intercepts as the first column of the matrix of
// weights and transpose it as in the way MATLAB presents it
double[][] coeffs = (w.InsertColumn(b, index: 0)).Transpose();
// Show results in MATLAB format
string str = coeffs.ToOctave();
随着这些变化,上述系数矩阵应变为
[ 10.4844779770616 6.18986077674717 6.28413863347486 ;
-0.634878923091644 -0.304054829845448 -0.0726082626993539 ;
0.0219492754418065 0.0105118991463605 0.00251024045589416 ;
0.192261724966225 0.0920775662006966 0.0219881135215502 ;
0.289484835410222 0.13863944631343 0.033107085796122 ]
[ 10.4844779770616 6.18986077674717 6.28413863347486 ;
-0.634878923091644 -0.304054829845448 -0.0726082626993539 ;
0.0219492754418065 0.0105118991463605 0.00251024045589416 ;
0.192261724966225 0.0920775662006966 0.0219881135215502 ;
0.289484835410222 0.13863944631343 0.033107085796122 ]