当 x 轴使用日期时计算趋势线

发布于 2024-07-25 06:22:22 字数 495 浏览 1 评论 0原文

关于计算散点图上的趋势线的帖子(我如何计算图表的趋势线?)非常有帮助,但我很好奇如何在 x 轴是日期时间字段而不是整数的图表上找到趋势线。 例如,考虑将邮件列表的订阅者数量随时间变化绘制图表的情况:

1 月 1 日:100 个订阅者
1 月 2 日:105 位订阅者
1 月 5 日:120 名订阅者
1 月 10 日:117 位订阅者
等等...

我遇到的问题是找出其中的“运行”(delta x)部分...由于间隔不会均匀分布,我们不能只假设一个时间单位在每次测量之间传递。 我有一种预感,我必须制定某种规模,但我被困在那里。

谁能解释当 x 轴是日期时间字段时如何计算趋势线? (如果您发布代码示例,C#、VB.NET 或 Java 将不胜感激!)

The post on calculating trend lines on a scatter plot (How do I calculate a trendline for a graph?) is quite helpful, but I'm curious how one could go about finding a trend line on a graph where the x-axis is a DateTime field, rather than an integer. For example, consider the case of charting the number of subscribers to a mailing list over time:

Jan 1: 100 subscribers
Jan 2: 105 subscribers
Jan 5: 120 subscribers
Jan 10: 117 subscribers
etc...

The problem I'm running into is figuring out the 'run' (delta x) portion of this... since the intervals are not going to be evenly spaced, we can't just assume a single unit of time passing between each measurement. I've got a hunch that I'll have to work out some sort of scale, but I'm stuck there.

Can anyone explain how to calculate a trendline when the x-axis is a DateTime field?
(If you post a code sample, C#, VB.NET, or Java would be most appreciated!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

清浅ˋ旧时光 2024-08-01 06:22:22

您始终可以将日期转换为整数,

网络给出了这个示例:

DateTime given = new DateTime(2008, 7, 31, 10, 0, 0);
TimeSpan t = given.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0));
long unixTime = (long) t.TotalSeconds;

you can always convert the date to an integer

the web gives this example:

DateTime given = new DateTime(2008, 7, 31, 10, 0, 0);
TimeSpan t = given.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0));
long unixTime = (long) t.TotalSeconds;
一花一树开 2024-08-01 06:22:22

您必须进行某种线性插值。 您需要将日期和时间转换为线性刻度。 好消息是您可以选择这个比例。 因此,请计算自情节开始以来已经过去了多少分钟、秒或小时。 然后您可以将其用作“运行”部分。

在您的示例中,我们可以关闭天数:

1 月 1 日:0 天,100 个订阅者
1 月 2 日:1 天,105 名订阅者
1 月 5 日:4 天,120 名订阅者
1 月 10 日:9 天,117 名订阅者

You'll have to do a sort of linear interpolation. You need to convert the dates and times to a linear scale. The good news is that you get to pick this scale. So calculate how many minutes, or seconds, or hours... have passed since the start of your plot. You can then use this as the "run" portion.

In your example, we can go off of days:

Jan 1: 0 days, 100 subscribers
Jan 2: 1 day, 105 subscribers
Jan 5: 4 days, 120 subscribers
jan 10: 9 days, 117 subscribers

情愿 2024-08-01 06:22:22

即使您的样本间隔不均匀,您的趋势线仍然可以持续“运行”。

例如,您可以选择 1 周的间隔。 在这种情况下,取 1 月 1 日、2 日和 1 月 1 日的平均订户数。 5 并在 1 月 7 日绘制一个点。接下来取 1 月 10 日和 1 月 10 日的平均值。 13 日,并在 1 月 14 日绘制一个点。等等。

如果您有大量历史数据,请使用 1 个月间隔,或者可能每季度更适合您的数据。

Even though your samples are not evenly spaced, your trendline can still have a constant "run".

For example, you could choose 1 week intervals. In that case take the average number of subscribers for Jan 1,2, & 5 and plot a point on Jan 7. Next take the average for Jan 10 & 13, and plot a point on Jan 14. etc..

If you have a lot of historical data, use 1 month intervals, or maybe quarterly would better suit your data.

对不⑦ 2024-08-01 06:22:22

指定起始日期并认为 x = 1。
如果您想更具体,请选择小时或 8 小时时段。

The first day:
jan 1, 2006 -> x = 1
45 days later
February 13th?? -> x = 45
2 years later:
jan 1, 2008 -> x = 730

Specifiy an origin date and consider it x = 1.
Chose hours or 8 hour periods if you want to be more specific.

The first day:
jan 1, 2006 -> x = 1
45 days later
February 13th?? -> x = 45
2 years later:
jan 1, 2008 -> x = 730
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文