Apache Commons Math中是否有numpy.linalg.lstsq的等效实现?

1 投票
1 回答
1489 浏览
提问于 2025-04-16 11:54

我有一个关于numpy.linalg.lstsq的调用:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.lstsq.html

x = [[ 0.69314718] [ 1.09861229] [ 1.38629436] [ 1.60943791] [ 1.79175947] [ 1.94591015]]

y = [ 0. 0.20273255 0.5815754 0.7520387 0.96885669 1.09861229]

l = numpy.linalg.lstsq(x, y)

这个调用返回了:

l -> 元组: (array([ 0.46323573]), array([ 0.25872885]), 1, array([ 3.63269497]))

有没有人能告诉我在

http://commons.apache.org/math/

(或者其他一些Java数学库中)有没有类似的函数?

1 个回答

2

谢谢你的提示,Joe。

这里有一段代码供参考:

double[][] testSquare = {{0.69314718}, {1.09861229}, {1.38629436}, {1.60943791}, {1.79175947}, {1.94591015}};
RealMatrix matrix = MatrixUtils.createRealMatrix(testSquare);
SingularValueDecomposition svd = new SingularValueDecomposition(matrix);
DecompositionSolver ds=svd.getSolver();
double[] b = {0.0, 0.20273255, 0.5815754, 0.7520387, 0.96885669, 1.09861229};
ds.solve(b)[0];

撰写回答