Javascript中的线性回归 [英] Linear Regression in Javascript
问题描述
我想在Web浏览器中使用Java最小二乘拟合.
I want to do Least Squares Fitting in Javascript in a web browser.
当前,用户使用HTML文本输入来输入数据点信息,然后我使用jQuery抓取该数据并使用 Flot .
Currently users enter data point information using HTML text inputs and then I grab that data with jQuery and graph it with Flot.
用户输入他们的数据点后,我想给他们显示最合适的线".我想我会计算线性,多项式,指数和对数方程,然后选择具有最大R^2
值的方程.
After the user had entered in their data points I would like to present them with a "line of best fit". I imagine I would calculate the linear, polynomial, exponential and logarithmic equations and then choose the one with the highest R^2
value.
我似乎找不到任何可以帮助我完成此操作的库.我偶然发现了 jStat ,但是它完全缺少文档(据我所知),并且在探究了源代码之后,它并没有似乎没有内置任何线性回归功能-但是,我纯粹是基于函数名称.
I can't seem to find any libraries that will help me to do this though. I stumbled upon jStat, but it is completely missing documentation (as far as I can find) and after digging through the the source code it doesn't seem to have any linear regression functionality built in--I'm basing this purely on function names however.
有人知道任何提供简单回归分析的Javascript库吗?
Does anyone know any Javascript libraries that offer simple regression analysis?
希望我可以像这样使用该库...
The hope would be that I could use the library like so...
如果我在数组var points = [[3,4],[15,45],...[23,78]]
中有一些散点集,那么我可以将其交给lin_reg(points)
之类的函数,如果线性方程为y = 7.12 x + 3
,它将返回诸如[7.12,3]
之类的东西.
If I had some set of scatter points in an array var points = [[3,4],[15,45],...[23,78]]
, I would be able to hand that to some function like lin_reg(points)
and it would return something like [7.12,3]
if the linear equation was y = 7.12 x + 3
.
推荐答案
什么样的线性回归?对于像最小二乘法这样的简单东西,我自己编写:
What kind of linear regression? For something simple like least squares, I'd just program it myself:
http://mathworld.wolfram.com/LeastSquaresFitting.html
在那里学习数学并不是很困难,可以花一个小时左右的时间试一试,如果太难了,请告诉我,我可以尝试一下.
The math is not too hard to follow there, give it a shot for an hour or so and let me know if it's too hard, I can try it.
找到了做到这一点的人
http://dracoblue.net/dev/linear-least-squares-in- javascript/159/
这篇关于Javascript中的线性回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!