Showing posts with label Forecasting. Show all posts
Showing posts with label Forecasting. Show all posts

June 10, 2014

How to Think About Forecasting

When I graduated college in 1995, I got a job working in Data Warehousing -- setting up reporting systems using a variety of relational and multi-dimensional databases.  It required a balance of financial reporting (i.e., what to report) and data design skills (i.e., how to report it).

Yet, if you asked my grandmother, you'd hear a slightly different story.  As far as she was concerned, "Brett works in computers."   Now, people often said such things in the 1980's, and it's probably acceptable septuagenarian-speak today.    But for most of us, it no longer cuts it.

Working "in Computers"
Why is that?  How is it possible that a phrase that was totally legit in the 80's can now sound so ridiculous? 

The answer:  As a society, we have learned things, and as we learned, language got more precise.   The phrase "in computers" was fine, back when few people did.   But today, it's just a catch-all for a broad array of specialties -- networking, security, graphics, databases, software development, etc. etc. 

Here's the kicker:  As our language evolves, even some of these terms will become too generic.  I already know term that's bound for the trash heap:  Forecasting.

Forecasting isn't really a thing.
These days, I tell people that I do forecasting, and they nod approvingly.  Quite often, they exclaim, "You should talk with So-and-So."  Sometimes I do talk with So-and-So, and find that we have very little, if anything, in common.

Why this?   The answer is simple:  Forecasting isn't one thing.  People picture it as a specialty, like something specific, like database administration or UI development.   People think that it surely has some common base of skills that all forecasters share, the equivalent of a DBA's schema or accountant's general ledger -- but it doesn't.

If you choose any two forecasts, they're likely to be wildly, crazily different.  They can use radically different techniques, different math (or as my Oxford-trained friend puts it: different "maths"),  different error tolerances,  different outcome distributions, etc. etc.

How to Think About Forecasting
I've dreamed up many analogies and descriptions for forecasting, to try to convey to people just how broad forecasting really is (and consequently how devoid of meaning the term is).

Here's the best one I've come up with:  Forecasting is just guessing what's going to happen next.   That's it.

If you think of it in those terms, a lot of what I've written becomes obvious.  You might presume that forecasting is a formal skill -- but what about "guessing what's going to happen next"?  Is that a formal skill?  Not quite so much.

Also, if someone at a party says that they do "Forecasting", you might not your head.  But what if they said, "I guess what's going to happen next."  ...There, you'd probably give them a blank-eyed look, because it's such a meaningless thing to say.

But that's all forecasting really is.

April 20, 2014

Conveying Forecast Error

Whenever you forecast, sometime you'll want to see where you're off a little.  And sometime, you'll want to see where you're off a lot.  You'll need a functional way to express these errors, that let you analyze them in a variety of ways.

I can pretty much step you through what most first-time forecasters do, and then explain where you'll sooner-or-later end up: Using a logarithmic scale.

Bad Method 1:  Using a Linear Scale
Crappier than it seems
At first glance, you'll be tempted to just do it like the picture to the right.  ...So, in this chart, the 130%-140% bucket would contain a forecast of $6.65 for an actual of $5 (6.65/5 = 133%), and the 60%-70% bucket would contain a forecast of $3.25 for an actual of $5 (3.25/5 = 65%).  

This works, right?   Sort of, but it has two big drawbacks:


Static Level of Precision
You probably don't want all of your error buckets to be the same size;  this gets ridiculous pretty quickly.

I mean, reporting upon a 100-110% bucket makes sense -- but what about the 170-180% bucket (are these sufficiently different from 180-190% to warrant their own bucket?).   And it makes zero sense to report a 780%-790% bucket or (even more ridiculous) a 8,920%-8,930% bucket.  And that's what you're gonna get with this approach.


Ideally, your buckets will grow along with your error:  You need fine precision when your forecasts are close, and coarser precision for your big misses -- which you don't get.

Asymmetrically Bounded

On a percentage chart like the one above, the smallest error bucket is fixed:  0-10%.  Your forecast can't get any lower than 0% of actual.  However, your forecast could be a bazillion times higher than actual.  

As a result, when you plot out your error, you'll get a very short "low-tail", and a very long "high-tail".  Among other problems, this makes it impossible to visually scan for forecast bias, because your too-high and too-low forecasts aren't reported in a consistent fashion.  

 
Bad Method 2:  Using a Custom Scale
From there, most people move on to creating customized buckets.  So you'll write statements like this:

If err = 0 then "Match"
else if err > 0 and err <= 1% then "1%"
else if err > 1% and err <= 5% then "1-5%"
else if err > 5% and err < 10% then "5-10%"
else if err > 10% and err < 25% then "10-25%"

...But you'll probably discover that your buckets are always somewhat arbitrary and not quite  pleasing.  And, of course, any time you want more or less-granular buckets, you gotta mess with your equation.

Proper Method:  Use a Log Scale
Reporting upon forecasting error on a logarithmic scale solves all of these problems.
 
But before I jump into using  log-based error groups, let me remind you about logarithms.  (For the rare few of you who are already savvy with logs, feel free to jump ahead.)


Logs 101
Easy, once you get the hang of it.
Logs are the opposite of exponentials, just like subtraction is the opposite of addition, or division is the opposite of multiplication.  So, ya know how since 5 * 2 = 10, then by definition 10 / 2 = 5?  Well, if 53 = 125  then log5(125) = 3.  ...Btw, that five in subscript is called the log's "base."

Logs are much easier to understand if you just see them in action.  The chart to the right shows the log values for certain bases. As you can see, for log base 5, each value represents five times the previous value.   For log base 2, each value represents two times the previous value.

To convert your forecasting error to a log scale, just take the log of the forecast/actuals.  Any base is fine.  With base 2, if your forecast were double your actual, log(200%,2)= 1.   If your forecast were half of your actual, log(50%,2)= -1.  If your forecast matched your actual, log(100%,2)=0.  

What does this buy us?  A lot!

Dynamic Level of Precision
First and foremost, each log value represents a bigger group, which can go from very constrained to enormous.  

Let's say that your forecast is often off by 30%, but you're occasionally off by upwards of 100,000%.  (This especially happens when your actual value unexpectedly drops near zero, where the forecast/actual ratio can be sky-high even for modest forecasts.)

On a linear scale, you can't meaningfully show 30% and 100,000% in the same chart, without the chart being enormous.  Yet on a log base 2 chart, the 30% gets a value of .37, and the 100,000% gets a value of 13.2. 

Amazingly, a log scale allows for fine-tuned precision for accurate forecasts (i.e, you can see the difference between a 5% and a 10% miss), even when reported right next to a 100,000% miss!

Symmetrically Bounded
As I described earlier, on a linear scale, too little precision for forecast that are very low (they're all lumped into the 0-10% bucket), and too much precision for forecasts that are too high (each one gets its own useless bucket, like 8050-8060%).

Logarithms don't have that problem: They represent high and low values on an equal terms.  If you were ever 100x too high, using a log base 2, you'd get a log value of 6.6.   If you were 100x too low, you'd get a log value of -6.6. 

Working Example:
Here, I used Excel to generate 1000 random numbers (each from 1 to 100), and then "forecast" each with another set of semi-random numbers -- based partly upon the original number, and partly upon another random number.  

For kicks, I gave my forecast a subtle positive bias -- it's higher than the actual number a bit too often.

Now, let's plot the error both linearly and logarithmically, and see what we find.

Linear Scale

Ugh, what a disaster. 

First, for one thousand data points, we have 629 buckets.  

Second, ten "low" buckets (0-10%, 10-20%, etc) averaged 28 entries each, while six hundred and nineteen "high" buckets averaged just one entry each.  

Third, because the chart is naturally lopsided, we can't visually see the overt bias in the forecast.

Logarithmic Scale

This is more like it!

First, our chart has only 100 points, instead of six hundred and twenty nine.  Yet our precision was precise where it mattered (i.e., forecasts close to 100% of actuals), and rough when it didn't matter.

Second, you can see that both our high and low values slope away, roughly in symmetry.  Instead of our low forecast crammed into ten groups, and our high values spread out over 619 groups, they're much closer to equal.

Third, you can see instantly that there is a positive forecast bias.  (Focus on the center bar, which represents forecasts near 100% of actuals.  Now compare the bars immediately to its right and left, and then bars two to the right and left.  See how the right bars are always higher?  That's a tell-tale sign of positive forecast bias.)

Conclusion
I probably could have written this entire article in a single sentence:  When reporting forecast error, use a logarithmic scale.

The trouble is, other people had told me that in the past, and I never quite understood why I was doing it, or even knew if I was doing it right.  Hopefully, by describing the drawbacks of the more conventional linear approach, you'll have a bit better understanding of why you should embrace logarithmic error reporting sooner, rather than later!

April 1, 2014

Building Modular Forecasts

The Pain of Smarter Forecasting
Pundits love to expound about how we should use our data "smarter" -- and often they're talking about making smarter forecasts.   Seriously, is there a person alive who would publicly disagree to the importance of making forecasts smarter?   It's quite fashionable to nod our heads vigorously.

...But I wonder how many people have pondered what exactly that means.   What does it mean to make our forecasts smarter?  What does a "smarter" forecast look like?

A lot of people assume it means fancier-shmancier math.  Ya know, eigenvalues and matrix math and whatnot.  That's rarely the case.   ...Indeed (and this topic begs for a separate post), I've witnessed lots of Directors and VP's place undue faith that a statistician can solve behavioral or process problems -- which invariably ends in tears.  Math only gets you so far.

Using the data smarter usually means two things:  1. Performing more steps.  2. Using more disparate data sets.  Basically, a "smarter" forecast does more comparing, inferring, measuring, assessing, extrapolating, interpolating, checking.  A smarter forecast is a more complicated forecast.

Net-net, a "smarter" forecast isn't free; its cost is reduced system explainability.

These days, the goal of staying simple and explainable isn't even ignored, it's practically scorned.  Companies rush towards unfathomably-complicated  forecasts, as if they're the path to salvation.  On some cosmic level, executives believe that as soon as it's so friggin' complicated that nobody understands how the damn thing works, the riches will surely start rolling in.

And here's the kicker:  Forecasts naturally gravitate towards incomprehensibility anyway, which leads me to my first assertion:

Left Unchecked, Forecasts Become Integrated, Inscrutable and Deteriorated.

There isn't one reason for this.  There are probably ten; here are a few that spring to mind:
  1. People are more prone to add logic to, rather than remove logic from, a forecast.
  2. Forecasting algorithms can work in unexpected ways, especially on volatile input data, which means that a forecast is never fully understood, even right after it is written.
  3. The forecast's logic is often split over several systems and/or sets of code. As a result, changes in one area can inadvertently affect the results of the other.
  4. The forecast's data inputs naturally change over time, which causes input data to become stale, inconsistent or even corrupted. 
  5. It's hard to tell when there even is a bug, because it's predicting the freakin' future and past performance is never a predictor of future results.  As a result, problems can fester.
  6. The people who have mastered the heady math might not be good at explaining what they're doing.  ...Worse yet, they might not fully understand how the dang forecast is even used.  As a result, problems might not be detected.
Worst case scenario (which I have seen many, many times):  The forecast integrates a myriad of different data sources, each of which slowly deviates from the forecast's working assumptions about it.  Fewer and fewer people claim to grasp how the forecast works, and nobody wants to take responsibility for (or rely upon) a forecast that they don't understand.  Finally, its performance begins to deteriorate, and nobody is sure how to fix it. 

The Proposal:  Stay Simple and Modular
At the heart of the problem is that many companies build monolithic forecasts:  Too much functionality fed into a big black box, with multiple data feeds coming out the other side.  See that picture above?  That's how it ends up. 

So what do you do about this?

Well, you can ensure your forecasts do not become too complicated by breaking them into simple and well-understood parts, that can be mixed-and-matched.  In other words, resist the natural temptation to build a big monolithic forecast, and focus upon building a series of smaller, simpler, more well-understood components that can be used independently.

I'm not 100% sure how easy/possible/feasible this will be in your circumstances.  But I've gotten it to work on many forecasts.  Let me describe the general approach I took here, using Akamai as an example.

Case Study: Revenue Forecasting

About this client...
Before I describe forecasting revenue I conducted at a client (back in my consulting days), allow me to provide some detail about the company's business model.

This company provides content delivery service, and its customers' invoices are similar to cell phone bills -- only instead of delivering minutes of phone service, they delivers internet traffic.   Just like with cell phone plans, customers can "Commit" to a certain level of usage; generally, the higher a customer's Commit, the lower the per-unit price.  If they push more than their Commit, they pay a per-GB Overage rate -- just like the per-minute Overage when you exceed your cell phone minutes.

Customers with steady traffic typically prefer high Commits (to get the lowest per-GB rate), customer with volatile traffic typically have low Commits (so that they don't pay for traffic that they don't use).  But any customer's traffic can gyrate unpredictably in any given month.

However, one way in which this company is unlike a typical cell phone plan is that the contracts can get rather complicated.  (This is a common phenomenon in B2B companies, where premier customers receive tailored contracts.)   Point being:  Even if you know a given customer's traffic, calculating their invoice amount can be very tricky.

Revenue Forecasting Data
So, when attempting to forecast quarterly revenue, what factors must be considered?  As it turns out, A LOT OF FACTORS.  However, they can generally be broken down into four categories, each with three sub-categories:
  • Traffic Factors:  the levels of content that customers push
  • Contract Factors: the customer contracts Akamai has, and the terms of each contract
  • Invoice Factors: the amounts that appear on the actual invoices
  • Revenue Factors: the amount of invoicing that Akamai recognizes (versus deferrals, rev reserve, credit memos, etc)
 Within each of these categories:
  • Current Data:  The most recent month's data.
  • Historical Patterns:  Patterns in how this data has changed over time.
  • Known Current Adjustments: One-off events scheduled to happen within the forecasted period.
Old vs. New Forecasting Methodologies
Until 2009, the forecast took all of these quite-different inputs, and incorporated them all into a single mega-algorithm, like so:
 Since then, Akamai has transitioned to a new modular forecast.   It works like this:
1. Use only traffic information to make a traffic forecast.
2. Next, use only contract information to forecast what our contracts will look like.
3. Then input our forecasted traffic and forecasted contracts into our invoicing system, to calculate forecasted invoicing.
4. Finally, use historical revenue data to forecast how much of this invoicing we will recognize as revenue.
Benefits of a Modular Approach
You might be wondering:  "Okay, so you went from one super-complicated forecast, to a series of four less-complicated ones.  Did you really come out ahead?"

The answer: Way ahead.  Here are some of the benefits:
  1. Forecast accuracy improved significantly.  As you might imagine, Revenue is really just a bunch of adjustments to Invoicing -- and in this case, we're calculating forecasted Invoicing, based upon forecasted Traffic and Contracts:  We literally use our production Invoicing system to say "Okay, if the contracts look like this, and the traffic looks like that, then how much money will we invoice?"  For a variety of confidentiality reasons, I can't cite specific accuracy levels, but believe me: nobody is complaining about accuracy.
  2. Forecast intuition is very high.  Each part of the forecast (e.g., our traffic forecast, our contract forecast, etc) had sufficiently few inputs that people could wrap their heads around how it worked, and what events would affect the forecast.   As a result, the forecast hasn't turned into a black box, like many other forecasts I've observed. 
  3. Forecasting modules can be swapped in and out.  Sooner or later, we'll need to revamp one of the forecasting modules diagrammed above; but because the forecasts are modularized, it won't introduce risk to the other forecasting modules.
  4. Our intermediary forecasts now sing for their supper.  Originally, we modularized our forecast to yield a simpler and more-accurate model -- but we attained another benefit:  We discovered that groups within the company could use these intermediary forecasts!   Engineering, Finance and Sales use our Traffic, Contracts and Invoicing forecasts -- and even spot opportunities to improve them, which yields a more accurate revenue forecast, to boot!
Conclusion
In most organizations, forecasts naturally gravitate towards becoming monolithic beasts that nobody fully understands, and which then deteriorate over time.  However, by moving towards more modular forecasts, a company can fight this trend, and maintain understandable, accurate forecasts for much longer.

March 25, 2014

The One-in-Ten-Novillion Post




March 22, 2014

Dealing with Outliers

The art of forecasting is, on many levels, the art of averaging.  And when it comes to averaging, outliers are a pain in the ass.  

Outliers wreak havoc on seemingly-level-headed forecasts, and get them to predict crazy things.  Yet, it's often unclear what counts as an outlier -- and if you're not careful, you end up throwing the baby out with the bath water.  To wit, in eliminating your outliers, you risk eliminating material data (i.e., information you want to factor into your forecast).   

So what are you supposed to do about outliers?  Well, first and foremost:
  • There are many ways to handle outliers.
  • The optimal method is very circumstance-specific, in about a dozen ways.
  • Dealing with outliers generally falls into two categories: elimination and mitigation.
Elimination
If you spy any weird values, maybe you can just knock out those values from your averages altogether.
  • Eliminate values above/below a fixed value.
"When calculating the average coffee consumption per employee, ignore employees who drinks more than six cups per day."
This is wonderful, when it works -- it's simple and explainable. However, it assumes that (a) you really can ignore this subset, and (b) you know the precise limit to set. 
Example: Caffeinated Carl averages a dozen cups of coffee per day.  Do we really want to let him skew the average?  (Damn that guy.)
Plus, it assumes that this fixed value doesn't change over time:  Maybe in 1970 drinking three cups would be unusual, but by 2014, that's par for the course.  ...Keep in mind that abruptly changing your criteria (e.g., "for 1970's, eliminate more than three cups.  In the 1980's, eliminate more than four...) will lead to weird discontinuities in your averages.  Smarmy analysis will mock it: "How come you ignored Kona Karen's 3.2 cups in 1979, and then suddenly in 1980 you're including her?"
  •  Eliminate values based upon relative extremes.
"When calculating the coffee consumption per employee, ignore the top/bottom 5%'s.  ...Or ignore any employees whose coffee consumption is more than 2 standard deviations from the group."
On the bright side, this is more flexible.  It elegantly handles natural progressions over time (i.e, as people drink more coffee, you naturally exclude larger drinkers), and doesn't give you discontinuity issues, like Kona Karen introduced above. 

On the down side, it's not quite as explainable:  You won't intuitively know precisely which drinkers would be included/excluded without observing the population set they're being compared to.   Even more vexing, you now need a certain population size or else you can get screwy results.  What happens if you're averaging a group of 3 drinkers, and one of those people is Caffeinated Carl?   Do you want to ignore him or not?   I dunno -- you tell me.  I suppose it depends upon what you're using your forecast for.
Mitigation
Sometimes, for one reason or another, you can't just eliminate extreme values -- especially if your data set is too small.  For example, consider if you were trying to take the average value of -40, 10, 14, 100 -- where both -40 and 100 are kind of outliers.  If you average all of them, the average of 21 might seem too high.  Yet if you eliminate the 100, the average of -5.3 might seem too low.  

In these circumstances, you need some way to acknowledge high and low values, but without letting them run roughshod over your average.
  • Take the Median.
There is some charm in just taking the middle value in any set.  This way, you're not ignoring high or low values -- any high value really does lead to a higher average, and any low value leads to a lower average.

However, if your data is unevenly distributed, it can be misleading.  For example, consider the median in the set -4, -3, -2, -1, 0, 201, 202, 203, 204.   Is a value of 0 really a representative average?  Maybe so, maybe not.
  • Take the Mode.
I've honestly never used the mode once, ever, in any forecast.  The mode is a statistically-cool sounding way of saying "Erm...what do people usually do?  Do that."  I suspect it's good for non-additive values, like the "average" favorite flavor of coffee.  But, hey, it's an option.   
  • Take the Harmonic Mean.
The harmonic mean is supposed to be a good way to average rates, and suppresses the impact of outliers.  You won't get far in forecasting without some would-be statistician recommending the harmonic mean (although they're probably just statistic-name-dropping to up their math cred). 

I've actually already written about how to calculate the harmonic mean (vs the geometric and arithmetic mean).  Check it out here.

I've used the harmonic mean, but sparingly.  For me, it's unclear exactly how much it is mitigating your outliers, and personally I don't like using averages when I can't intuitively fathom how it works.  But, hey, it has its own wikipedia entry, so it's pretty legit.
  • Use the Akamai Outlier Method.
This is a method that I co-developed with Tom Leighton, back when he was Chief Science Officer at Akamai.  ("Co-developed" might be a bit overstated -- he wrote the pseudocode, and I just programmed it.  But I was definitely in the room, so that should count for something.)   Results may vary by use, but it works wonderfully for mitigating outliers in very small data sets.  

I should mention that we didn't define this method just to express our creativity:  we attempted more traditional methods (such as those described above), but they each had edge cases where our forecast was screwy.  This method delivered consistently good results.
Here's how it works: 
  1. Take the arithmetic average of the set.  
  2. Identify the most extreme value in your data set. 
  3. Reduce this extreme value until it is no more than X% farther from the average than the next most extreme value (where X is a pre-defined amount; we settled upon 10%.)
This is a bit tricky, because you'll notice that as you reel in your extreme value, your average is changing, too.   And sometimes (this is a bit of a brain-bender), the second-most extreme value changes as you reel in your most extreme value.
Which method to eliminate/mitigate outliers is best?
If you're new to forecasting, you might think that there's a right answer.  Like, an answer that statisticians everywhere could agree upon.  There's not.  Now, granted, they can tell you if you're applying a method incorrectly, but that's about it.
Good in curries, less so pancakes.
A good forecast is like a recipe.  I can't just say "Come hell or high water, you had better add a teaspoon of paprika, or your meal is going to taste like crap."  It just doesn't work like that.  The best I can do is say, "Cardamom has a smokey flavor that's good on  fish. Crushed red pepper is great on pizza."  You are the chef -- I don't even know what the heck you're even making.
 As unpleasant as it might be to hear, this is your best bet:
  1. Try a bunch of different things.  
  2. Inspect the results closely, from a variety of perspectives.
  3. Decide which outlier-handling method(s) give you the results you prefer.
That's the best I've got.  Good luck!

March 20, 2014

Calculating Seasonality & Trending

If you are attempting to forecast any sort of quarterly/monthly/daily growth rate, you'll likely need to calculate trending and seasonality.  How come?  Because:
  • Things sometimes behave differently during different times of the year.  NORADSanta.org's internet traffic spikes in December, then drops in January. 
  • Things sometimes behave differently over time.  MySpace was on a tear for a while, but not so much these days.
In this post, I'll start by describing Trending and Seasonality a bit, and then step through a very basic way to calculate them.


What is Trending, exactly?
Trending is the long-term compound growth rate of your data.  Let's say that I watched a stock over four years, and it grew from 100 to 400 over that period.   Then it's long-term monthly trend would be:
...that "power()" function is how you'd calculate the value in Excel.  Don't let the root intimidate you; all it's saying is "what number would I have to multiply 100 by forty eight times in a row to arrive at 400?"   And sure enough, if you started with 100, multiplied once is 102.93, multiplied twice is 105.94...forty seven times is 388.61, and forty eight times is 400.

You can calculate different trends, too.  For example, if you have lots of historical data, you could have a long-term trend (say, a stock's behavior over the past 5 years) and then a short-term trend (its behavior over the past six months).
Autumn: divide by 1 leaf.

What is Seasonality, exactly?
Seasonality is the impact that repeating periods have on your data -- hours of the day, days of the week, months of the year, et cetera.   

The trick is, at least for when talking about growth rates, seasonality should be geometrically neutral.   Said in non-geek-speak:  If you multiply together all of your seasonality coefficients, you should get a value of 1.  Said another way, the net effect of seasonality (across all periods) should be no effect whatsoever.

Fortunately, making seasonality geometrically neutral is pretty easy -- I'll show you below.  (One of the perks of calculating seasonality, is that you can tell your co-workers that "naturally, I made sure the seasonality was geometrically neutral."  This may impress them, but be warned: It is unlikely to get you any dates.)

Calculating Trending and Seasonality

In the attached spreadsheet (here), we have four years of time series data for a particular item.  

Winter: add 1/3 cup snow
If you look in the sheet "Creating the Data", you can see how I created the time series, by choosing trending and seasonality values.  Then, in the sheet "Calculation", you can see how, using only the time series data itself, I'm able to derive the time series' trending and monthly seasonality values.  (Granted, this is a basic example -- I have an even number of periods for each season and zero volatility, but I'm focusing upon the base concepts here; we can trick it out later on.)

To calculate trending and seasonality, follow these four steps:

1. Calculate your long-term trend.  
This is precisely as I described above.  In this instance, over forty-eight periods we went from a value of 100 to a value of 657, so our long-term trend is the 48th root of 6.57, which is 104% -- or 4% growth.

2. Determine the month-over-month change.
Easy breezy.  Just divide each value by the previous value, to get the percentage change.   For example, the February and March time series values are 99.84 and 149.52 respectively.  This represents 149.52/99.84 = 149.7% growth for March.

3. De-trend the month-over-month changes.
Here, we're stripping out the long-term trend, so just divide each month-over-month value by the long-term trend.  For example, in March 2010 the value grew by 149.76%, but after we subtract out the 104% seasonality, we're left with 149.76%/104% = 144%.

4. Take the arithmetic average of each month's growth rates, to calculate its seasonality.
Last but not least, you can determine the seasonality for each month by simply (arithmetic) averaging its growth rates.  (Remember, the arithmetic average is the "regular" average -- just add up the growth rates for each month and divide by the number of values.)   In this example, each month always has the same seasonality -- but in real life you'd need to take an average to account for random variability.

Is It Really This Simple In Real Life?
Yes and no.  Trending and Seasonality are faithfully described, and you should be able to use the techniques described here to great benefit, as a mainstay of your forecasting algorithm.  But unfortunately, a forecast is more than just trending and seasonality.

You'll likely have to deal with a bunch of other dynamics, such as these:

  • Lots of random variability (aka "noise") in your data.
  • Uneven number of seasons (e.g., 4 Novembers but 5 Decembers).
  • Blurry or inconsistent data definitions (quite often customer, contract or product)
  • Extreme outliers that skew your averages.
  • Uneven amounts of data for each month.
  • Different long-term and short-term trends.
  • Operationalizing and fostering adoption of financial-centric forecasts.
  • Defining business processes around forecasts.
 ...Some of them I've already covered in other articles; others I'll get to as soon as I can!  Some of these processes help "prep" the data -- so change your data input.  Some others, might affect how you calculate trending and seasonality.  However, on some level, the process will be more-or-less as described above.

March 12, 2014

Not Your Average Mean

Forecasting is all about what's likely to happen, and what's likely to happen is usually an average (aka "mean").  Life would be pretty sweet if there were only one way to calculate a mean.  But there's not -- and if you use the wrong one, your forecast will be wrong.

Sadly, I speak from experience:  I used the wrong average for several months, and couldn't figure out why my results were always overstated.

Which one to use depends upon the type of data you're averaging.  
  •  If you're measuring the same thing fluctuating over different periods (e.g., month-over-month growth rates of a stock), then your variables are dependent, and you need to use the geometric mean.   This is sometimes referred to as a compound average.
To calculate the geometric mean, multiply together the growth rates and take the root of the number of elements.  (Note:  Express them all as a percentage of the previous value -- hence, if a value decreased by half, represent it as .5, and if it doubled, represent it as 2.)
Geometric Mean
  • If you're measuring truly different elements (such as growth rates for a bunch of different stocks), then your variables are independent, and if the values are more-or-less evenly distributed, then you're best off using the arithmetic mean: the "classic" average that we all used in school.
The arithmetic mean is the sum of all values, divided by the number of values.
Arithmetic Mean
  • If you're measuring different elements (i.e., independent variables) but you have crazy outliers that can skew your results (which is most common when averaging rates), you should use the harmonic mean. 
This is the number of values divided by the the sum of the reciprocal of each value.  (<phew!>)
Geometric Mean


Examples!
So, let's say that you're trying to figure out the average return on six stocks, where three decreased by 50% and three increased by 50%.   It would be (.5 + .5 + .5 + 1.5 + 1.5 + 1.5)/6 = 1.  (Right back to where you started)!

...However, let's say that you were trying to calculate the return on a single stock over six periods, where it decreased by 50% three times, and increased by 50% three times.  In that case, it would be (.5 * .5 * .5 * 1.5 * 1.5 * 1.5) ^ (1/6) =  .86.   ...In other words, an average drop of 14% per period.  

Finally, let's say you were taking the average of some internet traffic rates (which are measured in bits per second):  5 Mbps, 8 Mbps, 20 Mbps, 25 Mbps and 5000 Mbps.   Your (harmonic) average would be 5 / (1/5 + 1/8 + 1/20 + 1/25 + 1/5000)  = 12.04Mbps.