JavaScript中的简单回归预测算法 [英] Simple Regression Prediction Algorithm in JavaScript

查看:231
本文介绍了JavaScript中的简单回归预测算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用回归来基于过去的记录对组织的未来利润进行简单的预测。我正在关注



我的实际数据将是日期和利润,它们将上下移动而不是以连续的增量方式。我意识到上面的方法适用于样本数据,随着预测的准确性不断增加。然而,当我将数据更改为屏幕截图中的数据时,疯狂地上下移动,预测不再那么准确。



只是想知道是否有任何方法为了提高回归的准确性,因为我的数据会上下变化。



谢谢!

解决方案

进行回归时,您将模型拟合到数据中。换句话说,你说这是一个大致描述数据行为方式的方程式。在线性回归的情况下,模型/等式是:

  y = a * x + b 

其中x是输入,y是输出。通过线性回归,你会说我的数据遵循一条直线,这是我的数据,最适合数据的参数a和b是什么?。



显然,如果您的数据遵循直线,这将非常有效。例如,请查看我发现的此图片在谷歌图片上。



很明显,你可以看到数据有某种复杂的波浪形状 - 它上下然后再上升。线性模型不够复杂,无法表达这种形状(它只能做直线)。所以它不适合。



由于你需要一个更复杂的模型,你必须选择一个。有几十个标准的,你可以自己组成。所有模型都是一个带有一些固定参数的方程,可以调整这些参数以使公式适合您的数据。



我建议你在Excel中使用趋势线选项或谷歌表格,以了解这一点。请参阅趋势线类型位此处对于一些常见的模型。



请注意,这些都不适用于月度利润,因为它们都不是真正的周期性的。您可能需要一个模型,它是一些重复乘数的组合,用于捕获月到月的变化,然后是线性或多项式组件,以捕捉年利润随时间增加或减少的事实。



你不想要一个表达的模型,否则你会过度拟合数据(基本上它会看到噪音中的模式)。


I am trying to do a simple forecast of future profit of an organization based on the past records by using regression. I am following this link. For testing purpose, I have changed the sample data and it produced these results:

My actual data will be date and profit, and they will be going up and down rather than in a contiguous increment way. I realized that the method above works for sample data which keep on increasing as the prediction is quite accurate. However, when I changed the data to the one in the screenshot which goes up and down crazily, the prediction is not so accurate anymore.

Just wondering if there is any way to increase the accuracy for the regression as my data will be going up and down.

Thanks!

解决方案

When you do a regression you are fitting a model to the data. In other words you are saying "here is an equation that describes roughly how the data behaves". In the linear regression case the model / equation is:

y = a * x + b

Where x is the input and y is the output. By doing a linear regression you are saying "my data follows a straight line, here is my data, what are the parameters a and b that best fit the data?".

Obviously if your data does not follow a straight line this will work badly. For instance look at this image I found on Google Images.

Clearly you can see the data has some kind of complex wavy shape - it goes up and down and then up again. The linear model is not complex enough to express this shape (it can only do straight lines). So it doesn't fit well.

Since you need a more complex model you have to choose one. There are dozens of standard ones and you can make up your own. All the model is is an equation with some fixed parameters that can be adjusted so that the equation fits your data.

I suggest you play around with the trend line options in Excel or Google Sheets to get a feel for this. See the Trendline Types bit here for some common models.

Note that none of those will work well for monthly profit because none of them are really cyclical. You probably want a model that is a combination of some repeating multipliers to capture month-to-month variations, and then a linear or polynomial component to capture the fact that yearly profit is increasing or decreasing over time.

You don't want a model that is too expressive however, otherwise you will overfit the data (basically it will see patterns in the noise).

这篇关于JavaScript中的简单回归预测算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆