线性回归和 Java 日期
我试图找到一组数据的线性趋势线。该集合包含日期(x 值)和分数(y 值)对。我使用 此代码 的版本作为基础我的算法。
我得到的结果相差几个数量级。我假设存在舍入错误或溢出的问题,因为我使用的是 Date 的 getTime 方法,它为您提供了大量的毫秒数。 有人对如何最小化错误并计算正确的结果有建议吗?
I am trying to find the linear trend line for a set of data. The set contains pairs of dates (x values) and scores (y values). I am using a version of this code as the basis of my algorithm.
The results I am getting are off by a few orders of magnitude. I assume that there is some problem with round off error or overflow because I am using Date's getTime method which gives you a huge number of milliseconds. Does anyone have a suggestion on how to minimize the errors and compute the correct results?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许它有助于将 Date 返回的长值转换为更小的值。
如果你不需要毫秒精度,你可以除以 1000。也许你甚至不需要秒,再除以 60。
此外,该值锚定在 1970 年 1 月 1 日。如果你只需要最近的日期,你可以可以减去偏移量以将其重新设置为 2000 年。
整个想法是使数据差异在数值上更加显着(按百分比)。
Maybe it helps to transform the long value that Date returns into something smaller.
If you do not need millisecond precision, you can just divide by 1000. Maybe you do not even need seconds, divide by another 60.
Also, the value is anchored at January, 1st, 1970. If you only need more recent dates, you could subtract the offset to re-base it in 2000.
The whole idea is to make differences in the data more significant numerically (percentage-wise).
unix timestamp 的类型是一个整数,并且您正在以双精度形式读取数据。根据相对大小,您几乎肯定会遇到麻烦。
将时间戳保留为整数或将时间转换为更适合您的问题的时间。
The type of a unix timestamp is an integer and you are reading data as a double. Depending on the relative sizes you're almost bound to get into trouble.
Keep the timestamps as integers or convert the time into something more appropriate to your problem.