简体   繁体   English

Python 中的 Theil's U 1 / Theil's U 2 预测系数公式

[英]Theil's U 1 / Theil's U 2 Forecast Coefficient formula in Python

I have a problem implementing the Theil U forecast coefficient formula in my Python code.我在 Python 代码中实现 Theil U 预测系数公式时遇到问题。 One of the problems is that I found several different versions of the formula.问题之一是我发现了几个不同版本的公式。 The 3 formulas I want to try are the following:我想尝试的 3 个公式如下:

Theil's U 1 and 2 from a paper that ironically discusses the confusion of the Theil's U forecast coefficient: https://journals.sagepub.com/na101/home/literatum/publisher/sage/journals/content/mrja/1973/mrja_10_4/002224377301000413/20181220/002224377301000413.fp.png_v03 Theil's U 1 和 2 来自一篇讽刺性地讨论了 Theil's U 预测系数的混淆的论文: https : //journals.sagepub.com/na101/home/literatum/publisher/sage/journals/content/mrja/1973/mrja_10_4/ 002224377301000413/20181220/002224377301000413.fp.png_v03

A different version of the Theil's U forecast coefficient from what appears to be an Oracle help page: https://docs.oracle.com/cd/E40248_01/epm.1112/cb_statistical/frameset.htm?ch07s02s03s04.html Theil's U 预测系数的不同版本与似乎是 Oracle 帮助页面的内容不同: https : //docs.oracle.com/cd/E40248_01/epm.1112/cb_statistical/frameset.htm?ch07s02s03s04.html

The three formulas should achieve a value of 1 if the forecast is just a naive lagged forecast.如果预测只是一个朴素的滞后预测,这三个公式应该达到 1 的值。 So, let's consider the following simple list: list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and assume that the forecast for every value is the previous value.因此,让我们考虑以下简单列表:list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 并假设每个值的预测都是前一个值。

This is my code for the 3 formulas:这是我的 3 个公式的代码:

list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

num = (sum([(list[row] - list[row - 1]) ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) / 9) ** 0.5
denum = ((sum([list[row] ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) / 9) ** 0.5) + \
    ((sum([list[row - 1] ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) / 9) ** 0.5)

UI = num / denum
print(UI)

num = sum([(list[row - 1] - list[row]) ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) ** 0.5
denum = (sum([list[row] ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]])) ** 0.5

UII = num / denum
print(UII)

num = sum([((list[row - 1] - list[row]) / list[row - 1]) ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) ** 0.5
denum = sum([((list[row] - list[row - 1]) / list[row - 1]) ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) ** 0.5

U_Oracle = num / denum
print(U_Oracle)

These are the 3 results:这是3个结果:

0.08224166442822099 0.08224166442822099

0.15309310892394865 0.15309310892394865

1.0 1.0

I can't figure out why not all 3 values are equal to 1. Is something wrong with my code?我不明白为什么不是所有 3 个值都等于 1。我的代码有问题吗?

The paper from Briemel, called a clarification is actually quite confusing, as it says that Ai and Pi are actual and predicted values. Briemel 的论文,称为澄清实际上非常令人困惑,因为它说 Ai 和 Pi 是实际值和预测值。 That is not true, you should use those values as 'rate of change' (quoting from the paper itself If one means by Ai and Pj the observed changes and the predicted changes ... ), which would require you to write another code for it.事实并非如此,您应该将这些值用作“变化率”(引用自论文本身If one means by Ai and Pj the observed changes and the predicted changes ... ),这将需要您为它。

To make a long story short, the Oracle implementation is the right one you are looking for!长话短说,Oracle 实现正是您要寻找的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM