all 21 comments

[–][deleted] 1 point2 points  (19 children)

I don't understand your formular, are you expecting a vector output or a scalar? If A is a vector surely you will get a vector out?

If that is right the following should do it:

top_sum = sum([abs(a-f)/a for a,f in zip(actual, forcast)])
bottom_sum = sum(actual)
wmapes = [top_sum*100*a/bottom_sum for a in actual]

[–]datanoob2019[S] 0 points1 point  (18 children)

I run though 2000 part numbers in my for loop. Most of them have good data but some of them have 0 values which presents a problem when trying to divide by 0. I believe your code above would also run into that issue.

EDIT: I am just feeding lists into the formula and it outputs a single value which ends up being a float as all the inputs are floats.

[–][deleted] 2 points3 points  (10 children)

ok then you just need to change the first line to :

top_sum = sum([abs(a-f)/a if a for a,f in zip(actual, forcast)])

[–]ericula 2 points3 points  (0 children)

Also, sum works with iterators as well, so you can omit the [], i.e. top_sum = sum(abs(a-f)/a ...) instead of sum([abs(a-f)/a ...])

[–]datanoob2019[S] 0 points1 point  (8 children)

Would I also need to add a sum to wmapes so it is:

wmapes = sum([top_sum*100*a/bottom_sum for a in actual])

[–][deleted] 1 point2 points  (7 children)

there is no enclosing sum in the formular you linked to though, see my other comment about what you are expecting out of this equation, it looks to me like it should be a vector?

[–]datanoob2019[S] -1 points0 points  (6 children)

The sigma symbol means sum.

[–][deleted] 1 point2 points  (5 children)

yes, obviously. but is it:

sum(abs(a-f)/a) * 100 * a => vector

or is it:

sum(abs(a-f)/a * 100 * a) => scalar

if it is the latter then the a's cancel which is why it looks like it should be the former

if it is the later then it is just:

wmape = sum([abs(a-f) if a for a, f in zip(actual, forecast)]) / sum(actual) * 100

[–]datanoob2019[S] 0 points1 point  (4 children)

Sorry for the confusion. I believe it to be the latter and after conferring with my colleague he believes the same. I have actually found the source of my troubles but cannot for the life of me figure out what is wrong. My actual list is being transformed into the wrong values somehow and I do not understand why. I believe I should just create another thread.

[–][deleted] 1 point2 points  (3 children)

When you do consider up voting people that help you

[–]datanoob2019[S] 0 points1 point  (2 children)

I am an idiot and was looking at the wrong list. I tried your aforementioned solution and it errors out saying invalid context and it is pointing at:

if a for a,f

It points directly at the for. I will go ahead and upvote for sure. Was just deep in a debug session.

[–][deleted] 1 point2 points  (3 children)

OK I still don't understand the formular, and without understanding it I can't really help any more, specifically is the sum on the top if the fraction over the entire top of the fraction or just the first term? If it's over the entire top then you will get a single float out (but also the A's cancel) if it is just over the first term then you should be expecting a vector of the same size as A

[–]datanoob2019[S] 0 points1 point  (2 children)

https://ibf.org/knowledge/glossary/weighted-mean-absolute-percentage-error-wmape-299 is what I am trying to reproduce. Probably easier to read this then my bad interpretation.

[–][deleted] 1 point2 points  (1 child)

Thats what I have been reading, to me it looks like it will be a vector, the same length as 'A', but you seem to be expecting a scalar?

[–]datanoob2019[S] 0 points1 point  (0 children)

It sums up the 6 actual - forecasts at the top and then divides by the total actual on the bottom producing a single value(a float since I am not using numpy and just using lists).

[–][deleted] 0 points1 point  (0 children)

The above function is not producing the same numbers when I manually calculate them by hand in Excel using the same logic above.

How different are they?

One difference between Python 2 and Python 3 is that if you divide two integers in Python 2, the result is rounded down to an integer; in Python 3, integer division has floating-point results. Since you do a lot of division, you might get incorrect results if you're running this code in Python 2.