<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Analytics Made Skeezy</title> <atom:link href="http://analyticsmadeskeezy.com/feed/" rel="self" type="application/rss+xml" /><link>http://analyticsmadeskeezy.com</link> <description>Analytics explained via story time. Skeezy characters included</description> <lastBuildDate>Fri, 26 Apr 2013 00:22:33 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.5.1</generator> <item><title>Forecasting Continued: Using Simulation to Create Prediction Intervals Around Holt-Winters</title><link>http://analyticsmadeskeezy.com/2013/04/25/prediction-intervals/</link> <comments>http://analyticsmadeskeezy.com/2013/04/25/prediction-intervals/#comments</comments> <pubDate>Thu, 25 Apr 2013 15:52:00 +0000</pubDate> <dc:creator>Alex</dc:creator> <category><![CDATA[Forecasting]]></category> <category><![CDATA[Predictive Modeling]]></category> <category><![CDATA[Simulation]]></category> <category><![CDATA[Holt-Winters]]></category> <category><![CDATA[Meth]]></category> <category><![CDATA[Monte Carlo Simulation]]></category> <category><![CDATA[Prediction Intervals]]></category><guid
isPermaLink="false">http://analyticsmadeskeezy.com/?p=606</guid> <description><![CDATA[NOTE: In this post we&#8217;ll be implementing prediction intervals around the Holt-Winters forecast using Monte Carlo simulation on the error correction/state space model equations for Holt-Winters. Read this post first! &#8230; <a
class="readmore" href="http://analyticsmadeskeezy.com/2013/04/25/prediction-intervals/">Continue Reading &#8594;</a>]]></description> <content:encoded><![CDATA[<p><em>NOTE: In this post we&#8217;ll be implementing prediction intervals around the Holt-Winters forecast using Monte Carlo simulation on the error correction/state space model equations for Holt-Winters. <a
href="http://analyticsmadeskeezy.com/2012/11/15/forecasting-made-skeezy-projecting-meth-demand-using-exponential-smoothing/">Read this post first!</a> I&#8217;d highly recommend following along in the&nbsp;<a
href="https://dl.dropboxusercontent.com/u/98476545/ExponentialSmoothingPIs.xlsm">spreadsheet&nbsp;for this post</a>. And don&rsquo;t forget to <a
href="http://eepurl.com/qsEdr">sign up for the newsletter</a> to hear about future Analytics Made Skeezy tutorials.</em></p><p>&#8220;You lied to me, Alex,&#8221; said Victor. He spoke quietly but with an undeniable hint of anger.</p><p>My mind immediately went to the worst. He knew about my work with the feds. Victor knew he was getting screwed.</p><p>&#8220;What&#8217;d I lie about?&#8221; I asked thinking about which door I should make a run for if things got ugly. There were body guards posted outside the house, and I may look like <a
href="http://en.wikipedia.org/wiki/Steve_Prefontaine">Prefontain</a> but I run like <a
href="http://www.youtube.com/watch?v=E_0Ta_DIWuU">Phoebe Buffay</a>. If things were about to go down, I was likely dead. Even if I did make if out of the house, I&#8217;d been blindfolded on the way here, so I had no idea which way to head for safety.</p><p>&#8220;The forecast you made for my Janaury meth demand. It was wrong!&#8221; he said.</p><p>He brought his voice up to a boom with the word &#8220;wrong,&#8221; and it echoed quickly throughout the empty living room of the McMansion where we sat. Victor&#8217;s appearence was unkempt, and his usual cool tone had been replaced with a frazzled edge.</p><p>Victor was feeling pressure; Agent Bestroff was up to something, and I could guarantee it didn&#8217;t have anything to do with meth demand in Flint michigan. This was about something else, but forecast accuracy was what he was going to take his frustration out on.</p><p>I decided to push back a little on him.</p><p>&#8220;Of course the forecast was wrong,&#8221; I said.</p><p>Victor raised an eyebrow, &#8220;What do you mean, &#8216;of course?&#8217;&#8221;</p><p>&#8220;The only thing you can ever guarantee with a forecast is that it <em>will&nbsp;be</em>&nbsp;wrong. That&#8217;s why forecasting is often called &#8216;organized ignorance.&#8217; It&#8217;s tough to predict the future, especially things that might be impacted by unpredictable forces. Like drug addicts. They&#8217;re inherently unpredictable. As is the economy and the weather,&#8221; I said.</p><p>&#8220;How off was the forecast, exactly?&#8221; I added.</p><p>He shook his head and answered, &#8220;You told me I would sell 72.5 kilos. I only sold 68 kilos.&#8221;</p><p>I nodded, &#8220;Yeah, that&#8217;ll happen with a forecast.&#8221;</p><p>&#8220;Well then why bother? If I can&#8217;t trust it, what&#8217;s the point?&#8221; asked Victor.</p><p>&#8220;Hey, it&#8217;s better than nothing right? If you didn&#8217;t have a seasonally adjusted forecast, then you might just be planning off your gut instead,&#8221; I answered.</p><p>Victor sighed, &#8220;It&#8217;s not good enough. I want a worst case scenario to plan for that way I don&#8217;t have excess drugs sitting on shelves waiting for the cops to find.&#8221;</p><p>&#8220;Ah,&#8221; I answered, &#8220;Now a &#8216;worst case scenario&#8217; is something we can do. We can create something called a <strong>prediction interval</strong>&nbsp;around the forecast. Similar to a confidence interval (but <a
href="http://robjhyndman.com/hyndsight/intervals/">nitpickingly different</a>!), we can put a 95% prediction interval around the forecast so that you&#8217;ll have a likely band of where the demand will fall.&#8221;</p><p>&#8220;And we can do that with the forecast we&#8217;ve already made?&#8221; asked Victor.</p><p>&#8220;Yes and no,&#8221; I answered, &#8220;We can do it with the Holt-Winters forecast and a bit of <a
href="http://en.wikipedia.org/wiki/Monte_Carlo_method">Monte Carlo simulation</a>, but we&#8217;ll need to use some slightly different but equivalent level, trend, and seasonality update equations to make it happen.&#8221;</p><p>&#8220;What do you mean?&#8221; asked Victor.</p><p>&#8220;Well, there&#8217;s this alternative way of doing an exponential smoothing forecast, Holt-Winters included, called the <strong>error correction form</strong>. The numbers come out the same, but they&#8217;re written by forecasting from each period one step into the next, denoting the error between actual demand and that one-step forecast, and correcting the level, trend. and seasonality using that error.&#8221;</p><p>&#8220;And what does that method get us?&#8221; asked Victor.</p><p>&#8220;It will allow us to quantify the distribution of the error when doing a one-step forecast. We can use that distribution to <strong>simulate</strong>&nbsp;future forecast errors, and from those simulated errors we can actually back out an entire demand scenario. By generating a thousand or so demand scenarios based on random errors, we can come up with worst and best case scenarios.&#8221;</p><p>&#8220;OK,&#8221; said Victor, &#8220;So where do we start?&#8221;</p><p>He stood from the table where he sat and walked into the empty kitchen of the house. From an almost barren cabinet in the kitchen he pulled out a gigantic tub of kettlecorn and popped it open.</p><p>&#8220;You want any?&#8221; he asked.</p><p>&#8220;Uh, do I want any kettlecorn?&#8221; I asked, &#8220;No, Victor, I&#8217;m good&#8230;what is this house? Why was I blindfolded on the way here? And why does the place seem cleared out except for a random tin of kettlecorn?&#8221;</p><p>Victor permitted himself a brief chuckle between scowls.</p><p>&#8220;Recently I&#8217;ve had some security issues,&#8221; he said, &#8220;You wouldn&#8217;t know anything about that would you?&#8221;</p><p>&#8220;What kind of issues?&#8221; I asked.</p><p>&#8220;Forget it. My security problems always have a way of working themselves out,&#8221; he said and chomped down hard on a fistful of kettlecorn, &#8220;Let&#8217;s get back to the problem at hand.&#8221;</p><p>I was, for better or worse, growing used to the violent implications in Victor&#8217;s phrasing. I wished briefly that someone would just arrest the guy, so I could go back to my normal life. But then would they want me to testify? Oh lordy. That thought scared the mess out of me. He&#8217;d just whack me from prison or something.</p><p>I pushed that thought away and looked at Victor, &#8220;Can you pull up the spreadsheet we did the demand forecast in?&#8221;</p><p>He pulled out his laptop and threw the sheet open.</p><p>&#8220;OK, <a
href="http://analyticsmadeskeezy.com/2012/11/15/forecasting-made-skeezy-projecting-meth-demand-using-exponential-smoothing/">so if you&#8217;ll remember, last time</a> we finished with this &#8216;HW Exp Smoothing&#8217; sheet and a 12 month forecast,&#8221; I said, &#8220;What&#8217;d I&#8217;d like to do is make a new sheet in the workbook called &#8216;HW Error Correction&#8217; in which we&#8217;ll paste row 1 from the smoothing sheet. We can clear out the MAPE value. We&#8217;re not going to need that. Also, let&#8217;s paste in the time series data from the previous tab and the initial level, trend, and seasonal values in columns D:F.</p><p>This gave us a sheet that resembled the one in the figure below:</p><p><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2013/04/InitialErrorSheet.png" alt="" width="514" height="629" /></p><p>&#8220;Now, to this sheet I&#8217;m going to add another couple of calculations in columns G and H. In G, let&#8217;s put the one-step ahead forecast from our initial values into January 2008,&#8221; I said, &#8220;And if you&#8217;ll remember from last time how to make such a forecast, for one period forward it&#8217;s just the previous level plus the previous trend times the last relevent seasonal adjustment which is F4 in our sheet.&#8221;</p><p>&#8220;So that&#8217;s just (D15+E15)*F4?&#8221; Victor asked.</p><p>&#8220;Yep, and we&#8217;re going to throw that forecast into G16,&#8221; I said, &#8220;and then in column H, we can calculate the one-step error between the forecast in G16 and the actual demand in C16.&#8221;</p><p>This gave the figure show below:</p><p><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2013/04/OneStep.png" alt="" width="607" height="309" />&nbsp;</p><p>&#8220;OK, now how do we roll through time like we did using the previous equations?&#8221; asked Victor.</p><p>&#8220;We need to update the level, trend, and seasonality values and drag everything through all the months until we&#8217;re caught up,&#8221; I said, &#8220;So we&#8217;re going to use some update equations that are equivalent to the originals but rely on our one-step error calculation. First, we&#8217;ll update the level as just the previous level plus the previous trend plus the level smoothing factor <em>times</em>&nbsp;the one-step error divided by the appropriate seasonal factor to deseasonalize the error.&#8221;</p><p>I threw the calculation into the sheet as seen below:</p><p><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2013/04/Level1.png" alt="" width="605" height="306" /></p><p>Victor nodded, &#8220;So the higher the smoothing factor is, the more of the one-step error we adjust for when we update the level.&#8221;</p><p>&#8220;Exactly,&#8221; I said, &#8220;And the trend update works almost exactly the same way. It&#8217;s the previous trend plus the trend smoothing factor times the level smoothing factor times the deseasonalized error. You can think of it as the trend incorporating <em>some</em>&nbsp;of the error the level incorporated to adjust just the trend component.&#8221;</p><p>I put that calculation into the sheet as well:</p><p><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2013/04/Trend1.png" alt="" width="602" height="305" /></p><p>&#8220;And note how those two values, 50.51 and 1.15 are the <em>exact </em>same values we got using the other update equations. All we&#8217;re doing is writing everything in a way that&#8217;s going to be handy to us later on,&#8221; I said.</p><p>Victor nodded, &#8220;So then how do we update the seasonality?&#8221;&nbsp;</p><p>&#8220;It&#8217;s very similar to the trend update although kindof a mirror image. The seasonality update is just the previous relevant seasonality factor plus the seasonal smoothing factor times the error <em>not incorporated</em>&nbsp;into the level divided through by the previous level and trend to put it on a seasonal multiplier scale,&#8221; I said.</p><p>Victor looked slightly confused.</p><p>&#8220;To put it differently, it&#8217;s the seasonal factor from 12 months ago plus the seasonal smoothing factor times 1 minus the level smoothing factor times the error divided by the previous level and trend,&#8221; I said, &#8220;It&#8217;ll make more sense in the spreadsheet.&#8221;</p><p>And so I threw the calculation into the workbook as shown below:</p><p><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2013/04/Season1.png" alt="" width="612" height="318" /></p><p>&#8220;And now, since we&#8217;ve used absolute references on the smoothing parameters,&#8221; I added, &#8220;We can just drag values D16:H16 down through the last month of demand.&#8221;</p><p>Dragging the calculations down, the sheet filled.</p><p>&#8220;Here&#8217;s the cool part though,&#8221; I said, tapping column H on the screen, &#8220;We&#8217;ve now isolated this one-step ahead error column, and assuming our forecast is unbiased, we can calculate the standard deviation of the error, also called the <strong>standard error,</strong>&nbsp;and use that bell curve to simulate future errors.&#8221;</p><p>&#8220;And what is the standard deviation of our errors?&#8221; asked Victor.</p><p>&#8220;Well, up top in cell I1 let&#8217;s calculate the sum of the squared error (SSE) as&nbsp;<span
class="s1">=SUMPRODUCT(</span>H16:H75<span
class="s1">,</span>H16:H75<span
class="s1">) and then the standard error in this context is customarily calculated as the square root of the SSE divided by the number of data points minus the number of smoothing parameters. In our case that&#8217;s 60 minus 3,&#8221; I said and added the calculations to the top of the sheet:</span></p><p><span
class="s1"><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2013/04/StdErr.png" alt="" width="800" height="645" /><br
/> </span></p><p>&nbsp;&#8221;OK, so we&#8217;ve got a standard error that&#8217;s a little over 5, meaning <a
href="http://en.wikipedia.org/wiki/68-95-99.7_rule">68% of one-step errors</a> are within 5 and a quarter kilos of the forecast,&#8221; I said, &#8220;which, by the way, means that my January forecast error wasn&#8217;t all that bad.&#8221;</p><p>Victor nodded, &#8220;Fine, but I still didn&#8217;t know that.&#8221;</p><p>&#8220;True,&#8221; I said, &#8220;So what I&#8217;d like to now do is add the months in 2013 to the bottom of the sheet here and simulate future forecast error values by drawing them randomly from a normal distribution with mean 0 and standard error 5.24. To do that we use the formula =NORMINV(RAND<span
class="s1">()</span>,0,<span
class="s2">K$1</span>).&#8221;</p><p>I tossed the formula in cell H76 for January 2013 and dragged it down, yielding the sheet below:</p><p><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2013/04/Simulate1.png" alt="" /></p><p>&#8220;And now that we have our error, what can we do?&#8221; asked Victor.</p><p>&#8220;This is where the analytics gets pretty badass,&#8221; I said, &#8220;We can drag our calculations in D through G down through the future months just as if the demand had happened. And then using the error plus the one-step forecast, we can back out what the simulated demand is for that future month.&#8221;</p><p>I pulled the formulas in D:G down through row 87 and then backed out demand in C76 as G76+H76 and dragged that down as well, giving the sheet in the image below:</p><p><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2013/04/DemandSim.png" alt="" /></p><p>&#8220;All right!&#8221; I said, clapping my hands together, &#8220;That&#8217;s one possible future demand scenario.&#8221;</p><p>&#8220;And we need to find out what&#8217;s the worst case of these futures?&#8221; asked Victor.</p><p>&#8220;Yeah,&#8221; I nodded, &#8220;We need to generate a ton of these scenarios and discover how they spread out.&#8221;</p><p>&#8220;So how do we generate multiple scenarios?&#8221; asked Victor.</p><p>&#8220;Copy paste,&#8221; I said smiling, &#8220;Well, not quite, but sortof&#8230;lemme show you. Down a bit on the sheet on row 93 I&#8217;m going to write &#8216;Demand Scenarios 2013&#8242; and then below that I&#8217;m going to paste the months of the year going across the columns. Then below that I&#8217;m going to copy 2013&#8242;s simulated demand, and I&#8217;m going to paste-special the values <strong>transposed </strong>into row 95.&#8221;</p><p>That ended up looking like this:</p><p><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2013/04/s1.png" alt="" width="865" height="294" /></p><p>&#8220;And when you paste a scenario, the random numbers above update themselves,&#8221; said Victor.</p><p>&#8220;Exactly,&#8221; I answered.</p><p>&#8220;So you can just copy paste another scenario,&#8221; he said.</p><p>&#8220;Right, but honestly, that takes too long, so instead we&#8217;re going to record a macro to do it for us,&#8221; I said. (Some of you may need to <a
href="http://www.addintools.com/documents/excel/how-to-add-developer-tab.html">show the developer tab on the ribbon in Excel </a>to do this step.)</p><p>I navigated to the record macro button on the developer tab of the Excel ribbon. And pressing the record button, I named the macro and assigned it a shortcut key for fast access later:</p><p><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2013/04/Macro.png" alt="" /></p><p>Pressing OK, I did the following steps:</p><ol><li>Inserted a new, blank row 95</li><li>Copied the 2013 simulated demand data in column C</li><li>Did a paste-special values transposed onto my new blank row 95</li><li>Pressed stop on the macro recording</li></ol><p>&#8220;And now that we have our macro. We just need to press the shortcut key a lot to generate scenarios. Actually, you can just hold the buttons down and it&#8217;ll run through it on its own,&#8221; I said and pressed option + command + z on Victor&#8217;s Mac for a few minutes until I had just over 1000 scenarios.</p><p>Then on row 89, I calculated the 97.5th percentile of each of the simulated columns, on row 90, I pasted the transposed forecast values from the previous tab, and on row 91, I pulled the 2.5th percentile, giving me the following:</p><p><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2013/04/Precentile.png" alt="" /></p><p>&#8220;So here we now have our forecast and upper and lower 95% interval bounds on it that we&#8217;ve found by simulating the forecast error,&#8221; I said, &#8220;So you can be quite confident that whatever demand you experience over the next year will fall inside these bounds.&#8221;</p><p>Victor smiled wide for the first time that day, &#8220;Great!&#8221;</p><p>&#8220;And we can highlight these three rows, select the area chart in Excel, and then format the bottom series with a white fill in order to get what folks in the forecasting business call a <strong>fan chart</strong>,&#8221; I said and inserted the chart for him.</p><p><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2013/04/Fan.png" alt="" width="707" height="557" /></p><p>&#8220;And note how the error compounds over time. Also, due to the multiplicative nature of the forecast, the absolute width of the interval increases in high seasonal demand periods,&#8221; I added.</p><p>&#8220;Wow, that&#8217;s nice,&#8221; said Victor.</p><p>It was my turn to smile, &#8220;Consider your ignorance about the futre quantified.&#8221;</p><h2>Big Data-ish Tip</h2><p>Credit goes to Hyndman for developing the state equations for Holt-Winters that make this whole simulation approach possible. As part of that work, he also derived closed-form calculations for the prediction intervals, but I&#8217;m extremely partial to this monte carlo approach because it&#8217;s so intuitive (and intuition is really what exponential smoothing is all about).</p><p>Hyndman wrote all the good forecasting packages in R, and I highly recommend checking out his <a
href="http://robjhyndman.com/hyndsight/r/">blog</a>&nbsp;as well as his (unfinished?) <a
href="http://otexts.com/fpp/">online textbook</a>. Personally, I find <a
href="http://www.amazon.com/Forecasting-Time-Regression-CD-ROM/dp/0534409776">Bowerman&#8217;s 2004 textbook</a>&nbsp;to be the best for learning a lot of this stuff.</p> ]]></content:encoded> <wfw:commentRss>http://analyticsmadeskeezy.com/2013/04/25/prediction-intervals/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Author note: I&#8217;m still alive! (Just writing a book)</title><link>http://analyticsmadeskeezy.com/2013/04/25/author-note-im-still-alive-just-writing-a-book/</link> <comments>http://analyticsmadeskeezy.com/2013/04/25/author-note-im-still-alive-just-writing-a-book/#comments</comments> <pubDate>Thu, 25 Apr 2013 15:48:00 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[Uncategorized]]></category><guid
isPermaLink="false">http://analyticsmadeskeezy.com/?p=642</guid> <description><![CDATA[Hey folks. John here. I know I haven&#8217;t updated the blog in a while. Although I did just post a new forecasting tutorial that&#8217;s a lot of fun if you &#8230; <a
class="readmore" href="http://analyticsmadeskeezy.com/2013/04/25/author-note-im-still-alive-just-writing-a-book/">Continue Reading &#8594;</a>]]></description> <content:encoded><![CDATA[<p>Hey folks. John here. I know I haven&#8217;t updated the blog in a while. Although I did just post a <a
href="http://analyticsmadeskeezy.com/2013/04/25/prediction-intervals/">new forecasting tutorial</a> that&#8217;s a lot of fun if you read the <a
href="http://analyticsmadeskeezy.com/2012/11/15/forecasting-made-skeezy-projecting-meth-demand-using-exponential-smoothing/">first one</a>. I have been super busy doing things:</p><p><span
style="font-size: x-large;"><strong>Speaking and cheating on this blog</strong></span></p><p>Here&#8217;s a blog post I wrote over at the Strata blog: <a
href="http://strata.oreilly.com/2013/02/your-analytics-talent-pool-is-not-made-up-of-misanthropes.html">Your analytics talent pool is not made up of misanthropes</a>. And a fun one from the MailChimp blog <a
href="http://blog.mailchimp.com/sending-frequency-more-is-not-always-better/">here</a>. And I&#8217;ve been speaking. For instance, there&#8217;s this video of me speaking at Strata on how MailChimp is using data to do awesome things:</p><p><iframe
width="640" height="360" src="http://fast.wistia.net/embed/iframe/4h103h8nl9?controlsVisibleOnLoad=tr ue&amp;version=v1&amp;videoHeight=360&amp;videoWidth=640" frameborder="0"></iframe></p><p>Upcoming other talks:</p><p>6/20-21 Big Data Summit in Toronto</p><p>10/6 INFORMS Annual Meeting</p><p><span
style="font-size: large;"><strong>Hacker News debacle of 2013</strong></span></p><p>You may have missed it, but Analytics Made Skeezy made it to #1 on Hacker News. For all of a minute. Then the site immediately went down. Then HostGator made sure it stayed down for a couple weeks. So I&#8217;ve been struggling to get the AMS house in order. I think today we&#8217;re in a slightly better spot than we were. My apologies.</p><p><span
style="font-size: x-large;"><strong>The Book!!!!!</strong></span></p><p>I&#8217;ve been writing an analytics book!</p><p><img
src="http://25.media.tumblr.com/tumblr_lzk8u1ziJl1qfhca2o1_500.jpg" alt="" width="500" height="320" /></p><p>It&#8217;s an ongoing effort that was inpired by this blog, actually.</p><p>It&#8217;s called <em>Data Smart: Using Data Science to Transform Information into Insight</em>. Yeah, yeah, I know. It&#8217;s no &#8220;Analytics Made Skeezy,&#8221; but the publisher (Wiley) would only meet me so far on that. I think they were afraid that people might review the book negatively on Amazon due to the crime element.</p><p>So here are the details:</p><ul><li>The book, like this blog, will be in Excel (2007, 2010, or 2011 for Mac)</li><li>Unlike this blog, it will not be a narrative. It&#8217;ll be guided learning, but I maintain a large presence in the book and promise all sorts of cheesy groaning humor</li><li>The book is written with greater care than this blog. These blog posts take me a couple of days from start to finish. There are errors on the blog. Indeed, I think I mess up the metric system not once but twice! The chapters in the book on the other hand take up to a month to prepare. I go through techniques thoroughly. There are about 4x as many figures, and I try to call out differences in software where applicable.</li><li>Topics covered are:&nbsp;</li></ul><ol><li>Linear and nonlinear programming including Big M constraints, linearizing multiplied variables, and simulation optimization</li><li>K-means clustering, K-medians clustering, the silhouette, and asymetric distance calculations</li><li>Graph modularity maximization for clustering (in Excel and in Gephi&#8230;this is the only implementation of divisive clustering through modularity maximization that I know of, especially in Excel. Fun stuff.)</li><li>Linear regression and the use of a logistic link function for &#8220;AI&#8221;</li><li>Ensemble AI models and node purity calculations &#8212; we&#8217;ll implement bagged decision stumps in Excel to give a flavour for how it works</li><li>Forecasting using SES, Holt&#8217;s Trend, and Holt-Winters. R-squared, the F test, autocorrelation, and prediction intervals with Monte Carlo sim are also covered in this chapter. Hell, we&#8217;ll even make a correlogram complete with dashed critical value lines. Sweet!</li><li>Naive Bayes (in Excel???) &#8212; Haven&#8217;t finished this chapter yet.</li><li>Outlier detection techniques including LOF</li><li>Multi-criteria decision analysis techniques</li></ol><ul><li>The book will come with some ridiculously thorough spreadsheets for download that put this blog to shame. And the examples worked will be from other business topics than the drug trade.</li></ul><p>Now, this book is not for academics. It&#8217;s for folks who feel a little left behind by this whole data science thing and want to learn some techniques in a familiar environment without having to simultaneously learn to code. For production applications, I still think a lot of this should be implemented in OPL, R, etc., but those environments don&#8217;t facilitate learning like Excel does. You can&#8217;t learn modularity maximization in Gephi &#8212; you can just learn to press the button. We&#8217;re going to dig deep and actually learn this stuff.</p><p>Why? Because if you really <em>know</em> the techniques (even if you forget a little) then your abilitiy to identify opportunities to use them in a business context increases. And you&#8217;re not gun-shy; you&#8217;ve got some confidence.</p><p>Anyway, sign up for the AMS newsletter, and I&#8217;ll be updating everyone as we get nearer to release. Alternatively, I&#8217;ll be posting book-related info at john-foreman.com</p><p>Hugs,</p><p>John</p> ]]></content:encoded> <wfw:commentRss>http://analyticsmadeskeezy.com/2013/04/25/author-note-im-still-alive-just-writing-a-book/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Intrusion Detection Made Skeezy: How do you find the DEA in a haystack?</title><link>http://analyticsmadeskeezy.com/2012/11/29/intrusion-detection-made-skeezy-how-do-you-find-the-dea-in-a-haystack/</link> <comments>http://analyticsmadeskeezy.com/2012/11/29/intrusion-detection-made-skeezy-how-do-you-find-the-dea-in-a-haystack/#comments</comments> <pubDate>Thu, 29 Nov 2012 17:07:50 +0000</pubDate> <dc:creator>Alex</dc:creator> <category><![CDATA[Clustering]]></category> <category><![CDATA[Data Mining]]></category> <category><![CDATA[Graphing]]></category> <category><![CDATA[Intrusion Detection]]></category> <category><![CDATA[Local Outlier Factors]]></category> <category><![CDATA[Outlier Detection]]></category><guid
isPermaLink="false">http://analyticsmadeskeezy.com/?p=513</guid> <description><![CDATA[NOTE: In this post we&#8217;ll be implementing the Local Outlier Factor algorithm introduced in 2000 by Breunig et. al. I&#8217;d highly recommend following along in the spreadsheet for this post. And don’t &#8230; <a
class="readmore" href="http://analyticsmadeskeezy.com/2012/11/29/intrusion-detection-made-skeezy-how-do-you-find-the-dea-in-a-haystack/">Continue Reading &#8594;</a>]]></description> <content:encoded><![CDATA[<p><em>NOTE: In this post we&#8217;ll be implementing the <a
href="http://www.dbs.ifi.lmu.de/Publikationen/Papers/LOF.pdf">Local Outlier Factor algorithm introduced in 2000 by Breunig et. al</a>. I&#8217;d highly recommend following along in the <a
href="https://dl.dropbox.com/u/98476545/OutlierDetection.xlsx">spreadsheet for this post</a>. And don’t forget to sign up for the newsletter to hear about future Analytics Made Skeezy tutorials.</em></p><p>&#8220;We have a problem Alex,&#8221; said Victor. We sat together on a bench outside the Great American Scream Machine at Six Flags. I was beginning to suspect that Victor was picking these bizarre meeting locations on purpose. Certainly no one had stuck a hidden mic under this bench, although plenty of folks had stuck their gum there.</p><p>The evening air smelled of sweet garbage, like a rotten apple core. And the rickety roller coaster clacked up the first hill in the distance. Victor watched it through slit, thoughtful eyes. I&#8217;d never seen him like this. A scruffy beard, he fidgeted slightly.</p><p>&#8220;What kind of problem?&#8221; I asked nervously. I knew the normal Victor was a dangerous man; I assumed the paranoid Victor wouldn&#8217;t be much better.</p><p>He turned and looked at me, &#8220;There&#8217;s a fox in my henhouse.&#8221;</p><p>&#8220;What do you mean?&#8221; I asked. Someone on the roller coaster shrieked as it tumbled down a hill.</p><p>&#8220;I have a source within the DEA,&#8221; he said, eyeing me carefully as he spoke, &#8220;And this source has told me that there is a Judas waiting to betray me.&#8221;</p><p>My throat was beginning to close, and my heart leapt.</p><p>&#8220;Who is it?&#8221; I asked, faking a calm curiosity.</p><p>&#8220;A coke supplier is all I know. They&#8217;ve set a trap for me and some of my competition. But I don&#8217;t know which supplier,&#8221; He shook his head, &#8220;Which is terrible because there&#8217;s a shortage right now from all the gang violence south of the border, and I&#8217;m having to make deals with stranger and stranger suppliers just to meet demand.&#8221;</p><p>I breathed a sigh of relief. I wasn&#8217;t the traitor. At least not this time. But the fact that the DEA had a mole didn&#8217;t bode well for me. I made a note to warn Agent Bestroff.</p><p>&#8220;So do you have any clues?&#8221; I asked.</p><p>&#8220;I have a short list,&#8221; said Victor, &#8220;A list of all the coke suppliers offering up their goods to me right now who&#8217;ve passed basic vetting. But I have no idea which one has been turned.&#8221;</p><p>I nodded, &#8220;You got any data on these guys?&#8221;</p><p>&#8220;Yeah,&#8221; he said, &#8220;I&#8217;ve got some data. Simple checks we run, supply chain info, price, and availability data, but honestly, I already looked through it, and I didn&#8217;t see anything funny.&#8221;</p><p>He opened a spreadsheet that looked like this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/RawData.tiff.jpg"><img
class="alignnone size-full wp-image-515" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/RawData.tiff.jpg" alt="" width="833" height="323" /></a></p><p>&#8220;Here they are,&#8221; he said with a shrug, &#8220;All 249 of them. I looked at their prices, the quantities they offered&#8230;we&#8217;ve got small and large players, but no one&#8217;s an outlier.&#8221;</p><p>I smiled, &#8220;That&#8217;s an interesting word you use, &#8216;outlier.&#8217; How&#8217;d you check to see if you had any outliers?&#8221;</p><p>&#8220;I looked on the list for anyone named &#8216;Judas,&#8217;&#8221; he said with a laugh, &#8220;No, I computed the means and standard deviations for the price and quantity columns, but no values seemed too far from the others. And I made graphs of the numeric data, but it all looks fine.&#8221;</p><p>He pulled up a graph of the available coke each supplier had for sale:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/AvailableGraph.png"><img
class="alignnone  wp-image-516" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/AvailableGraph.png" alt="" width="479" height="395" /></a></p><p>&#8220;You can see from the jump in the graph that we&#8217;ve got about 80% small time suppliers and 20% or so larger suppliers,&#8221; said Victor, &#8220;But a minimum of 500 kg for sale is not extraordinary nor is a max of 5000 kg. These values are all expected.&#8221;</p><p>&#8220;And the same is true for the other numeric columns here?&#8221; I asked. Victor nodded yes.</p><p>&#8220;So we&#8217;re bumping up against a couple of issues in intrusion detection,&#8221; I said, &#8220;The first problem is that you&#8217;re looking at each column individually for an outlying variable, but maybe this fox is hiding right in the middle of your henhouse, and only when we examine all the data holistically will we find him. And by all the data, I mean this text data too.&#8221;</p><p>I pointed to all the categorical information in the spreadsheet, the &#8216;Y&#8217;s and &#8216;N&#8217;s and shipping methods.</p><p>&#8220;You said there were a couple issues here. What&#8217;s the other one?&#8221; Victor asked.</p><p>&#8220;Well, taking means and standard deviations are terrible for finding outliers here, even if we could do the analysis column by column, because as we can see from the jump in the graph, your data is pretty oddly distributed. Furthermore, when you take a mean or a standard deviation, those values actually <em>include</em> any outlying values in them. You should be using more <a
href="http://en.wikipedia.org/wiki/Robust_statistics#Examples_of_robust_and_non-robust_statistics">robust statistics</a> of spread and centrality.&#8221;</p><p>&#8220;What do you propose then?&#8221; asked Victor.</p><p>I thought for a moment, &#8220;Well, if there is an intruder in this data, a &#8216;wolf in sheep&#8217;s clothing&#8217; as they say, then the first thing we should search for are people who may not necessarily be outliers globally on any one value but who nevertheless look unlike the suppliers nearest them. They&#8217;re trying to fit in with some subgroup of suppliers here, &#8216;putting on the sheep&#8217;s clothing,&#8217; but they&#8217;re failing.&#8221;</p><p>&#8220;But let&#8217;s back up a minute. Can you explain all the columns in this sheet to me?&#8221; I asked.</p><p>&#8220;Of course,&#8221; said Victor. He distractedly smiled as he watched a boy walk by carrying an over-stuffed bear he&#8217;d won. The uncomfortable bench we sat on was starting to hurt my butt, and it irritated me that I&#8217;d had to fork over $30 just to meet a drug dealer inside an amusement park when the parking lot would have sufficed.</p><p>Victor turned his eyes back to the sheet.</p><p>&#8220;So the &#8216;Operate Own Transpo&#8217; column is pretty straightforward,&#8221; he said, &#8220;Some suppliers contract out to drug runners, while others own and operate that vertical. Usually the larger guys will operate their own running operations.&#8221;</p><p>&#8220;The column next to it is the smuggling method they prefer to use,&#8221; he continued, &#8220;Personally, I don&#8217;t like to deal with someone who uses drug mules unless I have to. Too messy, too many things go wrong, and the quantities they can smuggle are small. The new narco subs are the most reliable, but even a car across the Canadian border through the Chippewa Indian Reservation isn&#8217;t a bad risk.&#8221;</p><p>&#8220;And what does &#8216;Counterintel?&#8217; mean?&#8221; I asked.</p><p>&#8220;Do they have any counterintelligence they can bring to the table?&#8221; he said, &#8220;As in, do they have any tipsters in law enforcement? Do they have inside information that tips the scales in favor of successful transfers of product? Once again, the larger organizations are more likely to have this.&#8221;</p><p>&#8220;Then why not go with the larger guys every time?&#8221; I asked.</p><p>&#8220;Well,&#8221; said Victor, smiling, &#8220;Economies of scale don&#8217;t trickle down to pricing in the drug trade per se. The large guys are less likely to lose a load, get caught, get you busted, poison your customers, but they charge a hefty premium for their higher level of service. Much like shopping at the nice grocery store here in town, Publix I think it&#8217;s called, you pay extra for the nice experience. On top of that, I need the small guys to meet my total demand across the U.S.&#8221;</p><p>&#8220;Who are Jimbo, Stevie, and Margalo?&#8221; I asked, pointing to the next columns in the spreadsheet.</p><p>Victor laughed, &#8220;Strange, right? They&#8217;ve actually my competition in some major cities, but we pool information on suppliers. If one of them can vouch for a supplier, that&#8217;s better than nothing.&#8221;</p><p>Victor held a finger up, &#8220;But you can&#8217;t always trust it. You never know when they might get together and burn you. If one of them were to get busted, they could start feeding bad intel to the rest of the group.&#8221;</p><p>I nodded, &#8220;And the &#8216;Criminal Record&#8217; column is whether the supplier has a criminal record?&#8221;</p><p>&#8220;Yes, their leadership,&#8221; he said, &#8220;Believe it or not, that&#8217;s a plus in this line of business. People who seem too clean often are.&#8221;</p><p>&#8220;What&#8217;s &#8216;need to meet?&#8217;&#8221; I asked.</p><p>&#8220;The exchange, money for product, can either go down in a meet or a drop. If you do a meet, the supplier is less likely to get burned because the bags change hands at the same time. But it&#8217;s dangerous and unpredictable. The big guys often prefer to just do a drop. Leave the drugs in the trunk of a car and get the money from you where you leave it. Clean hands. But many of the littler guys can&#8217;t afford to front the loss of even one shipment so they&#8217;re more likely to insist on a person-to-person meet,&#8221; said Victor, &#8220;As for the last three columns in the sheet, they&#8217;re all self-explanatory: the number of times we&#8217;ve personally dealt with the supplier, the max coke we can currently buy from them, and the price per kilo.&#8221;</p><p>I nodded, &#8220;Ok, so the first thing we need to do is get this categorical data into something we can analyse. We&#8217;re going to convert all the yes/no questions into +1/-1 values, and we&#8217;re going to take that transportation method column and split it into dummy variable columns with a 1 in the slot of the transportation method they prefer similarly to how we did it for our <a
href="http://analyticsmadeskeezy.com/2012/10/29/introduction-to-machine-learning-logistic-regression-for-predicting-bad-trips/">LSD trip AI model</a>.&#8221;</p><p>&#8220;Yes, I remember <a
href="http://en.wikipedia.org/wiki/Dummy_variable_(statistics)">dummy variables</a>,&#8221; said Victor tapping his temple with his index finger.</p><p>I created a new sheet called &#8220;Numeric&#8221; and filled it in with the converted data using simple IF() formulas:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Numeric.tiff.jpg"><img
class="alignnone size-full wp-image-518" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Numeric.tiff.jpg" alt="" width="873" height="176" /></a></p><p>&#8220;So now the data is numeric, but what do we do with it?&#8221; asked Victor.</p><p>&#8220;Well, we&#8217;re going to compute a value for each supplier called their &#8216;Local Outlier Factor&#8217; or LOF for short,&#8221; I said.</p><p>&#8220;And what will the LOF tell us?&#8221; asked Victor.</p><p>&#8220;The LOF is a single number that when it&#8217;s near 1 means &#8216;Hey, I look like all the suppliers whose data is most similar to mine&#8217; and when it&#8217;s far greater than 1 it means &#8216;Hey, I look unusually different from those suppliers whose data is most similar to mine,&#8217;&#8221; I answered, &#8220;It&#8217;s a local outlier detection method as opposed to a global outlier detection method, meaning that while the outlying supplier may not be worlds away from everyone in this data set, he&#8217;s odd when compared to his closest peers.&#8221;</p><p>Victor gave a face that he tentatively accepted what I was saying.</p><p>I smiled, &#8220;It&#8217;s a bit of a journey to get there, but I swear once you see the result, you&#8217;ll get it.&#8221;</p><p>&#8220;OK,&#8221; said Victor, &#8220;So what do we do with this numeric data?&#8221;</p><p>&#8220;Well, the first thing we&#8217;re going to do is scale and center it,&#8221; I said, &#8220;So I&#8217;m going to take the <a
href="http://en.wikipedia.org/wiki/Truncated_mean">trimmed mean</a> and <a
href="http://en.wikipedia.org/wiki/Absolute_deviation">mean absolute deviation</a> of each column to start.&#8221;</p><p>I added it two rows at the bottom of the numeric data.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/MeanAndMAD.tiff.jpg"><img
class="alignnone size-full wp-image-520" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/MeanAndMAD.tiff.jpg" alt="" width="883" height="307" /></a></p><p>&#8220;The trimmed mean is just like a regular mean except that I&#8217;m gonna toss out the lowest and highest 5% of values from each column to prevent any outliers in a single column from skewing the mean. A trimmed mean is kindof like what they use when judging gymnastics meets and they &#8216;throw out the highest and lowest scores.&#8217;&#8221;</p><p>&#8220;Ah,&#8221; said Victor, &#8220;That makes sense.&#8221;</p><p>&#8220;And the mean absolute deviation is just the average of the absolute values of the differences between each value and the trimmed mean. It&#8217;s like <a
href="http://en.wikipedia.org/wiki/Variance">variance</a> except we&#8217;re using absolute values instead of squared values to minimize the effect of any outliers,&#8221; I said.</p><p>&#8220;OK,&#8221; said Victor as he peered at the sheet, &#8220;And what do we do with them?&#8221;</p><p>&#8220;Well,&#8221; I said and created a new sheet called Scaled, &#8220;We&#8217;re going to subtract the trimmed mean from each value in the sheet to center the values around 0. Then we&#8217;ll divide through by that column&#8217;s mean absolute deviation. That&#8217;s going to take something like the price column and put it on the same scale as the &#8216;# of Past Deals&#8217; column, so that no column is going to be numerically more important than any other just because it&#8217;s got a big scale.&#8221;</p><p>I filled in the &#8216;Scaled&#8217; spreadsheet, showing Victor how, for example, in the Transpo column for the supplier &#8216;Abraham&#8217; (B2) its new scaled value was just its old numeric value minus the mean divided by the spread. <a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/ScaledFormula.tiff.jpg"><img
class="alignnone size-full wp-image-522" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/ScaledFormula.tiff.jpg" alt="" width="880" height="134" /></a></p><p>&#8220;Now we have all numeric, scaled data,&#8221; I said, smiling.</p><p>&#8220;And we use it to tell suppliers apart?&#8221; asked Victor.</p><p>&#8220;We want to use it to measure the distance between each pair of suppliers,&#8221; I said, &#8220;And by distance, there&#8217;s a lot of different distance metrics out there.&#8221;</p><p>&#8220;Like the <a
href="http://en.wikipedia.org/wiki/Cosine_similarity">cosine similarity</a> we used on my <a
href="http://analyticsmadeskeezy.com/2012/10/11/graphing-clustering-community-detection-wholesale-drug-deals-using-excel-and-gephi/">wholesale</a> data?&#8221; asked Victor.</p><p>&#8220;Yes, exactly, although this time let&#8217;s keep it simple and just use <a
href="http://en.wikipedia.org/wiki/Euclidean_distance">Euclidean distance</a>,&#8221; I said.</p><p>&#8220;So when measuring the distance between two suppliers, then,&#8221; said Victor, &#8220;That&#8217;s just the square root of the sum of the squared differences of the values from each of the columns?&#8221;</p><p>&#8220;Yep, just like you used to do in elementary school when you calculated the length of the hypotenuse of a triangle as the square root of the height squared plus the length squared,&#8221; I said.</p><p>I created a new tab in the workbook called &#8220;Distances&#8221; and filled it with a Suppliers X Suppliers grid.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Distances.tiff.jpg"><img
class="alignnone size-full wp-image-524" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Distances.tiff.jpg" alt="" width="801" height="132" /></a></p><p>&#8220;Can you explain that Excel formula to me?&#8221; asked Victor.</p><p>&#8220;Sure,&#8221; I said and pointed to the top left distance in the spreadsheet, &#8220;I&#8217;m looking up the scaled data for the supplier for this row using a VLOOKUP and pulling out the numeric columns I want from the previous sheet with that curly braced list. I&#8217;m doing the same VLOOKUP for the column. Then I&#8217;m taking the difference between the two sets of looked up values, squaring each difference, summing up the list, and taking the square root a la Euclidean distance.&#8221;</p><p>Victor nodded, &#8220;And this is another one of your array formulas?&#8221;</p><p>&#8220;Yes,&#8221; I said, &#8220;Since we&#8217;re using the VLOOKUP to grab a list of values which we&#8217;re subtracting from another list, we need to use an <a
href="http://office.microsoft.com/en-us/excel-help/introducing-array-formulas-in-excel-HA001087290.aspx">array formula</a> in Excel instead of a regular one to do that list operation. And to use an array formula, I just type the formula normally into the cell and then instead of hitting return I hit &#8216;control/command + shift + return&#8217; to engage it. That&#8217;s what added those curly braces around the entire formula.&#8221;</p><p>&#8220;So now we have a distance between each (row, column) pair of suppliers?&#8221; asked Victor.</p><p>&#8220;Exactly,&#8221; I said, &#8220;Very similar to the grid we made for the <a
href="http://analyticsmadeskeezy.com/2012/10/11/graphing-clustering-community-detection-wholesale-drug-deals-using-excel-and-gephi/">wholesale customer clustering</a> we did a while back. And the next thing we&#8217;re going to do is rank them. For a given column, we&#8217;re going to replace the distance to the supplier in a row with its rank-order starting with nearest first. Since the self-distance is on the diagonal, we&#8217;ll start the rankings at 0 to make it easy to ignore the self-distance.&#8221;</p><p>I created a new sheet called &#8216;Rank&#8217; with the rankings. The formula for the top left rank looked like this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Rank.tiff.jpg"><img
class="alignnone size-full wp-image-529" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Rank.tiff.jpg" alt="" width="572" height="94" /></a></p><p>&#8220;So you&#8217;re just using the RANK() formula to look up a distance and compare it to the rest of the distances on that column?&#8221; asked Victor.</p><p>&#8220;That&#8217;s it,&#8221; I said and made another sheet called &#8216;Rank-Inv&#8217; which was a transpose of the rankings so they were row-oriented.</p><p>&#8220;Now,&#8221; I said, &#8220;The reason why this approach is called Local Outlier Factors is because it compares how dense a local neighborhood of points is gathered around you to how dense the neighborhoods are around those points neighboring you. If your neighborhood is  bit watery compared to the neighborhoods around you, then you&#8217;re an outlier. The people you consider your friends, don&#8217;t consider you much of a friend.&#8221;</p><p>&#8220;So how big is a neighborhood?&#8221; asked Victor.</p><p>&#8220;Well,&#8221; I said, &#8220;The size of the neighborhood is the only parameter we need to choose when calculating LOFs.&#8221;</p><p>&#8220;And what do we set it to?&#8221; asked Victor.</p><p>I shrugged, &#8220;Let&#8217;s start with a neighborhood of 5 points. The algorithm is fairly robust to changes in the size of K, but 5 is a good place to begin. And we&#8217;re going to create a sheet of &#8216;reach distances&#8217; where if you&#8217;re in my neighborhood of 5 closest points, then your reach distance with respect to me is the distance to the perimeter of the neighborhood, but if you&#8217;re outside of my neighborhood, then the reach distance to you is our actual distance.&#8221;</p><p>Victor looked confused.</p><p>&#8220;Think of it like Lord of the Rings. If I&#8217;m the King of Gondor and you&#8217;re in my kingdom, i.e. Gondor, then the reach distance to you is the city walls. But if you&#8217;re not in my walled city, if you&#8217;re in say, Minas Tirith, then the reach distance between you and me is just our actual distance.&#8221;</p><p>&#8220;I hated that movie,&#8221; said Victor, &#8220;but I think I&#8217;m following you.&#8221;</p><p>&#8220;How can you hate Lord of the Rings?&#8221; I asked.</p><p>&#8220;I liked all the evil creatures,&#8221; he said, &#8221;But the nice ones, the elves and the like, they were silly and poorly done.&#8221;</p><p>An international criminal would think that, wouldn&#8217;t he, I thought. But I said nothing.</p><p>I added a sheet called &#8216;Reach-dist,&#8217; filled in &#8217;5&#8242; as the size of the neighborhood, and then calculated the distance to the fifth and furthest point within each supplier&#8217;s neighhood, called the &#8216;K-distance.&#8217;</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/K-distance.tiff.jpg"><img
class="alignnone size-full wp-image-531" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/K-distance.tiff.jpg" alt="" width="606" height="142" /></a></p><p>Victor leaned in to read the formula, &#8220;So you&#8217;re going over to the Rank sheet, finding the rank that&#8217;s equal to 5, setting that value equal to 1 and the rest to 0, and then multiplying that unit vector with the column&#8217;s distance vector before summing that up. All that really does is just look up the fifth ranked distance in the end.&#8221;</p><p>&#8220;That&#8217;s right,&#8221; I said, &#8220;It&#8217;s just a ghetto-hacked lookup across the &#8216;Rank&#8217; and &#8216;Distances&#8217; sheets. And to do that array calculation, we have to make the whole thing into an array formula.&#8221;</p><p>He nodded, &#8220;That makes sense.&#8221;</p><p>&#8220;OK,&#8221; I said, &#8220;So now we&#8217;re going to copy in all the distances from the Distances sheet, except if you&#8217;re in my neighborhood, I&#8217;m going to replace the distance with the distance to my neighborhood&#8217;s edge, the K-distance.&#8221;</p><p>Here&#8217;s what the sheet looked like where the MAX function is used to pick between the neighborhood&#8217;s edge and the distance to the supplier:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Reach-distance.tiff.jpg"><img
class="alignnone size-full wp-image-533" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Reach-distance.tiff.jpg" alt="" width="415" height="237" /></a></p><p>&#8220;And now that we have all our Reach Distances set, we&#8217;re ready to finish this calculation up,&#8221; I said, &#8220;We know that the reach distance to my five neighbors with respect to me is just the distance to the fifth and farthest in the neighborhood. But what&#8217;s my reach distance with respect to them? If their neighborhood is smaller than mine, i.e. their neighbors are closer to them than mine to me, then while they&#8217;re inside my &#8216;city walls,&#8217; I&#8217;m outside theirs.&#8221;</p><p>&#8220;We&#8217;re going to calculate the average reachability of each supplier with respect to their five neighbors,&#8221; I continued, &#8220;To do that we just read across the rows of the Reach Distance sheet, grabbing the Reach Distances from the five closest points using the ranking information from the Rank-Inv sheet that has row-oriented rankings on it.&#8221;</p><p>I created a new sheet called &#8216;LOF,&#8217; pasted the names of the suppliers down the first column, and filled in the formula for the average reachability distance to &#8216;Abraham&#8217; and showed it to Victor.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/AverageReachability2.tiff.jpg"><img
class="alignnone size-full wp-image-540" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/AverageReachability2.tiff.jpg" alt="" width="696" height="25" /></a></p><p>&#8220;Once again, the lookup of rows of data between sheets makes it an array formula,&#8221; Victor said, reading over the formula, &#8220;And you&#8217;re dividing the sum by 5 to make it an average.&#8221;</p><p>I dragged down the calculation and the sheet looked like this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/AverageReachability.tiff.jpg"><img
class="alignnone size-full wp-image-535" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/AverageReachability.tiff.jpg" alt="" width="214" height="188" /></a></p><p>&#8220;So now that we have the average reachability of each supplier with respect to their neighbors, if we invert that value what we&#8217;re left with is basically a density of the area around you&#8221; I said, &#8220;We&#8217;ll call it &#8216;Local Outlier Density.&#8217;&#8221;</p><p>I inverted the Average Reachability column and dragged the density values down.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Density.tiff.jpg"><img
class="alignnone size-full wp-image-536" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Density.tiff.jpg" alt="" width="294" height="138" /></a></p><p>&#8220;Then, to finish this up,&#8221; I added, &#8220;The Local Outlier Factor for a supplier is just the average of the ratios of my 5 nearest neighbors&#8217; densities to my own. If we&#8217;re all about the same density, then the value will tend toward 1, and I&#8217;m locally ordinary. If they&#8217;re in regions more dense than mine, then the ratios of their densities over my density will climb. That means that I consider them neighbors way more than they consider me a neighbor. I&#8217;m like that kid growing up who lived on a farm just outside of town. I&#8217;ve got friends in town who go to my school, but they&#8217;re better friends with each other than poor old me.&#8221;</p><p>I filled in the Local Outlier Factor formula which required that I look up the densities of my five nearest neighbors, divide each by the density of the point at hand, and average those ratios. The whole lookup was once again an array formula.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/LocalOutlierFactor.tiff.jpg"><img
class="alignnone size-full wp-image-537" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/LocalOutlierFactor.tiff.jpg" alt="" width="558" height="243" /></a></p><p>I tossed some conditional formatting on the column and rubbed my hands together.</p><p>&#8220;All we have to do now is look for the largest factor. That&#8217;s the point whose neighbors don&#8217;t really consider him a neighbor. The point is like Edward Scissorhands up in that castle at the edge of town,&#8221; I said.</p><p><a
href="http://www.alicia-logic.com/capsimages01/esc_014Neighborhood.jpg"><img
class="alignnone" src="http://www.alicia-logic.com/capsimages01/esc_014Neighborhood.jpg" alt="" width="450" height="218" /></a></p><p>I scrolled down the list. Near the bottom, I stopped.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Zhenli1.tiff.jpg"><img
class="alignnone size-full wp-image-545" title="Zhenli1.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Zhenli1.tiff.jpg" alt="" width="336" height="202" /></a></p><p>&#8220;Whoa, check out this Zhenli guy,&#8221; I said, &#8220;He&#8217;s the only one with an outlier factor over two, so reachability is way out of whack with those points nearest him.&#8221;</p><p>&#8220;Hmmm,&#8221; Victor said, &#8220;I&#8217;ve not dealt with this supplier, but I&#8217;ve heard of him. Up and coming large supplier out of the pacific. Flip back to the raw data.&#8221;</p><p>I flipped back to the first sheet and scrolled down to the same supplier:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Zhenli2.tiff.jpg"><img
class="alignnone size-full wp-image-546" title="Zhenli2.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Zhenli2.tiff.jpg" alt="" width="854" height="145" /></a></p><p>Victor nodded, &#8220;OK, he&#8217;s a big player. Operates his own narco sub, counterintelligence, has a criminal record. Even Margalo vouched for him, which isn&#8217;t nothing. But the other two don&#8217;t know him.&#8221;</p><p>Then Victor fell silent, &#8220;But look at his price.&#8221;</p><p>&#8220;Is it abnormally, low?&#8221; I asked.</p><p>&#8220;Not for a small player, but for someone operating transpo and counter-intel, it&#8217;s very cheap. And for good quantities too,&#8221; he said.</p><p>&#8220;And he demands that you meet in person,&#8221; I said.</p><p>&#8220;Yes,&#8221; said Victor, &#8220;Also rare for a big player. I don&#8217;t like it&#8230;maybe a trap.&#8221;</p><p>Victor suddenly stood and pulled out his phone, &#8220;I need to make a call.&#8221;</p><p>He walked some steps away where his voice was drowned out by the sound of the children, rides, and games. I feared that I&#8217;d just royally screwed the DEA. I needed to warn them. I couldn&#8217;t make out the words on Victor&#8217;s lips, but his left hand was clenched into a fist and his eyes had a far-away look as he spoke.</p><p>He hung up the phone and returned to the bench.</p><p>&#8220;We&#8217;ll see if this man is a problem or not,&#8221; said Victor.</p><p>&#8220;How are you going to do that?&#8221; I asked.</p><p>Victor just smiled, &#8220;I have ways of dealing with such matters.&#8221;</p><p>I didn&#8217;t contact agent Bestroff until I was back in my car and on I-20 speeding back toward Atlanta, safe from prying eyes and ears.</p><p>&#8220;Mr. Bestroff,&#8221; I said into my speakerphone, &#8220;I&#8217;m not sure if you&#8217;re working with a coke supplier named Zhenli Ye Gon, but if you are, Victor&#8217;s on to your honeypot.&#8221;</p><p>The other end of the phone was silent for a moment.</p><p>&#8220;Shit,&#8221; was all that finally came over the line.</p><p>&#8220;And to make matters worse,&#8221; I said, &#8220;You&#8217;ve got a mole inside the DEA. At least that&#8217;s where Victor says he got the intel. I sure hope you haven&#8217;t been using my real name in any of your interoffice communications.&#8221;</p><p>More silence.</p><p>&#8220;I&#8217;ll call you back,&#8221; was all Bestroff said, and he rang off.</p><p>That didn&#8217;t inspire confidence.</p><p>&#8220;I&#8217;m so screwed,&#8221; I said quietly to myself, and I sped back toward the frat house.</p><h2>Big Data-ish Tip</h2><p>At MailChimp most of our abuse is conducted not by malicious folks but by <a
href="https://blog.mailchimp.com/project-omnivore-three-years-of-gorging-on-data/">unthinking customers</a>. If I download the stolen list of email addresses from the Sony hack and send to it regarding my plumbing company, sure that&#8217;s illegal and malicious, but it&#8217;s not adversarial per se. Joe the plumber is not trying to hide from me &#8212; he&#8217;s just being an idiot. Most of the abuse I see in my job does not evolve over time.</p><p>In that case, training an AI model like we did in an <a
href="http://analyticsmadeskeezy.com/2012/10/29/introduction-to-machine-learning-logistic-regression-for-predicting-bad-trips/">earlier post</a>, using labelled abusers to find future abusers, is possible. But what if your abusers are adversarial? They&#8217;re trying to hide, perhaps blend in. They change their behavior with each intrusion.</p><p>In this case, a supervised AI model ain&#8217;t gonna do you as much good. That&#8217;s where outlier detection techniques like LOF come in. You don&#8217;t know apriori what an outlier looks like, but local outlier factors give you a value that helps you prioritize cases to investigate. The example above is somewhat artificial, but you can envision situations where you&#8217;ve got HTTP requests and timestamps in a vector from your website and maybe you want to use them to detect aberrant behavior. LOF might be the way to go there. How does a user&#8217;s HTTP request vector line him up with his neighbors?</p><p>Now, that said, once you have distance data, you can do all sorts of fun stuff with it. You could construct a trimmed kNN graph like we did in our <a
href="http://analyticsmadeskeezy.com/2012/10/11/graphing-clustering-community-detection-wholesale-drug-deals-using-excel-and-gephi/">wholesale graphing discussion</a>. Just applying a layout algorithm on the graph using 1 / distance as the weight on the edges might show you something visually. In 2004, Hautamaki et. al. <a
href="http://www.computer.org/portal/web/csdl/abs/proceedings/icpr/2004/2128/03/212830430abs.htm">released a paper</a> arguing that looking at the <a
href="http://en.wikipedia.org/wiki/Directed_graph#Indegree_and_outdegree">Indegree</a> of each node on the graph would let you know who&#8217;s an outlier.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/ForeverAlone.jpg"><img
class="alignnone size-full wp-image-566" title="ForeverAlone" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/ForeverAlone.jpg" alt="" width="502" height="501" /></a></p> ]]></content:encoded> <wfw:commentRss>http://analyticsmadeskeezy.com/2012/11/29/intrusion-detection-made-skeezy-how-do-you-find-the-dea-in-a-haystack/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Forecasting Made Skeezy: Projecting Meth Demand using Exponential Smoothing</title><link>http://analyticsmadeskeezy.com/2012/11/15/forecasting-made-skeezy-projecting-meth-demand-using-exponential-smoothing/</link> <comments>http://analyticsmadeskeezy.com/2012/11/15/forecasting-made-skeezy-projecting-meth-demand-using-exponential-smoothing/#comments</comments> <pubDate>Thu, 15 Nov 2012 19:40:45 +0000</pubDate> <dc:creator>Alex</dc:creator> <category><![CDATA[Forecasting]]></category> <category><![CDATA[Optimization]]></category> <category><![CDATA[Predictive Modeling]]></category> <category><![CDATA[Revenue Management]]></category> <category><![CDATA[Excel]]></category> <category><![CDATA[Exponential Smoothing]]></category> <category><![CDATA[Price-Sensitive Forecasting]]></category> <category><![CDATA[Solver]]></category><guid
isPermaLink="false">http://analyticsmadeskeezy.com/?p=421</guid> <description><![CDATA[NOTE: I&#8217;d highly recommend following along in the spreadsheet for this post. And don’t forget to sign up for the newsletter to hear about future Analytics Made Skeezy tutorials. It&#8217;s been three &#8230; <a
class="readmore" href="http://analyticsmadeskeezy.com/2012/11/15/forecasting-made-skeezy-projecting-meth-demand-using-exponential-smoothing/">Continue Reading &#8594;</a>]]></description> <content:encoded><![CDATA[<p><em>NOTE: I&#8217;d highly recommend following along in the <a
href="https://dl.dropbox.com/u/98476545/ExponentialSmoothing.xlsx">spreadsheet for this post</a>. And don’t forget to sign up for the newsletter to hear about future Analytics Made Skeezy tutorials.</em></p><p>It&#8217;s been three days since I last saw Victor, and I&#8217;ve been lying low ever since. I know that if he wanted me dead, I&#8217;d be dead already. But I can&#8217;t help it. I&#8217;m freaked. Screw the DEA.</p><p>It was Tuesday night when Andre whisked me away to the freaking Marietta <a
href="http://www.daveandbusters.com/default.aspx">Dave &amp; Busters</a>. I couldn&#8217;t believe it. Victor was just sitting there at a table in the midst of the arcade games. Around him kids and teens ran from game to game. The din and the lights were a constant aggravation, but there he sat in the middle of it, unbothered, like some drug-dealing Buddhist monk with a laptop. I nearly burst into laughter at the sight of him, but his expression made me rethink my levity.</p><p>I took a seat next to him and immediately felt something hard and cold press against my leg. I went weak in the knees. I knew I shouldn&#8217;t have cooperated with the DEA and installed that bug on Victor&#8217;s laptop. Now I was good and dead.</p><p>Victor just smiled at me. His face betrayed none of the situation below the table.</p><p>&#8220;Tell me, Alex,&#8221; he said, &#8220;Have you been talking to anyone about our little tutorials?&#8221;</p><p>He ran a hand along his laptop, and for the first time I noticed that it wasn&#8217;t the same laptop as before. It was a small MacBook Air. And all the USB ports had little rubber nubs in them to prevent drives from being inserted. That last bit had me really and truly panicked.</p><p>&#8220;N-No,&#8221; I stammered, &#8220;Why would I do that? I&#8217;m not exactly innocent myself.&#8221;</p><p>He stared at me for a time. Suddenly, a ski-ball machine blared a loud noise, and I jumped out of my chair. I thought Victor had pulled the trigger.</p><p>Victor just burst into laughter and tucked the gun back into a holster on his ankle.</p><p>&#8220;You sure are a jumpy one, Alex,&#8221; he said with a grin.</p><p>My heart has beating like a machine gun, and I felt nauseous. Victor waved me back into a seat.</p><p>&#8220;I&#8217;m not used to this,&#8221; I said, &#8220;I-I&#8217;m not familiar with this sort of world.&#8221;</p><p>Victor just kept smiling.</p><p>&#8220;And keep it that way,&#8221; he said, &#8220;I&#8217;m not interested in you learning this world. I&#8217;m interested in learning the techniques from yours. Then I pay you. Then you leave and say nothing. Understood?&#8221;</p><p>&#8220;Understood,&#8221; I said, half relieved that I was dead, half despondent that I was dealing with Victor instead of playing games like the kids around me. I was rethinking all my bad choices in a big way.</p><p>&#8220;You want something to eat before we get started?&#8221; asked Victor, &#8220;Chicken fingers, potato skins, and other vile stuff?&#8221;</p><p>I forced a smile, &#8220;I&#8217;m all set. Why don&#8217;t we just dive in?&#8221;</p><p>Victor slapped me on the leg, &#8220;Good, my boy. That&#8217;s what I like to hear. Especially today, because today I have all sorts of troubles.&#8221;</p><p>&#8220;What&#8217;s going on?&#8221; I asked.</p><p>&#8220;My meth supplier wants me to submit orders for the entire next year by month. In the past, I could just order everything the month before, but he says the feds are making life hard for him, so he needs more time to plan,&#8221; said Victor, &#8220;That means that I have to forecast demand for each city I sell in for all of 2013 at the monthly level.&#8221;</p><p>&#8220;OK, well, that&#8217;s not so bad,&#8221; I said, &#8220;What have you tried so far?&#8221;</p><p>Victor opened his computer and pushed the screen my way.</p><p>&#8220;Here are the demand numbers in kilos for Flint, Michigan for the last five years,&#8221; he said.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/RawData.png"><img
class="alignnone size-full wp-image-424" title="RawData" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/RawData.png" alt="" width="226" height="927" /></a></p><p>&#8220;So I just graphed it, fitted a line to it, and I&#8217;m going to use that trend line for projections,&#8221; he said and showed me the graph.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/DemandGraph.png"><img
class="alignnone size-large wp-image-425" title="DemandGraph" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/DemandGraph-1024x807.png" alt="" width="642" height="505" /></a></p><p>I nodded, &#8220;OK, and that&#8217;d work fine if you were just doing a yearly projection for total demand, but your supplier wants demand projections by month, right?&#8221;</p><p>&#8220;Exactly,&#8221; said Victor, &#8220;And I know that line is going to be terrible for that. I already know that demand peaks in the summer and lags in the winter in Flint, but that line isn&#8217;t going to account for it. Hell, I was thinking about just sketching out the shape of the next year. Just using my eyeballs to do the projection.&#8221;</p><p>I laughed, &#8220;Well, you wouldn&#8217;t be wrong in noting that visual inspection is one of the <a
href="http://books.google.com/books?id=hz_mvNU8YHYC&amp;pg=PA278&amp;dq=%22eyeball+search%22&amp;lr=&amp;sig=ztqc-srOr7fzycmSRlUfJMEQsP4#v=onepage&amp;q=%22eyeball%20search%22&amp;f=false">best ways to identify unknown patterns</a>, but I think in this case we can do better than that. Plus, I&#8217;m guessing Flint isn&#8217;t the only city you&#8217;re going to have to do these projections for.&#8221;</p><p>Victor, &#8220;No, and in fact, it&#8217;s not the only product either. I hear that some of my other suppliers are moving in this direction.&#8221;</p><p>&#8220;Well, in that case, I&#8217;m going to show you a really simple forecasting technique called Triple <a
href="http://en.wikipedia.org/wiki/Exponential_smoothing">Exponential Smoothing</a> or Holt-Winters Exponential Smoothing that is perfect for this problem,&#8221; I said.</p><p>I created a new tab in Victor&#8217;s Excel workbook called &#8220;HW Exp Smoothing,&#8221; and leaving the first couple of rows blank, I pasted the demand data in on row 3. I also added a fake year before 2008 called &#8220;initial&#8221; so that my data ended up looking like this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Initial.tiff.jpg"><img
class="alignnone size-full wp-image-426" title="Initial.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Initial.tiff.jpg" alt="" width="225" height="515" /></a></p><p>&#8220;Now, let me explain a little bit about how Triple Exponential Smoothing works. The &#8216;Triple&#8217; refers to the fact that we&#8217;re going to be more or less splitting this forecast into three components. We have <strong>seasonal adjustment factors </strong>which scoot the forecast up and down by month based on the historical data. So we&#8217;d expect the December factor to bump the forecast down and the July factor to bump it up. Then we have the <strong>trend</strong> component which helps us project out without considering the seasonal piece. This captures whether your demand is generally growing or shrinking. We also have what&#8217;s called the <strong>level </strong>which you can think of as the constant part of the forecast once we strip out a trend and seasonal variation. It&#8217;s a baseline.&#8221;</p><p>&#8220;Ok, so how do we start to break those out?&#8221; asked Victor.</p><p>&#8220;Well, I&#8217;m going to start in our fictional time just before the beginning of 2008, and the first thing I&#8217;m going to do is initialize the level as the demand from January 2008,&#8221; I said, &#8220;I&#8217;m also going to initialize the trend as the average of monthly increases in demand using same-month pairs from 2008 and 2009 to avoid seasonal wonkiness. So for instance, demand increased by .43 kg a month if I look at January 2009 versus January 2008. I&#8217;m going to average those across all 12 pairs in &#8217;08 and &#8217;09.&#8221;</p><p>I added columns to the sheet for level and trend and used this <a
href="http://www.dummies.com/how-to/content/how-to-build-an-array-formula-in-excel-2010.html">array formula</a> to initialize the trend:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/InitTrend.tiff.jpg"><img
class="alignnone size-full wp-image-427" title="InitTrend.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/InitTrend.tiff.jpg" alt="" width="226" height="16" /></a></p><p>When I&#8217;d set the two initial values, the spreadsheet now looked like this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/InitLevelTrend.tiff.jpg"><img
class="alignnone size-full wp-image-428" title="InitLevelTrend.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/InitLevelTrend.tiff.jpg" alt="" width="352" height="577" /></a></p><p>&#8220;But what about the seasonal adjustment?&#8221; asked Victor.</p><p>&#8220;Well, for that we actually need 12 initial values. One for each month we&#8217;re adjusting. And this is where things get slightly more funky. The first thing I&#8217;m going to do is take the average monthly demand for each year in your data and calculate how each month in that year deviates from the average. For instance, January 2008 here had 81% of the average monthly demand for 2008,&#8221; I said.</p><p>&#8220;Ah,&#8221; said Victor, &#8220;If January is 81% of the average monthly demand, then I could use that value to adjust.&#8221;</p><p>&#8220;Yes,&#8221; I said, smiling, &#8220;But we&#8217;ve got five years worth of data, so we&#8217;re going to average these values across all five years to get our adjustment factors.&#8221;</p><p>I added an &#8220;Average Monthly Demand for Year&#8221; column into the sheet and calculated the value for each year. I then added in the month by monthly variations from the average monthly demand in the next column.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/SeasonInit1.tiff.jpg"><img
class="alignnone size-full wp-image-429" title="SeasonInit1.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/SeasonInit1.tiff.jpg" alt="" width="484" height="796" /></a></p><p>I then added a column for my seasonal adjustment factors where I initialized them as averages of the values from the previous column, using an AVERAGEIF() to make sure I only averaged the correct months.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/SeasonInit2.tiff.jpg"><img
class="alignnone size-full wp-image-430" title="SeasonInit2.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/SeasonInit2.tiff.jpg" alt="" width="570" height="719" /></a></p><p>I clapped my hands together and rubbed them like I was heating them over a fire, &#8221;Now, we&#8217;ve got a starting place for these factors.&#8221;</p><p>&#8220;But what do we do with them?&#8221; asked Victor.</p><p>&#8220;Well, we&#8217;re going to roll them over the entire horizon of data here, refining them as each month ticks by. We&#8217;re going to take some percentage of the factor from the previous month combined with some percentage of a factor calculated from the data at the current month until we reach the very end of our data. Then we&#8217;ll have our final estimates for level, trend, and seasonal values,&#8221; I said.</p><p>Victor looked confused, &#8220;What do you mean you&#8217;re going to take some percentage of the value from the previous period?&#8221;</p><p>&#8220;Good question,&#8221; I said, &#8220;I&#8217;ll back up a bit. This is where this technique gets the term &#8216;smoothing&#8217; from. I&#8217;m going to introduce three arbitrary terms called smoothing factors. One for level, another for trend, and a third for seasonal. And initially I&#8217;m just going to set them at 50%, so as we roll over the data, we&#8217;re going to take 50% of the previous estimate for level and 50% of the estimate dictated by the current month&#8217;s data, yeah?&#8221;</p><p>I added in the smoothing factors at the top of the sheet.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/SmoothingFactors.tiff1.jpg"><img
class="alignnone size-full wp-image-465" title="SmoothingFactors.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/SmoothingFactors.tiff1.jpg" alt="" width="571" height="391" /></a></p><p>&#8220;So to see how this works,&#8221; I said, &#8220;Let me go ahead and roll one month down into January 2008. The first thing we&#8217;re going to do is set the January 2008 value of level. Since our level smoothing factor is 50%, we&#8217;re going to take 50% of the previous level value plus one month of trend and we&#8217;re going to combine it with 50% of the current month&#8217;s demand adjusted using the most recent seasonal factor we have for January,&#8221; I said.</p><p>I added the value to the sheet:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Level11.png"><img
class="alignnone size-large wp-image-466" title="Level1" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Level11-1024x670.png" alt="" width="642" height="420" /></a></p><p>&#8220;As for trend, that&#8217;s just 50% of the previous trend value and 50% of the difference between the current level value and the previous one,&#8221; I said and added the value to the sheet.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Trend1.tiff1.jpg"><img
class="alignnone size-full wp-image-467" title="Trend1.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Trend1.tiff1.jpg" alt="" width="440" height="377" /></a></p><p>&#8220;And the new seasonal variation for January is just 50% the previous seasonal variation and 50% January 2008 over the current level,&#8221; I continued.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Season1.tiff1.jpg"><img
class="alignnone size-full wp-image-468" title="Season1.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Season1.tiff1.jpg" alt="" width="572" height="367" /></a></p><p>&#8220;And here&#8217;s the cool part,&#8221; I said, &#8220;Now that we have these first smoothed values set, we just copy them all the way down the sheet.&#8221;</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/AllFactors.tiff1.jpg"><img
class="alignnone size-full wp-image-469" title="AllFactors.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/AllFactors.tiff1.jpg" alt="" width="577" height="363" /></a></p><p>&#8220;But what do we do with them?&#8221; asked Victor.</p><p>I smiled, &#8220;Now we&#8217;re ready to project into the future. And it&#8217;s super easy.&#8221;</p><p>I added some rows on the sheet for 2013.</p><p>&#8220;Let&#8217;s take June 2013 for example,&#8221; I said, &#8220;We can forecast that as the final estimate we have for the level plus 6 months of trend since we ended December 2012. Then we take that value and adjust it for June. Bam, we have a forecast.&#8221;</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/June.tiff1.jpg"><img
class="alignnone size-full wp-image-470" title="June.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/June.tiff1.jpg" alt="" width="630" height="582" /></a></p><p>Victor looked pleased, &#8220;And that&#8217;s it? I can use these numbers as my forecast?&#8221;</p><p>I shrugged, &#8220;You could. They wouldn&#8217;t be terrible. But that 50/50 split we&#8217;ve been doing with the smoothing factors, we really should change that.&#8221;</p><p>&#8220;To what?&#8221; asked Victor.</p><p>&#8220;Well, honestly, I don&#8217;t know. How much do you let past data influence you, and how much does your current period&#8217;s data matter? That varies from forecast to forecast. But there is a way we can have the computer figure it out for us,&#8221; I said.</p><p>&#8220;How&#8217;s that?&#8221; asked Victor.</p><p>&#8220;Well, we can forecast 2012 as if we were sitting at the end of 2011, compare the forecast with actuals, and find the smoothing values which do the best. In this way, we&#8217;re training the model like you would any machine learning model,&#8221; I said.</p><p>&#8220;Ah, OK, let&#8217;s do it,&#8221; he said.</p><p>I forecasted 2012 (below in yellow), calculated the average percent error (APE) between the forecast and actual, and then averaged the APEs at the top of the sheet to get a <a
href="http://en.wikipedia.org/wiki/Mean_absolute_percentage_error">Mean Absolute Percentage Error (MAPE)</a>.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/MAPE.tiff1.jpg"><img
class="alignnone size-full wp-image-471" title="MAPE.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/MAPE.tiff1.jpg" alt="" width="678" height="334" /></a></p><p>&#8220;Now, all I have to do is find the values of my smoothing factors between 0 and 1 that minimize my MAPE,&#8221; I said.</p><p>&#8220;So you use Solver?&#8221; asked Victor.</p><p>I laughed, &#8220;You&#8217;re catching on to my love of solver, Victor. Absolutely.&#8221;</p><p>I opened up Solver and set up the problem, &#8220;We&#8217;re going to minimize the MAPE where our decisions are to change the three smoothing factors subject to keeping them between 0 and 1. And this time let&#8217;s select the evolutionary solver from the menu since this problem is so nonlinear and ugly.&#8221;</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/solver.tiff.jpg"><img
class="alignnone size-full wp-image-439" title="solver.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/solver.tiff.jpg" alt="" width="672" height="618" /></a></p><p>I pressed solve and let the thing roll. The MAPE dropped over various trial solutions until finally it stopped at just 2.6%.</p><p>&#8220;2.6%. That&#8217;s a 10x improvement on the MAPE we had before Solver ran,&#8221; I said.</p><p>&#8220;Awesome,&#8221; said Victor, &#8220;And now I have a final forecast?&#8221;</p><p>&#8220;Yes,&#8221; I said, &#8220;you&#8217;re done. Let&#8217;s graph it real quick.&#8221;</p><p>I popped the values into a chart so we could look at them.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Projection1.png"><img
class="alignnone size-large wp-image-441" title="Projection" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/Projection1-1024x540.png" alt="" width="642" height="338" /></a></p><p>&#8220;Looks great!&#8221; said Victor, and then he paused, &#8220;but wait, what about the <a
href="http://analyticsmadeskeezy.com/2012/10/08/revenue-management-for-meth-dealers-in-flint/">price adjustments we talked about putting in place in Flint</a>?&#8221;</p><p>&#8220;Ah,&#8221; I said, &#8220;You&#8217;re right! We haven&#8217;t accounted for the fact that you moved your pricing strategy from an average of 5% less than your competitors to 8% more than your competitors. That means that this historical data is giving us an over-estimate for your newly raised prices. We&#8217;ll need to shift it down.&#8221;</p><p>&#8220;But by how much?&#8221; asked Victor.</p><p>&#8220;Well, if you&#8217;ll remember, we found in that <a
href="http://analyticsmadeskeezy.com/2012/10/08/revenue-management-for-meth-dealers-in-flint/">previous conversation</a> that for every 1% you increased prices over the competition, you lost .42 kilograms of demand for the month,&#8221; I said and added a &#8220;Price Sensitive Forecast&#8221; column to the sheet. I took the existing forecast and subtracted from it 5.46 kg that our demand model anticipated forfeiting by pricing 8% above the competition.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/PriceSensitive.tiff.jpg"><img
class="alignnone size-full wp-image-442" title="PriceSensitive.tiff" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/PriceSensitive.tiff.jpg" alt="" width="254" height="144" /></a></p><p>&#8220;There,&#8221; I said, &#8220;Done.&#8221;</p><p>Victor clapped me on the back and shook my hand before sliding me a massive wad of bills.</p><p>&#8220;Don&#8217;t spend it all on one video game, OK?&#8221; he said, smiling.</p><p>&#8220;And remember what we talked about,&#8221; he added with a twinkle in his eye, &#8220;If you talk about these conversations with anyone, you&#8217;ll need to adjust your forecasted lifespan a great deal lower.&#8221;</p><p>I nodded and stuttered to respond, but Victor had already turned away to flag down a server.</p><p>&#8220;I want more of those Jalapeno poppers,&#8221; he muttered to himself.</p><h2>Big Data-ish Tip</h2><p>A lot of <a
href="http://support.sas.com/rnd/app/ets/proc/ets_forecast.html">software</a> <a
href="http://stat.ethz.ch/R-manual/R-patched/library/stats/html/HoltWinters.html">packages</a> these days come with Holt-Winters built in. It&#8217;s an <a
href="http://www.forecasters.org/pdfs/foresight/free/Issue19_goodwin.pdf">old method</a> but extremely accurate for how simple it is, oftentimes beating ARIMA models in actual business settings. I wouldn&#8217;t try anything more complex than HW until I&#8217;d given it a whirl first as a baseline for comparison.</p><p>For more reading on forecasting, I&#8217;d recommend anything by <a
href="http://robjhyndman.com/researchtips/">Rob Hyndman</a>.</p><p>The price-sensitive forecasting at the end of this post is simple, but believe it or not, it&#8217;s not too far from how many Fortune 500 companies combine price elasticity models and forecasts to create price optimization models.</p><p>This post, as written, is decidedly &#8220;small data.&#8221; Indeed, we don&#8217;t get into big data until we start thinking about someone like Amazon where you may need to forecast demand across zillions of SKUs. Then you&#8217;ve got a nightmare on your hands.</p><p>Luckily, that problem is highly parallelizable. And one of the reasons why I prefer exponential smoothing to something more <a
href="http://scialert.net/abstract/?doi=jas.2009.521.527">exotic</a> (like machine learning with exogenous variables included) is that if you&#8217;ve got this stuff in a highly automated system across scads of products, you&#8217;re not going to necessarily notice when the forecast gets screwed up. I prefer to avoid constant babysitting and retraining. For me, Holt-Winters strikes the right balance of simplicity and effectiveness that many businesses want when they talk about &#8220;set it and forget it.&#8221;</p> ]]></content:encoded> <wfw:commentRss>http://analyticsmadeskeezy.com/2012/11/15/forecasting-made-skeezy-projecting-meth-demand-using-exponential-smoothing/feed/</wfw:commentRss> <slash:comments>12</slash:comments> </item> <item><title>Check Yo Self: 5 Things You Should Know About Data Science (Author Note)</title><link>http://analyticsmadeskeezy.com/2012/11/05/check-yo-self-5-things-you-should-know-about-data-science-author-note/</link> <comments>http://analyticsmadeskeezy.com/2012/11/05/check-yo-self-5-things-you-should-know-about-data-science-author-note/#comments</comments> <pubDate>Mon, 05 Nov 2012 18:02:24 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[Author Note]]></category> <category><![CDATA[Analytics]]></category> <category><![CDATA[Big Data]]></category> <category><![CDATA[Bullshit]]></category> <category><![CDATA[Hype]]></category><guid
isPermaLink="false">http://analyticsmadeskeezy.com/?p=357</guid> <description><![CDATA[Hey folks. I&#8217;m going to take a brief break from the narrative to talk to you directly about data science as a discipline. There&#8217;s a lot of noise floating around &#8230; <a
class="readmore" href="http://analyticsmadeskeezy.com/2012/11/05/check-yo-self-5-things-you-should-know-about-data-science-author-note/">Continue Reading &#8594;</a>]]></description> <content:encoded><![CDATA[<div
id="attachment_365" class="wp-caption alignnone" style="width: 442px"><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/jesus.jpg"><img
class=" wp-image-365  " title="The Data Scientist. Thanks to @SeriousRon for the image." src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/11/jesus.jpg" alt="" width="432" height="572" /></a><p
class="wp-caption-text">The Data Scientist. Thanks to @SeriousRon for the image.</p></div><p>Hey folks. I&#8217;m going to take a brief break from <a
href="http://analyticsmadeskeezy.com/what-the-hell-is-this-blog/">the narrative</a> to talk to you directly about data science as a discipline. There&#8217;s a lot of noise floating around about how data scientists are the <a
href="http://www.forbes.com/sites/gilpress/2012/09/27/data-scientists-the-definition-of-sexy/">sexy</a> <a
href="http://servicesangle.com/blog/2012/08/03/can-data-science-save-the-us-economy/">saviors</a> <a
href="http://yaleglobal.yale.edu/content/can-big-data-save-lives">of</a> <a
href="http://www.techopedia.com/2/28526/it-business/it-careers/data-scientists-the-new-rock-stars-of-the-tech-world">the</a> <a
href="http://siliconangle.com/blog/2012/10/05/microsoft-uses-big-data-to-help-save-the-worlds-most-endangered-species/">world</a>. Well, we&#8217;re not. At least, anyone who&#8217;s ever seen my <a
href="http://www.chubbiesshorts.com/">hairy, white thighs</a> knows I&#8217;m not sexy. I won&#8217;t speak for the rest of my data science colleagues, but few look like this:</p><p><img
class="alignnone" title="Not a data scientist" src="http://austenacious.com/wp-content/uploads/2011/01/darcy.jpg" alt="" width="283" height="332" /></p><p>When trying to be sexy, we look more like this:</p><p><img
class="alignnone" title="sexy data science" src="http://fc05.deviantart.net/fs30/f/2009/245/d/a/wilford_brimley_is_bad_by_Kyle_M_Boyko.jpg" alt="" width="306" height="306" /></p><p>So whether you actually are a so-called data scientist or are looking to hire one or become one, let&#8217;s have a little quiet time for reflection. Having been in this field for a while, allow me to pontificate uncontrollably:</p><p>1) <strong>You are not the most important function of your organization.</strong> This is a toughie. I do love me some me.</p><p>But consider the airline industry. They&#8217;ve been doing big data-ish analytics for a long while. For example, they&#8217;ve been engaging in revenue management and <a
href="http://en.wikipedia.org/wiki/Yield_management">yield management</a> since before you were a twinkle in yo&#8217; mama&#8217;s eye. They&#8217;ve used all their data to squeeze that last nickel out of you for that seat you can barely fit in.  It&#8217;s a huge win for mathematics.</p><p>But you know what? The most important part of their business is flying. The products and services an organization sells matter more than the big data models that tack on pennies to those dollars. Your goals should be things like using data to facilitate better targeting, forecasting, pricing, decision-making, reporting, compliance, etc. In other words, working with the rest of your organization <strong>to do <a
href="http://www.scienceofbetter.org/">better</a>, </strong>not to do data science for its own sake.</p><p>2) <strong>Leave the complexity at the door. </strong>A long time ago in a galaxy somewhere near Cambridge, MA, I helped build a supply chain optimization model for a Fortune 500 company. The model used the tangents of an integral over a truncated normal distribution as a function of the mean as linear upper bounds for embedding a probabilistic model inside a Mixed-Integer Program. Sound complicated? It was. And it worked. So long as we baby-sat the fuck out of it and fed it a loving diet of accurate standard deviations of demand forecasts.</p><p>The model was dead on arrival, because it was too complex. The same thing happened to the <a
href="http://techblog.netflix.com/2012/04/netflix-recommendations-beyond-5-stars.html">Netflix prize</a> winners. Your model is not the goal; your job is not a Kaggle competition (unless you work at Kaggle or something). Sustainable, repeatable business improvement is the goal, and on-going effort to use your complex big data product can be at odds with this goal if you&#8217;re not sensible in your design. If that means using a regular mixed-integer program instead of a probabilistic one, do that. Because this isn&#8217;t about proving how smart you are. Do you want to be the only one who can run your model? That&#8217;s the most boring kind of job security I can imagine.</p><p>3) <strong>Much of what you do is marketing. </strong>Big Data is a hot topic right now, and company leaders are dying to show off how they&#8217;re using their data. Especially if the company is going public or being acquired.  There&#8217;s money to be made off of doing cool shit with data. What do you think LinkedIn&#8217;s InMaps product was? Did you play with it? Maybe. Was it useful? Errrm, not really. Was it cool? Fuck yeah. Did it impress investors and launch DJ Patil&#8217;s career? Ah, there you go.</p><p>Go ahead and do the marketing. It&#8217;s good for your business. But don&#8217;t forget that it&#8217;s just you being all &#8220;sexy data scientist&#8221; again. In certain cases, it may be your responsibility to steer the organization back toward something that delivers real value but uses less Gephi.</p><p>Tip: If you&#8217;re making <a
href="http://blog.ouseful.info/2011/07/07/visualising-twitter-friend-connections-using-gephi-an-example-using-wireduk-friends-network/">Gephi</a> <a
href="http://blog.ynada.com/425">graphs</a> <a
href="http://blog.ynada.com/339">out</a> <a
href="http://guidogarcia.net/blog/2012/01/21/graph-yourtwitter-network-with-gephi/">of</a> <a
href="http://strata.oreilly.com/2010/12/graph-your-twitter-network.html">tweets</a>, you&#8217;re probably doing more data science marketing than data science analytics. And stop it. Please. I can&#8217;t take any more. To paraphrase the Gospel of Mark, what does it gain a man to have graphs of tweets and do jack for analysis with them? I thought we were doing science, not our best impression of something that belongs in MoMA.</p><p><strong>4) The tools are wagging the analytics right now. </strong>I can get a little hadoop added to my latte at Starbuck&#8217;s now. hive, pig, mongodb, riak, redis. Rub a little cassandra on it and lay down on the couchdb for an hour. The money to be made is in selling tools and services around the tools. Doing the actually nitty gritty of big data analytics, that&#8217;s secondary. So everyone&#8217;s talking up their tool set, and you may have a great setup, but it&#8217;s not about the tools or how big your dataset is, it&#8217;s about how you use them. I&#8217;ve seen better analytics done with ten megs of data in a pivot table than what most seem to be doing with their petabytes of unstructured garbage.</p><p>It&#8217;s great to have a shit-ton of data, find a way to use it to actually make money. Not draw graphs of tweets. <a
href="https://blog.mailchimp.com/digging-deeper-into-wavelength-and-egp-data-finding-interest-clusters-in-mailchimps-network/">Draw graphs of emails instead <img
src='http://analyticsmadeskeezy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </a></p><p><strong>5) Data scientist is a poor term. Communication and creativity are most important.</strong> Whoever chose the term data scientist has downplayed what&#8217;s most important about this job. A data scientist needs to be someone who can bridge the gap between complex analytics on large data sets and the dreams of company leadership. A data scientist needs to be creative about indentifying ways that data can solve company problems. And if the data&#8217;s not collected yet to solve a problem? They need to figure out how to get it. Here&#8217;s a break down of how I spend my time:</p><p>-1/3 talking with others and figuring out how we can use our data to solve problems</p><p>-1/3 up to my elbows in uggo data cleaning and prepping to solve a problem</p><p>-1/3 hunting down data that&#8217;s logged in some strange way, plying developers with drinks to get the data moved into our big data store in the appropriate way for modeling</p><p>-.00000001% actual training of models.</p><p>This is why Kaggle is bullshit. It&#8217;s like focusing on the cherry on your milkshake. Who gives two shits about the cherry? You need the rest of the milkshake.</p> ]]></content:encoded> <wfw:commentRss>http://analyticsmadeskeezy.com/2012/11/05/check-yo-self-5-things-you-should-know-about-data-science-author-note/feed/</wfw:commentRss> <slash:comments>16</slash:comments> </item> <item><title>Introduction to Machine Learning: Logistic Regression for Predicting Bad Trips</title><link>http://analyticsmadeskeezy.com/2012/10/29/introduction-to-machine-learning-logistic-regression-for-predicting-bad-trips/</link> <comments>http://analyticsmadeskeezy.com/2012/10/29/introduction-to-machine-learning-logistic-regression-for-predicting-bad-trips/#comments</comments> <pubDate>Mon, 29 Oct 2012 01:50:15 +0000</pubDate> <dc:creator>Alex</dc:creator> <category><![CDATA[Artificial Intelligence]]></category> <category><![CDATA[Machine Learning]]></category> <category><![CDATA[Optimization]]></category> <category><![CDATA[Predictive Modeling]]></category> <category><![CDATA[Analytics]]></category> <category><![CDATA[Big Data]]></category> <category><![CDATA[Excel]]></category> <category><![CDATA[Logistic Regression]]></category> <category><![CDATA[Nonlinear Optimization]]></category> <category><![CDATA[Solver]]></category><guid
isPermaLink="false">http://analyticsmadeskeezy.com/?p=214</guid> <description><![CDATA[NOTE: This one is pretty complex, so I&#8217;d highly recommend following along in the spreadsheet for this post. And don’t forget to sign up for the newsletter to hear about future Analytics Made &#8230; <a
class="readmore" href="http://analyticsmadeskeezy.com/2012/10/29/introduction-to-machine-learning-logistic-regression-for-predicting-bad-trips/">Continue Reading &#8594;</a>]]></description> <content:encoded><![CDATA[<p><em>NOTE: This one is pretty complex, so I&#8217;d highly recommend following along in the <a
href="https://dl.dropbox.com/u/98476545/LogistcRegressionLSD.xlsx">spreadsheet for this post</a>. And don’t forget to sign up for the newsletter to hear about future Analytics Made Skeezy tutorials.</em></p><p>&#8220;Getting some early morning air?&#8221; Andre asked as I returned to the house from <a
href="http://analyticsmadeskeezy.com/2012/10/29/federales/">my meeting with Agent Bestroff</a>.</p><p>Was he suspicious? I don&#8217;t know. I couldn&#8217;t tell because I&#8217;d never paid attention before. I&#8217;d never had to worry about Andre perceiving me as some kind of traitor.</p><p>&#8220;Rough night,&#8221; I said, &#8220;Don&#8217;t ask.&#8221;</p><p>Andre cracked a smile, &#8220;I hear you. Now go do your make-up, because Victor wants to talk.&#8221;</p><p>&#8220;Geez,&#8221; I muttered under my breath.</p><p>&#8220;Huh?&#8221; asked Andre.</p><p>My palms were sweaty, and I fingered the usb drive in my pocket that the DEA agent had given me. I hadn&#8217;t even had time to collect my thoughts about this, and it was already happening.</p><p>&#8220;Can this wait?&#8221; I asked.</p><p>&#8220;No, son,&#8221; Andre said, &#8220;It can&#8217;t. And you get paid for it to not, so let&#8217;s get moving.&#8221;</p><p>Great, I thought. I&#8217;m dead. I&#8217;m so dead. That thought continued right up until I sat down with Victor half an hour later.</p><p>We met at the restaurant at the Druid Hills Golf Club. How Victor had become a member at this stodgy hellhole was beyond me. But there he was digging into a plate of huevos rancheros surrounded by a bunch of people whose lives seemed to consist of banalities like Hilton Head, Botox, college football, and marital affairs. Not that I don&#8217;t love me some college football, but it was apparent that these people had no idea who they shared their dining room with.</p><p>&#8220;Alex, my boy,&#8221; Victor said with a huge smile, &#8220;So glad Andre found you. He&#8217;d been waiting at your house for some time. Where were you?&#8221;</p><p>Did I see a hint of suspicion in Victor&#8217;s eyes?</p><p>&#8220;I was already up,&#8221; I shrugged, &#8220;Decided to take a walk around town.&#8221;</p><p>He stared at me for a moment, deep in thought. Then suddenly he crumpled up the cloth napkin in his lap and tossed it onto his plate before pushing his food aside.</p><p>&#8220;Well, let&#8217;s get started then,&#8221; he said, &#8220;No time like the present.&#8221;</p><p>He pulled out his laptop and some scrap paper from his briefcase and set it on the dining room table. You had to admire the man&#8217;s audacity. There seemed to be no place he wouldn&#8217;t talk about dealing drugs.</p><p>&#8220;What&#8217;s on the agenda for today?&#8221; I asked.</p><p>&#8220;Acid,&#8221; said Victor, &#8220;Specifically, bad trips.&#8221;</p><p>&#8220;What about bad trips?&#8221; I asked.</p><p>&#8220;I make a stellar product,&#8221; Victor replied, &#8220;I pride myself on the quality of all my products; my LSD is some of the best out there. The problem is that it&#8217;s very potent. If it could travel back in time, this acid would have <a
href="http://www.youtube.com/watch?v=_Ob46f952eU" target="_blank">killed all the hippies</a>.&#8221;</p><p>The man started laughing loudly at the thought, and some old folks in the dining room turned to look.</p><p>Victor held up a hand apologetically and stifled his laughter, &#8220;Sorry. Sorry. Anyway, yes, the people who love my product, really love it. I get plenty of repeat buyers.&#8221;</p><p>&#8220;But?&#8221; I asked.</p><p>&#8220;There seems to be a certain set of people who can&#8217;t handle it,&#8221; he said, &#8220;They can&#8217;t take it, and they have really bad trips. I don&#8217;t want to water my product down just to make something mediocre that everyone will kindof like. But if I knew who was going to have a bad trip before they had it, then I could steer them toward the shrooms instead or something.&#8221;</p><p>I nodded, &#8220;Got any data on who these people are? The bad trippers versus the good trippers?&#8221;</p><p>Victor gave one of his cheshire grins, &#8220;As a matter of fact, I do. I had my dealers write down a few things about their customers. If the customer let them know it was a bad trip or if they were a repeat customer but never came back after buying acid, then we logged the sale as a bad trip. If the customer came back and said they had a good time, then we logged the trip as good,&#8221; he said.</p><p>He fired up excel and turned a spreadsheet toward me. The data looked like this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/RawData.tiff.jpg"><img
class="alignnone size-full wp-image-228" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/RawData.tiff.jpg" alt="" width="563" height="375" /></a></p><p>&#8220;So 1 is a bad trip and 0 is good trip?&#8221; I asked. Victor nodded yes.</p><p>&#8220;This is a really odd set of features,&#8221; I said staring at the data, &#8220;Some physical descriptors, the customer&#8217;s product preference, the phone they carried. I can&#8217;t see how their phone matters. Is 1 male or female?&#8221;</p><p>Victor smiled, &#8220;1 is male. And with attire, 10 is a full suit and nice shoes, while 1 is dirty, homeless clothing. It&#8217;s very subjective.&#8221;</p><p>&#8220;I thought I could run a <a
href="http://en.wikipedia.org/wiki/Linear_regression" target="_blank">linear regression</a> on the numeric values,&#8221; he added, &#8220;but I wasn&#8217;t sure what to do with the last two columns. They&#8217;re not numeric.&#8221;</p><p>&#8220;Well, first off, linear regression is totally the wrong way to go, because your <a
href="http://en.wikipedia.org/wiki/Dependent_and_independent_variables#Dependent_variables" target="_blank">response variable</a>, i.e. the thing you&#8217;re trying to predict, is binary, not continuous. You want to predict things that are either a good trip or a bad trip, 0 or 1, but if you just plot a trend line through your data, you&#8217;re going to get predictions above and below that,&#8221; I said, &#8220;What you need is to do some <a
href="http://en.wikipedia.org/wiki/Logistic_regression" target="_blank">logistic regression</a>, which is going to take your data and spit out a probability value between 0 and 1 where the closer you are to 1, the more likely you are to have a bad trip.&#8221;</p><p>&#8220;OK, so logistic regression is something I use when I want to predict the answer to a &#8216;yes or no&#8217; question?&#8221; Victor asked.</p><p>&#8220;Exactly,&#8221; I said, &#8220;Will my customer buy? Will they use the coupon I gave them? Is my supplier a cop in disguise? Will they give my meth a five star review on Yelp? All those questions could be answered with logistic regression.&#8221;</p><p>&#8220;But before we do that,&#8221; I continued, &#8220;the first step is to transform these favorite drug and cell phone columns from categorical data to <a
href="http://en.wikipedia.org/wiki/Dummy_variable_(statistics)" target="_blank">dummy variables</a>.&#8221;</p><p>&#8220;What&#8217;s a dummy variable?&#8221; asked Victor.</p><p>&#8220;Well,&#8221; I said, &#8220;Rather than have one column for all your favorite drugs, we&#8217;re going to make one column for each drug, and if you&#8217;re favorite drug is meth then the meth column gets a 1 and the rest get 0s.&#8221;</p><p>Victor nodded, &#8220;So you&#8217;re taking each option and giving it its own indicator column?&#8221;</p><p>&#8220;Yep,&#8221; I answered, &#8220;Except that since you&#8217;ve got 7 drug options, we only need columns for 6 of them. If they&#8217;re all 0, then we&#8217;ll know that the 7th, absent column is a 1. That&#8217;ll keep us from encoding any redundancy into our new data.&#8221;</p><p>I copied the data over into the new format in a tab called &#8220;CategoricalFixed&#8221; where it now looked like this (Apologies for the width. Click on the picture or<em> </em>download the <em><a
href="https://dl.dropbox.com/u/98476545/LogistcRegressionLSD.xlsx">spreadsheet for this post</a></em> to see it better):</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/RawDataFixed.tiff1.jpg"><img
class="alignnone size-full wp-image-233" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/RawDataFixed.tiff1.jpg" alt="" width="1042" height="272" /></a></p><p>&#8220;See how the categorical data is now blown out across these dummy columns?&#8221; I asked.</p><p>&#8220;Yes, I see,&#8221; said Victor, &#8220;And if I were to have 0s all the way across for my phone columns, that means my phone was an Android phone in the original data since that&#8217;s the absent column?&#8221;</p><p>I smiled, &#8220;Exactly.&#8221;</p><p>&#8220;Ok, so what do we do with this new data?&#8221; asked Victor.</p><p>&#8220;Well, let&#8217;s talk about it as un-technically as possible. For some future customer, I want to gather data just like this and combine it in some way, run it through some function, such that out comes a number between 0 and 1, right?&#8221; I asked.</p><p>&#8220;Correct,&#8221; said Victor.</p><p>&#8220;And what we have here, in machine learning speak, is &#8216;training data,&#8217;&#8221; I said, &#8220;We&#8217;re going to <a
href="http://en.wikipedia.org/wiki/Supervised_learning" target="_blank">train an artificial intelligence model on this data</a>, and by &#8216;model,&#8217; all I mean is a function that combines a row of data like this and spits out a value between 0 and 1.&#8221;</p><p>I added a row at the top of my sheet that had all the same columns as below, except I added a column called &#8216;constant&#8217; to the end of it.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/TopBar.tiff.jpg"><img
class="alignnone size-full wp-image-234" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/TopBar.tiff.jpg" alt="" width="1073" height="53" /></a></p><p>&#8220;This row here is going to give the coeffients that we&#8217;re going to multiply by the data you&#8217;ll gather from a customer. If this were a linear regression, you&#8217;d just fit it such that the sum product of this row with the gathered data for the customer would give you a prediction.&#8221;</p><p>I jotted the equation down on a sheet of paper:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/logitppt.jpg"><img
class="alignnone size-full wp-image-235" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/logitppt.jpg" alt="" width="674" height="84" /></a></p><p>&#8220;That sumproduct looks like this in mathematical notation, where the x values are what we gather from the customer and the b values are what I&#8217;ve got in this green coefficient row,&#8221; I said, &#8220;I&#8217;m just going to call that sumproduct a &#8216;logit,&#8217; but it kinda looks like what we&#8217;d get out of a linear regression, right?&#8221;</p><p>&#8220;Yes. But we&#8217;re not doing a linear regression.&#8221; said Victor.</p><p>&#8220;Exactly,&#8221; I said, &#8220;So instead we&#8217;re going to take this simple equation I&#8217;m calling the logit, and we&#8217;re going to transform it into a value that&#8217;s guaranteed to be between 0 and 1,&#8221; I said.</p><p>&#8220;How?&#8221; asked Victor.</p><p>&#8220;We&#8217;ll, consider this equation,&#8221; I said and jotted down a fraction:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/logitexp.jpg"><img
class="alignnone size-full wp-image-236" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/logitexp.jpg" alt="" width="132" height="120" /></a></p><p>&#8220;That <a
href="http://en.wikipedia.org/wiki/E_(mathematical_constant)">e is just the mathematic constant used as the base of a natural logarithm</a>. It&#8217;s approximately 2.72, and you can use it in Excel via the exp() function,&#8221; I said.</p><p>&#8220;Ok,&#8221; said Victor, &#8220;So why is this always between 0 and 1?&#8221;</p><p>&#8220;Well, ok, let&#8217;s start with the coefficients I currently have in the workbook. All 0s,&#8221; I said.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/TopBar.tiff1.jpg"><img
class="alignnone size-full wp-image-237" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/TopBar.tiff1.jpg" alt="" width="1073" height="53" /></a></p><p>&#8220;If I use those coefficients in my logit, then the logit is equal to what?&#8221; I asked.</p><p>Victor thought a second, &#8220;No matter what data the customer gives, the logit would be 0 because all your multipliers are.&#8221;</p><p>I nodded, &#8220;Exactly. Which means that this second equation is e raised to the 0th power divided by one plus e raised to the zero, right?&#8221;</p><p>&#8220;Right,&#8221; said Victor, &#8220;Which is just one divided by two. It&#8217;s just .5.&#8221;</p><p>&#8220;Exactly,&#8221; I said, &#8220;And what if my coefficients were something else? What if they made my logit a negative number instead of 0?&#8221;</p><p>&#8220;Hmmm,&#8221; said Victor, &#8220;Well if the logit were, let&#8217;s say, -2, then e to the -2 is 1 divided by e squared, which is something like 1 divided by 8 or 9. So that&#8217;d give us something close to an eighth divided by one plus an eighth, which is approximately one ninth.&#8221;</p><p>&#8220;Yeah, it&#8217;s about .12. So already we&#8217;ve fallen well below the .5 value we got from a logit of 0. And what if instead of -2 I had a larger negative number, like -100?&#8221; I asked.</p><p>&#8220;Well, e to the -100 would be a very, very small number. So the whole calculation would give a small number over 1 plus that same small number,&#8221; Victor said, &#8220;So the whole calculation is getting closer and closer to zero.&#8221;</p><p>&#8220;Right,&#8221; I added, &#8220;And if we go the other way, if the logit is big and positive, we approach 1. We&#8217;d get a big ass number divided by a big ass number plus 1, which is going to end up as .999 repeating. Since our coefficients are going to end up being set to actual numbers, we&#8217;ll never hit a solid 0 or a solid 1, but we can get arbitrarily close.&#8221;</p><p>I jotted down some examples on paper:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/probex.jpg"><img
class="alignnone size-full wp-image-238" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/probex.jpg" alt="" width="268" height="442" /></a></p><p>&#8220;So no matter what value the logit takes,&#8221; said Victor, &#8220;We&#8217;ve got a value between 0 and 1. But how do we set this green row of coefficients such that the value between 0 and 1 we get for the customer&#8217;s input data is correct?&#8221;</p><p>&#8220;Ah ha,&#8221; I said, &#8220;This is where we train the model.&#8221;</p><p>I added a column into the sheet for the logit for each row of training data the dealers had gathered:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/LogitCalc2.png"><img
class="alignnone size-full wp-image-240" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/LogitCalc2.png" alt="" width="1466" height="409" /></a></p><p>I then added the probability calculation next to each logit:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Probability3.png"><img
class="alignnone size-medium wp-image-239" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Probability3-300x112.png" alt="" width="300" height="112" /></a></p><p>&#8220;Now, all we need to do is find the coefficients that make the probability column as close to the &#8216;Bad?&#8217; column as possible. If we can find coefficients that give a 0 probability for the people we know had good trips and a 1 for the people who had bad trips in our training data, then bam, we have our model,&#8221; I said.</p><p>&#8220;So how do we find those coefficients?&#8221; asked Victor, &#8220;Trial and error?&#8221;</p><p>I laughed, &#8220;Oh lord. That&#8217;d take an eternity. No, we&#8217;re going to <a
href="http://analyticsmadeskeezy.com/2012/08/29/optimal-blending-of-cocaine/">use Excel Solver just like we did some weeks ago</a>.&#8221;</p><p>Victor nodded, &#8220;But to use Solver, don&#8217;t we need an objective, just like how cocaine cost was our objective in the other problem?&#8221;</p><p>&#8220;Right,&#8221; I said, &#8220;So this time around, we want our probabilities on our training data to be very near our actual values. So consider this value:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/scoreppt.jpg"><img
class="alignnone size-full wp-image-336" title="scoreppt" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/scoreppt.jpg" alt="" width="444" height="47" /></a></p><p>&#8220;What happens when I had a bad trip and the model predicted I would have one? In other words, what happens when &#8216;bad?&#8217; is a 1 and &#8216;probability&#8217; is super high, like .99?&#8221; I asked.</p><p>Victor stared at the equation a moment, &#8220;Well, you get .99^1*.01^0 which is more or less 1.&#8221;</p><p>&#8220;And if I had a bad trip but the model completely whiffs and says I&#8217;ll have a good one?&#8221;</p><p>&#8220;You&#8217;d get .01^1 *.99^0,&#8221; Victor said, &#8220;Which is more or less 0.&#8221;</p><p>&#8220;So then if we calculate one of these values for each row of our training data and sum them up, all we have to do is maximize the value of their sum by changing the coefficients around. If we get a lot of scores of 1, then we&#8217;ve got a pretty good fit on the training data, don&#8217;t we?&#8221; I asked.</p><p>I added the score values to each row of the sheet, summed them up, and opened solver.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Solver2.png"><img
class="alignnone  wp-image-242" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Solver2.png" alt="" width="905" height="788" /></a></p><p>I set solver to maximize the sum of the scores, while changing my coefficient row.</p><p>Before I hit solve, I made sure I&#8217;d chosen the GRG Nonlinear solver option from the Solving Methods list.</p><p>&#8220;Why not use the simplex algorithm, like last time?&#8221; asked Victor.</p><p>&#8220;Because these exponential functions aren&#8217;t linear,&#8221; I said, &#8220;It&#8217;d barf. But the nonlinear solver will handle the problem nicely.&#8221;</p><p>I hit solve, and the algorithm set the coefficients.</p><p>&#8220;Bam!&#8221; I said and pointed to the top row.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/final1.tiff.jpg"><img
class="alignnone size-full wp-image-243" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/final1.tiff.jpg" alt="" width="326" height="45" /></a></p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/final2.tiff.jpg"><img
class="alignnone size-full wp-image-244" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/final2.tiff.jpg" alt="" width="392" height="45" /></a></p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/final3.tiff.jpg"><img
class="alignnone size-full wp-image-245" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/final3.tiff.jpg" alt="" width="329" height="33" /></a></p><p>&#8220;If the coefficient is positive, that&#8217;ll push the probability of a bad trip up, right? And if it&#8217;s negative, it&#8217;s pushing the probability down,&#8221; I said, &#8220;So what do you notice?&#8221;</p><p>Victor studied the coefficients for a moment, &#8220;Attire is very important. The nicer the customer dresses, the more likely they are to have a bad trip.&#8221;</p><p>&#8220;Yeah, same with jitteriness, while tattoos work the opposite direction&#8221; I said, &#8220;And check out the favorite drug coefficients. X, meth, and coke all increase likelihood, while Ketamine, LSD, and shrooms all decrease likelihood.&#8221;</p><p>&#8220;And with phones, Blackberries are most likely to correlate with bad trips,&#8221; said Victor.</p><p>&#8220;I think what we&#8217;re seeing is that <a
href="http://en.wikipedia.org/wiki/Type_A_and_Type_B_personality_theory">Type A</a> individuals are most likely to have bad trips,&#8221; I said.</p><p>&#8220;Really?&#8221; asked Victor.</p><p>&#8220;Well, when I think about a suit-wearing, non-tattooed, jittery, Blackberry-using cokehead, I think Type A. When I think of a scruffy, laid-back person who likes Ketamine and uses an iPhone instead of a Blackberry, I think Type B,&#8221; I said.</p><p>Victor nodded his head side to side, &#8220;It&#8217;s not an airtight theory, but I see your point; people who are controlling might have difficulty with very strong acid.&#8221;</p><p>&#8220;OK, so the next thing we need to do is set up a calculator for future predictions,&#8221; I said, &#8220;For that we just take a new row of data through the same calculations with the coefficients we just found.&#8221;</p><p>I set up a calculator section in the spreadsheet for Victor and jammed in some made-up data:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/calculator.tiff1.jpg"><img
class="alignnone size-full wp-image-248" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/calculator.tiff1.jpg" alt="" width="134" height="317" /></a></p><p>&#8220;Let&#8217;s say we&#8217;ve got a 5&#8217;2&#8243; dude with mediocre attire, no tattoos, and the jitters. He loves coke and is glued to his Blackberry,&#8221; I said, &#8220;In that case, the survey says&#8230;he&#8217;s a .76 so he&#8217;s more likely to have a bad trip than a good one.&#8221;</p><p>Victor smiled, &#8220;Neat! So I could turn this into a little iPhone app and have my dealers refuse a customer or sell them a diluted sample if they score too high.&#8221;</p><p>&#8220;Exactly,&#8221; I said, &#8220;You can use this simple AI model to better customize your product based on how you think your customers will react to it.&#8221;</p><p>&#8220;This is stellar my boy,&#8221; said Victor, &#8220;Thanks.&#8221;</p><p>I laughed and reached out a hand to shake Victor&#8217;s, half mockingly. As I moved my hand toward him, I knocked our scrap paper onto the floor.</p><p>&#8220;Whoops,&#8221; I said, and Victor raised a hand and bent under the table to gather the spilt paper. Quickly, I slid the USB drive that agent Bestroff had given me into the USB port of the laptop.</p><p>The computer made a brief bump-bump noise, indicating something had been plugged in. I immediately broke into a sweat, but Victor seemed not to notice.</p><p>As he leaned back up with the papers, I slid the laptop a little more my way, palming the usb port.</p><p>&#8220;Let me just save this for you,&#8221; I said and clicked save while subtley sliding the USB drive out of the port and back along the table to myself. Victor collected the papers in his hands and seemed not to notice anything I did.</p><p>&#8220;That all you want to look at today?&#8221; I asked cheerily. My heart felt like it was about to burst, and my voice wavered slightly.</p><p>Victor set the papers down and fished a wad of bills out of his pants pocket.</p><p>He handed it to me, &#8220;That is all for today Alex. Thank you so much for being so useful.&#8221;</p><p>There was that word again. Useful. I wondered what happened to me when &#8220;useful&#8221; turned into &#8220;screwed me over with the DEA.&#8221;</p><h2>Big Data-ish Tip</h2><p>Short of <a
href="http://online.wsj.com/article/SB10001424052702304458604577488822667325882.html">basic summary statistics on large datasets</a>, predictive modeling is probably the <a
href="http://en.wikipedia.org/wiki/Netflix_Prize">most common big data pursuit</a>. Can I predict my customers&#8217; behavior using the data I&#8217;ve gotten in the past?</p><p>And I hope this post has convinced you that very simple predictive modeling is <a
href="http://gigaom.com/data/why-becoming-a-data-scientist-might-be-easier-than-you-think/">actually quite easy</a>. In fact, this Excel exercise is way harder than what it takes to create the same model in Matlab, R, SPSS, etc., because you&#8217;ve gotta solve for the coefficients yourself. <a
href="http://www.amazon.com/The-Elements-Statistical-Learning-Prediction/dp/0387848576/ref=sr_1_12?ie=UTF8&amp;qid=1351355856&amp;sr=8-12&amp;keywords=machine+learning">Understanding the guts of predictive models</a> is a lot harder than blindly using them, but for better or for worse, the latter approach can often work just fine.</p><p>Of course, the idea that this is the sum total of predictive modeling is something I&#8217;ve termed the &#8220;Kaggle falacy.&#8221; There&#8217;s <a
href="http://www.josephmisiti.com/why-becoming-a-data-scientist-is-not-actually">a lot more to this stuff than just training models</a>. For instance, which data should Victor have collected? Which features should be selected for the model? What if there&#8217;s a <a
href="http://en.wikipedia.org/wiki/Oversampling_and_undersampling_in_data_analysis" target="_blank">class imbalance</a> between good and bad trips? Maybe the data&#8217;s dirty, or it&#8217;s scaled oddly. What about dreaming up problems based on the data available, or dreaming up what data to gather and features to assemble in order to solve problems that are plaguing your business? The truth is that a holistic approach to machine learning is important, because <a
href="http://gigaom.com/data/forget-your-fancy-data-science-try-overkill-analytics/" target="_blank">shit like this</a> is just stupidity.</p><p>OK, let me catch my breath. All this to say, machine learning is an awesome tool for your analytics toolbox. It ain&#8217;t that hard to use (say, versus building a <a
href="http://en.wikipedia.org/wiki/Integer_programming" target="_blank">mixed integer program</a>). So download the workbook and give it a shot.</p><p>If you&#8217;re interested in further study on this topic, this book is the <a
href="http://www.liaad.up.pt/~ltorgo/DataMiningWithR/" target="_blank">effing bee&#8217;s knees</a>.</p><p><a
href="http://www.liaad.up.pt/~ltorgo/DataMiningWithR/"><img
class="alignnone" title="torgo" src="http://www.liaad.up.pt/~ltorgo/DataMiningWithR/imagens/book.jpg" alt="" width="258" height="401" /></a></p><p>Plus, the dude&#8217;s name is Torgo which reminds me of <a
href="http://www.youtube.com/watch?v=eKNTaWElUgA" target="_blank">Torgo from <em>Manos: The Hands of Fate</em></a>.</p><p>&nbsp;</p> ]]></content:encoded> <wfw:commentRss>http://analyticsmadeskeezy.com/2012/10/29/introduction-to-machine-learning-logistic-regression-for-predicting-bad-trips/feed/</wfw:commentRss> <slash:comments>11</slash:comments> </item> <item><title>Had a Little Run-in with the Federales</title><link>http://analyticsmadeskeezy.com/2012/10/29/federales/</link> <comments>http://analyticsmadeskeezy.com/2012/10/29/federales/#comments</comments> <pubDate>Mon, 29 Oct 2012 01:49:46 +0000</pubDate> <dc:creator>Alex</dc:creator> <category><![CDATA[Plot Only]]></category><guid
isPermaLink="false">http://analyticsmadeskeezy.com/?p=263</guid> <description><![CDATA[Two days after I got back from Europe, there was another early morning knock on the frat house door. Graham pulled me out of bed, fuming, &#8220;Dude, you gotta stop &#8230; <a
class="readmore" href="http://analyticsmadeskeezy.com/2012/10/29/federales/">Continue Reading &#8594;</a>]]></description> <content:encoded><![CDATA[<p>Two days after I got back from Europe, there was another early morning knock on the frat house door.</p><p>Graham pulled me out of bed, fuming, &#8220;Dude, you gotta stop these people bugging us at the house this early. I need my beauty sleep.&#8221;</p><p>Now, Graham doesn&#8217;t need beauty sleep any more than <a
href="http://cdn.whatculture.com/wp-content/uploads/2011/10/albert-finney-bourne.jpg">Albert Finny</a>, but he was right. I wasn&#8217;t even sure how Victor got my address now that I&#8217;d come to think of it.</p><p>When I&#8217;d dragged myself to the door and opened it, it was neither Andre nor Victor. Instead, the man standing in front of me looked like Ving Rhames with a big old bald dome of a head. His tone was as flat as his boring, gray suit.</p><p>&#8220;Alex Sheffield?&#8221; he asked in a bass voice.</p><p>&#8220;Yeah,&#8221; I said, sleepily, not really understanding what was going on, &#8220;Agent Bestroff, DEA. You need to come with me.&#8221;</p><p>I&#8217;m not afraid to admit that I nearly shat a brick. My ears must have been bright red, and my knees had started knocking a little. I would&#8217;ve been embarrassed at my lack of composure had I not been too scared shitless to care.</p><p>&#8220;Am I under arrest or something?&#8221; I asked.</p><p>Bestroff raised an eyebrow and spoke with a Mississippi drawl, &#8220;Do you wanna be?&#8221;</p><p>He loaded me into his Tahoe, and we drove to a <a
href="http://en.wikipedia.org/wiki/Brutalist_architecture">brutalist</a>, kakhi-colored building in the center of downtown. He took me through security and escorted me into an interview room on the sixth floor. Bestroff didn&#8217;t say a word to me til he&#8217;d settled across from me in an <a
href="http://en.wikipedia.org/wiki/Emeco_1006">Emeco chair</a>.</p><p>&#8220;Why do you think you&#8217;re here?&#8221; asked Bestroff. He ran a hand across his bald head.</p><p>I shrugged and remained mute.</p><p>Bestroff stood and left the room. A moment later he reentered with a folder, which he flopped disinterestedly on the table in front of me. I opened it and looked inside to find a stack of photos.</p><p>Riding in the truck with Andre. Victor and I at the hotel. Victor and I at the airport. Even on the freaking airplane.</p><p>&#8220;We&#8217;ve got all the audio too,&#8221; said Bestroff, &#8220;You&#8217;re a very good tutor.&#8221;</p><p>For the first time, Bestroff cracked a smile. He knew he had me in a position to squirm.</p><p>&#8220;I want a lawyer,&#8221; was all I said.</p><p>Bestroff started to laugh, &#8220;Look Alex, you little shit. I don&#8217;t care about you, and I sure as well don&#8217;t want to waste my time charging you. No, I want Victor, and I want his associates. All of &#8216;em. And you&#8217;re going to help me get them.&#8221;</p><p>I was still freaking out a bit, but Bestroff&#8217;s tone was reassuring. He continued, &#8220;And if you don&#8217;t want to help, I&#8217;m going to approach your school, your frat; hell, I&#8217;m gonna have a talk with your parents. I&#8217;ve got enough to jail you, but even if I didn&#8217;t, I love dealing with spoiled college kids. People like you are always scared and always have too much to lose.&#8221;</p><p>He had me pegged. I&#8217;m not afraid to admit it. And I sure as hell didn&#8217;t want my dad involved in this. I&#8217;d never hear the end of it.</p><p>I just nodded, &#8220;What do you want me to do?&#8221;</p><p>Bestroff cracked another huge smile, &#8220;We&#8217;re gonna start small. You&#8217;re gonna sign some papers. We&#8217;ll have a chat. And then we&#8217;re gonna all get back to work.&#8221;</p><p>Bestroff held out a hand across the table, &#8220;Welcome to the team, asshole.&#8221;</p><p>Two hours later, Bestroff escorted me out the building and made me walk back home past the Varsity. In my pocket I carried a little usb drive, but it weighed on me like a brick.</p><p>&#8220;When Victor&#8217;s not looking, pop it in his laptop for five seconds, then remove it. That&#8217;s all you&#8217;ve got to do,&#8221; he&#8217;d said, &#8220;We&#8217;ll log all his communications after that.&#8221;</p><p>It was a simple task, but those five seconds could get me killed. By the time I&#8217;d made it back to the house, the stress was palpable. And that was before I saw Andre leaning against his car door outside the front of the house. I was shitting so many bricks today, I could&#8217;ve built a pyramid out of them.</p> ]]></content:encoded> <wfw:commentRss>http://analyticsmadeskeezy.com/2012/10/29/federales/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>MDA for MDMA: Multi-criteria Decision Analysis and ecstasy pill design</title><link>http://analyticsmadeskeezy.com/2012/10/15/mda-for-mdma-multi-criteria-decision-analysis-and-ecstasy-pill-design/</link> <comments>http://analyticsmadeskeezy.com/2012/10/15/mda-for-mdma-multi-criteria-decision-analysis-and-ecstasy-pill-design/#comments</comments> <pubDate>Mon, 15 Oct 2012 14:16:04 +0000</pubDate> <dc:creator>Alex</dc:creator> <category><![CDATA[Multi-criteria Decision Analysis]]></category> <category><![CDATA[Optimization]]></category> <category><![CDATA[Analytic Hierarchy Process]]></category> <category><![CDATA[Analytics]]></category> <category><![CDATA[Excel]]></category> <category><![CDATA[Multi-criteria decision analysis]]></category> <category><![CDATA[Rank Order Centroid]]></category> <category><![CDATA[Weighting techniques]]></category><guid
isPermaLink="false">http://analyticsmadeskeezy.com/?p=164</guid> <description><![CDATA[NOTE: Here is the spreadsheet for this post if you&#8217;d like to follow along. This is gonna be an awesome sheet to have laying around just as a refresher on &#8230; <a
class="readmore" href="http://analyticsmadeskeezy.com/2012/10/15/mda-for-mdma-multi-criteria-decision-analysis-and-ecstasy-pill-design/">Continue Reading &#8594;</a>]]></description> <content:encoded><![CDATA[<p><em>NOTE: <a
href="https://dl.dropbox.com/u/98476545/MDA.xlsx">Here is the spreadsheet</a> for this post if you&#8217;d like to follow along. This is gonna be an awesome sheet to have laying around just as a refresher on these techniques. And remember, don&#8217;t forget to sign up for the newsletter to hear about future Analytics Made Skeezy tutorials.</em></p><p>What a crazy weekend. Nuts. I&#8217;m completely wiped, but I&#8217;m sitting here typing, because I&#8217;m jet lagged and can&#8217;t sleep a wink.</p><p>It all started Friday morning with a knock on my bedroom door. Graham was standing there in his tighty whiteys (why does he wear those again?) and mustache looking like some kind of molester. He was rubbing sleep from his eye.</p><p>&#8220;There&#8217;s someone at the door for you,&#8221; said Graham.</p><p>&#8220;The front door?&#8221; I asked groggily. The night before had been fun but unkind, and my head felt a little like it&#8217;d been taxidermied.</p><p>&#8220;Yes, Alex. The front door you jackass. What other door would I be talking about?&#8221; he said, irritated.</p><p>My first thought was Andre. I just knew it was him. Victor&#8217;d sent him again. How much math can one drug dealer need help on, I wondered.</p><p>&#8220;Some older dude in a suit,&#8221; Graham added as I rolled out of bed and tossed on some pants, &#8220;Looks like he could be your dad, man.&#8221;</p><p>Oh shit, I thought. This is gonna be the FBI, DEA, who knows who. I&#8217;m so screwed.</p><p>But it was neither Andre nor the heat. It was Victor. Victor in a three piece suit, looking dapper as hell. He was standing at the door of the frat hourse eying his watch with impatience when I walked up.</p><p>&#8220;Come on my boy,&#8221; he said when he saw me, &#8220;We must get going.&#8221;</p><p>&#8220;Huh?&#8221; I asked, still a big groggy. It was only just now 6 AM.</p><p>&#8220;We have a plane to catch,&#8221; he said, &#8220;Put on some clothes, and grab your passport and wallet. You do have a passport, don&#8217;t you?&#8221;</p><p>&#8220;Yeah, I have a passport,&#8221; I answered, &#8220;But why?&#8221;</p><p>&#8220;I&#8217;ll tell you in the car, now go get what you need for the weekend,&#8221; he said and turned back to the CLK Black that was idling in front of the house.</p><p>I shoved some stuff in a bag as fast as I could, and moments later, we were speeding down 85 toward the airport.</p><p>&#8220;I must go to Amsterdam on business this weekend, and I have some decisions I need to make before I meet with my suppliers. There&#8217;s no time for you to help me here, so you must work with me on the plane,&#8221; he said.</p><p>&#8220;I&#8217;m going to Amsterdam?&#8221; I asked.</p><p>&#8220;Have you ever been?&#8221; he asked.</p><p>&#8220;Never left the states except to Canada and the Bahamas,&#8221; I said.</p><p>&#8220;Well, then you should enjoy this,&#8221; he laughed and looked over at me, &#8220;Consider it a short European holiday.&#8221;</p><p>Any thought of this being a holiday faded when I passed through security at Hartsfield in the company of an international drug dealer. The TSA agent stopped me, and for a second I thought that surely I&#8217;d be arrested for who knows what. But it turned out that I&#8217;d left my lighter in my pocket, so I mopped away the bullets I was sweating and followed Victor to the international concourse.</p><p>You get this idea from the movies that all drug dealers fly in private jets, but that&#8217;s just not the case it seems. I asked him about it.</p><p>&#8220;Private jets attract scrutiny. I lead a simple life, but I do like to fly first class on international travel,&#8221; he said with a shrug.</p><p>When we&#8217;d boarded, gotten our gin and tonics in order, and leveled out at thirty six thousand feet, Victor removed his laptop from his carry-on.</p><p>&#8220;So here&#8217;s the deal,&#8221; he said, &#8220;I&#8217;m meeting with my main X supplier in Amsterdam, and he wants me to pick a design for my pills from the new ones he&#8217;s got rolling of the line.&#8221;</p><p>&#8220;OK,&#8221; I nodded.</p><p>He opened a spreadsheet and pointed the screen my way.</p><p>&#8220;These are my options,&#8221; he said.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Options.png"><img
class="alignnone  wp-image-165" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Options.png" alt="" width="541" height="278" /></a></p><p>&#8220;Wow, ok,&#8221; I said, &#8220;Kindof random, aren&#8217;t they?&#8221;</p><p>&#8220;He makes what he makes. Strange guy,&#8221; said Victor.</p><p>&#8220;So why not just pick one, any one?&#8221; I asked, &#8220;Like the four leaf clover. That could be cool.&#8221;</p><p>&#8220;If you were a car company would you just release any car? Would you just plop out an <a
href="http://en.wikipedia.org/wiki/Pontiac_Aztek">Aztek</a> and be done with it?&#8221; he asked.</p><p>I shook my head no.</p><p>&#8220;Of course not,&#8221; he said, &#8220;And in this case, we know for a fact that pill attributes directly affect sales. That&#8217;s what my dealers tell me. At the bigger festivals and shows, there&#8217;s plenty of competition. I need my pills to stand out.&#8221;</p><p>&#8220;So what are the most important attributes?&#8221; I asked.</p><p>&#8220;Well, I asked that of twenty of my trusted dealers. I had them give me a ranked list of the attributes that mattered when they tried to sell this stuff,&#8221; Victor said, &#8220;I also had them vote individually on which attribute was most important in each pair of attributes. This is what they gave me.&#8221;</p><p>He showed me two small tables of data. The ranked list:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Rank.jpg"><img
class="alignnone size-full wp-image-166" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Rank.jpg" alt="" width="138" height="142" /></a></p><p>&#8220;So color is more important than purity?&#8221; I asked.</p><p>&#8220;Druggies like pretty colors. Especially under black light. Very few bring <a
href="http://en.wikipedia.org/wiki/Simon's_reagent">Simon&#8217;s regeant</a> with them, and even when they do, they&#8217;re willing to accept less than 100% MDMA so long as the additives are benign,&#8221; he shrugged.</p><p>&#8220;Explain texture,&#8221; I said.</p><p>&#8220;If the pill looks bumpy or brittle, people seem to think it&#8217;s cheap, like back alley lab cheap,&#8221; he answered.</p><p>&#8220;And timeliness?&#8221; I asked.</p><p>&#8220;Is the pill stamped with an image, shape, or text that provides a timely reference to world events?&#8221; Victor said, &#8220;So the Obama pill and the Republican pill are both timely since it&#8217;s an election season, while the four leaf clover would be better next March for St. Patty&#8217;s. People get a kick out of those touches, and it makes the pill seem fresh.&#8221;</p><p>&#8220;So &#8216;pop culture&#8217; is like the Bart Simpson pill,&#8221; I said, &#8220;It&#8217;s a reference.&#8221;</p><p>&#8220;Yes, and likewise &#8216;Brand&#8217; just means it gives a brand reference,&#8221; he said.</p><p>&#8220;What about happy?&#8221; I asked.</p><p>Victor laughed, &#8220;Does the pill look happy? This seemed stupid to me, but many of my dealers agreed on this. People like uplifting images on the pill. Something that&#8217;s not intimidating.&#8221;</p><p>&#8220;Weird,&#8221; I said.</p><p>&#8220;And here&#8217;s the vote data,&#8221; he added and pulled up another table, &#8220;I had 20 dealers weigh in.&#8221;</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Votes.jpg"><img
class="alignnone size-full wp-image-168" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Votes.jpg" alt="" width="269" height="439" /></a></p><p>&#8220;OK, so here you&#8217;ve got all the pairwise comparisons with vote counts,&#8221; I said.</p><p>Victor nodded, &#8221;And here I graded my options as best I could based on these attributes.&#8221; He flipped over to a new sheet:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Big1.jpg"><img
class="alignnone size-full wp-image-167" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Big1.jpg" alt="" width="632" height="989" /></a></p><p>&#8220;One means yes, zero means no. The MDMA column gives the percentage MDMA. Also, I gave Bart only half a point for his color since it&#8217;s not very vibrant,&#8221; he said.</p><p>Victor took a sip of his drink and looked over at me, &#8220;So which one do I pick?&#8221;</p><p>I laughed, &#8220;So what you&#8217;re bumping up against here is a topic called <a
href="http://en.wikipedia.org/wiki/Multi-criteria_decision_analysis">multi-criteria decision analysis</a>. How do you make decisions in the midst of multiple, completing objectives such as the oft-cited &#8216;risk versus reward.&#8217;&#8221;</p><p>&#8220;So this is like picking stocks?&#8221; he asked.</p><p>&#8220;To a degree. We&#8217;ve got a whole host of criteria here, but we can only pick one pill design. I can tell you up front though that whatever we pick, it ain&#8217;t going to be the Optimus Prime, the clover, the smiley face, or the crown,&#8221; I said.</p><p>Victor furrowed his brow and looked back at his spreadsheet, &#8220;Why?&#8221;</p><p>&#8220;Because those four pills are all strictly dominated by other pills. They&#8217;re not <a
href="http://en.wikipedia.org/wiki/Pareto_efficiency">Pareto efficient</a>,&#8221; I said.</p><p>Victor&#8217;s brow furrowed even further, so I pointed out a few rows in the spreadsheet, &#8220;What I mean by that is that if we look at the grades you&#8217;ve given here I can see that Bart has everything the Smiley pill has and more. So no matter which attributes are most important, Bart is always going to beat Smiley. So we can ignore Smiley.&#8221;</p><p>Victor nodded, &#8220;That makes sense.&#8221;</p><p>&#8220;So then the question is,&#8221; I said, &#8220;How do we combine your attribute scores into a single score here?&#8221;</p><p>&#8220;You average them,&#8221; said Victor.</p><p>I smiled, &#8220;Right, but we can&#8217;t do a straight average. After all, some attributes are more important. We have to do a weighted average.&#8221;</p><p>&#8220;Sure,&#8221; said Victor, &#8220;But what weights do we use?&#8221;</p><p>&#8220;For that, we get into a strange pseudo-scientific field of weighting techniques. We know that our weights should sum to 1, and we know that if an attribute is more important than another, then its weight should be bigger.&#8221;</p><p>&#8220;But how much bigger?&#8221; Victor interrupted.</p><p>&#8220;Precisely,&#8221; I said, &#8220;How should the weights decay as you go down in ranking? It depends. A lot of psychology goes into it. People tend to overweight their lower criteria when buying things only to make the decision almost entirely off their top criterion. For instance, they may say they care about fuel economy right after cup holders and paint color, but when your customer buys a Hummer, you know that that preference didn&#8217;t hold much weight.&#8221;</p><p>&#8220;So the weights should decay rapidly?&#8221; he asked.</p><p>&#8220;Fairly rapidly, yes,&#8221; I answered, &#8220;I wouldn&#8217;t give all the weight to &#8216;Color&#8217; but I wouldn&#8217;t give but a tiny bit to &#8216;Brand.&#8217;&#8221;</p><p>&#8220;Got it,&#8221; he said, &#8220;So where do we start assigning the weights?&#8221;</p><p>&#8220;Well, let&#8217;s take a look at three &#8216;direct weighting&#8217; techniques, and one &#8216;indirect&#8217; weight technique that will use the vote data you&#8217;ve given me instead of the ranking data,&#8221; I said.</p><p>&#8220;Sounds good,&#8221; answered Victor.</p><p>I set Victor&#8217;s computer on the seat tray in front of me and added a column to the attribute ranking where I inverted the ranks:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/invert.jpg"><img
class="alignnone size-full wp-image-171" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/invert.jpg" alt="" width="200" height="139" /></a></p><p>&#8220;We&#8217;ll need that in a sec,&#8221; I said, &#8220;The first technique I want to show you is the simplest. It&#8217;s called Rank Sum, and the way it works is that if I come in first place  out of eight criteria, I get 8 points out of a total of 8+7+6+5+4+3+2+1 points equal to 36 points. So my weight is .22. If I come in last place I only get 1 out of 36 points so my weight is .03.&#8221;</p><p>I scribbled out the formula on a napkin:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/ranksum.png"><img
class="alignnone size-medium wp-image-172" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/ranksum-300x168.png" alt="" width="300" height="168" /></a></p><p>&#8220;This is the calculation for each attribute <em>i </em>with rank <em>ri </em>where in this case <em>K</em> is 8,&#8221; I said. In excel it looked like this:</p><p>=(9-A2)/(9*8-SUM(A$2:A$9))</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/RankSum21.jpg"><img
class="alignnone size-full wp-image-178" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/RankSum21.jpg" alt="" width="396" height="173" /></a></p><p>&#8220;Those weights don&#8217;t taper off very fast,&#8221; I said as I dragged down the formula, &#8220;In fact, they decay linearly.&#8221;</p><p>&#8220;So what other options are there?&#8221; asked Victor.</p><p>&#8220;Well, on the flip side (pun intended), there&#8217;s something called Rank Reciprocal where I get the value of my inverse rank divided by the sum of the other inverse ranks,&#8221; I said.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/rankreciprocal.png"><img
class="alignnone size-medium wp-image-174" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/rankreciprocal-300x186.png" alt="" width="300" height="186" /></a></p><p>I filled in the column in Excel with this formula:</p><p>=C2/SUM($C$2:$C$9)</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/RankReciprocal21.jpg"><img
class="alignnone size-full wp-image-177" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/RankReciprocal21.jpg" alt="" width="347" height="142" /></a></p><p>&#8220;Here we get better decay at the beginning,&#8221; I said.</p><p>&#8220;But &#8216;Happy&#8217; and &#8216;Brand&#8217; actually count for more at the end,&#8221; he said.</p><p>&#8220;Right, so let&#8217;s look at my favorite technique. It&#8217;s kindof in the middle of these two. It&#8217;s called Rank Order Centroid, although occasionally you&#8217;ll hear it referred to as <a
href="http://en.wikipedia.org/wiki/Multi-attribute_global_inference_of_quality">MAGIQ</a> or SMARTER in the literature,&#8221; I said and jotted down a new formula on my napkin:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/rankordercentroid1.png"><img
class="alignnone  wp-image-180" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/rankordercentroid1.png" alt="" width="442" height="270" /></a></p><p>&nbsp;</p><p>&#8220;Just like rank reciprocal, it uses the inverted rank values,&#8221; I said, &#8220;but this one gives us a decay that&#8217;s a bit more agreeable. Not that you care, but the calculation is also a bit better grounded in the natural world. It&#8217;s a bastardized center of mass calculation.&#8221;</p><p>I put the formula in Excel and dragged it down:</p><p>=SUM(C2:C$9)/8</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Roc2.jpg"><img
class="alignnone size-full wp-image-181" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Roc2.jpg" alt="" width="533" height="171" /></a></p><p>I graphed the three different weight columns:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Plot.png"><img
class="alignnone  wp-image-183" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Plot.png" alt="" width="544" height="544" /></a></p><p>&#8220;See how the Rank Order Centroid weights decay quickly and finish low?&#8221; I asked.</p><p>Victor nodded.</p><p>&#8220;That fits pretty well with human psychology. Whenever I don&#8217;t have weights to start with in a problem, I go the ROC route,&#8221; I said.</p><p>&#8220;But then what about the votes?&#8221; asked Victor.</p><p>&#8220;Ah ha,&#8221; I said, &#8220;You&#8217;re right. We need to go over indirect weighting.&#8221;</p><p>I adjusted myself in my seat a little. The cabin was hot, and drinking only made it hotter. My butt was starting to stick to the seat.</p><p>&#8220;So here&#8217;s the deal,&#8221; I said, &#8220;Asking a group of people like your dealers to create a ranked list can be an inherently flawed question. Group decision-making on deciding the placement of low-ranking criteria is shit. Twenty people cannot collectively decide whether fifth and sixth place shouldn&#8217;t be reversed. If there&#8217;s a loud person in the room, no one&#8217;s gonna fight to make sure their ordering of low-ranking criteria wins.&#8221;</p><p>&#8220;So instead, using pairwise comparisons, like we have in this voting data, keeps the task manageable,&#8221; I said, &#8220;Furthermore, having votes instead of a pure &#8216;this is better than that&#8217; gives us some more data we can use.&#8221;</p><p>I flipped the tab in the spreadsheet over to the voting data, &#8220;So we can use something called the <a
href="http://en.wikipedia.org/wiki/Analytic_hierarchy_process">analytic hierarchy process or AHP</a> to transform these votes into weights. It&#8217;s a bit convoluted though.&#8221;</p><p>Victor nodded, &#8220;I&#8217;m trapped on a plane with nothing better to do. Let&#8217;s try it.&#8221;</p><p>&#8220;OK,&#8221; I said, folding my hands and cracking my knuckles, &#8220;You&#8217;ve got the winners in each vote in the left column, so what I&#8217;m going to go is take the vote difference and then normalize that difference to a score between 1 and 9 where 1 is a tie and 9 is a 20-to-0 vote.&#8221;</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Votescore.jpg"><img
class="alignnone size-full wp-image-185" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Votescore.jpg" alt="" width="396" height="437" /></a></p><p>I plugged this formula into Excel to do the normalization:</p><p>=E2*(8/20)+1</p><p>and dragged it down. I then created a new tab called &#8216;AHP&#8217; and created a criteria X criteria grid with 1s on the diagonal, the normalized scores on the upper triangle, and the inverse of the normalized scores on the low triangle like this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/AHP1.jpg"><img
class="alignnone size-full wp-image-186" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/AHP1.jpg" alt="" width="588" height="138" /></a></p><p>&#8220;So this is just a matrix representation of your vote data where a value greater than 1 indicates that the row value is more important and a value less than 1 indicates that the column value is more important,&#8221; I said.</p><p>&#8220;What do we do with it though?&#8221; asked Victor.</p><p>&#8220;We&#8217;re going to pull an eigenvector out of it that&#8217;s going to be our weights,&#8221; I said, &#8220;which is a fancy word for a simple computation. The first thing we do is multiply all the elements on a row together and take their eighth root in this case because there&#8217;s 8 elements.&#8221;</p><p>I added in the column to the right of the matrix taking the 8th root of the product of the elements on each row.</p><p>=PRODUCT(B2:I2)^(1/8)</p><p>&#8220;Then I&#8217;m going to total these values up and normalize them by their sum, so that the vector adds up to 1. And that&#8217;ll be my weight vector,&#8221; I said.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/AHP2.jpg"><img
class="alignnone size-full wp-image-187" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/AHP2.jpg" alt="" width="754" height="194" /></a></p><p>&#8220;And so the advantage of these weights is that I can elicit them without making the group create a ranking together?&#8221; asked Victor.</p><p>&#8220;Yes, and there are all kinds of <a
href="http://www.boku.ac.at/mi/ahp/ahptutorial.pdf">boring</a> <a
href="http://www.slideshare.net/ricardo.vargas/using-the-analytic-hierarchy-process-ahp-to-select-and-prioritize-projects-in-a-portfolio">guides</a> out there on how to do this,&#8221; I said, &#8220;But I think they can be a <a
href="http://www.robustdecisions.com/making-robust-decisions/2008/09/why-pairwise-comparisons-are-waste-of.php">waste of time</a> for most stuff.&#8221;</p><p>&#8220;So can we see how the various weights perform?&#8221; asked Victor.</p><p>&#8220;Let&#8217;s do it,&#8221; I said. I moved back over to Victor&#8217;s choices, pasted in the weights and took the sumproduct of weights and scores for each pill:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Final1.jpg"><img
class="alignnone size-large wp-image-189" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Final1-1009x1024.jpg" alt="" width="642" height="651" /></a></p><p>We stared at the results a moment.</p><p>&#8220;Obama wins for everything but Rank Sum,&#8221; said Victor, motioning to the last row, &#8220;for that technique, Bart barely wins.&#8221;</p><p>&#8220;Right,&#8221; I said, &#8220;And that&#8217;s because Rank Sum decays slower, so even though Bart&#8217;s color is only a half point, he still gets lots of points later. That&#8217;s the wrong call in my opinion.&#8221;</p><p>Victor nodded, &#8220;I agree.&#8221;</p><p>&#8220;The rest are quite similar with departures occurring further down the pill ranking,&#8221; I said, &#8220;And that should tell you that your time is best not spent doing a crapload of complex scoring on pairwise comparisons. Just be careful when you rank your criteria.&#8221;</p><p>&#8220;That makes sense,&#8221; said Victor, &#8220;I think it&#8217;s interesting that some of those points you excluded did well here.&#8221;</p><p>&#8220;Yeah, that&#8217;s because while they&#8217;re not Pareto efficient, they still had points in the right weighted places. The elephant was Pareto efficient but on low-weighted criteria.&#8221;</p><p>&#8220;Ah ha,&#8221; said Victor.</p><p>He slammed the lid to his laptop shut and smiled a broad smile, &#8220;Green Obama it is! Care for another drink?&#8221;</p><h2>Big Data-ish Tip</h2><p>Wanting to weight things comes up more often than you&#8217;d think in analytics. It&#8217;s not exciting, but when you have to do it, it&#8217;s nice to have some tools. If you can&#8217;t tell, I gravitate toward ROC as a quick-and-dirty technique that provides generally OK results.</p><p>It&#8217;s terribly common when dealing with <a
href="http://en.wikipedia.org/wiki/Performance_indicator">KPIs</a>, performance dashboards, and other various Lean Six Sigma garbage to need to weight scores. Doing a weighted average of scores is also one of the few ways to solve a linear programming problem when you&#8217;ve got multiple, conflicting objectives. You can always do something like put one of the objectives in the problem as a constraint or something, but if you can shove everything in the objective function, why not?</p><p>The government really digs this stuff, especially the military. If you&#8217;ve got a ton of primary and secondary objectives, how do you build a simplified dashboard full of red/yellow/green indicators? You&#8217;re gonna have to combine some stuff, and these weighting techniques are one way to do it.</p><p>Now, if you&#8217;re working a problem with tons of data&#8230;for instance, let&#8217;s say Victor had months of demand data for his pills in a database. In that case, it might be possible to build a <a
href="http://en.wikipedia.org/wiki/Predictive_analytics#Classification_and_regression_trees">CART</a> model or a random forest model of pill attribute versus likelihood to be purchased or demand or something. Then you could use the relative importance of the attributes from the model as weights. That&#8217;s how I&#8217;d do it if I had the data.</p><p>&nbsp;</p> ]]></content:encoded> <wfw:commentRss>http://analyticsmadeskeezy.com/2012/10/15/mda-for-mdma-multi-criteria-decision-analysis-and-ecstasy-pill-design/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Even Wholesale Drug Dealers Can Use a Little Retargeting: Graphing, Clustering &amp; Community Detection in Excel and Gephi</title><link>http://analyticsmadeskeezy.com/2012/10/11/graphing-clustering-community-detection-wholesale-drug-deals-using-excel-and-gephi/</link> <comments>http://analyticsmadeskeezy.com/2012/10/11/graphing-clustering-community-detection-wholesale-drug-deals-using-excel-and-gephi/#comments</comments> <pubDate>Thu, 11 Oct 2012 02:24:30 +0000</pubDate> <dc:creator>Alex</dc:creator> <category><![CDATA[Clustering]]></category> <category><![CDATA[Data Mining]]></category> <category><![CDATA[Graphing]]></category> <category><![CDATA[Community Detection]]></category> <category><![CDATA[Excel]]></category> <category><![CDATA[Gephi]]></category> <category><![CDATA[Modularity]]></category> <category><![CDATA[Trimmed Nearest Neighbors Graph]]></category><guid
isPermaLink="false">http://analyticsmadeskeezy.com/?p=86</guid> <description><![CDATA[NOTE: Here&#8217;s the final spreadsheet for this post if you&#8217;d like to work along with Alex and Victor. No drugs needed. Two days later, I was walking to class at &#8230; <a
class="readmore" href="http://analyticsmadeskeezy.com/2012/10/11/graphing-clustering-community-detection-wholesale-drug-deals-using-excel-and-gephi/">Continue Reading &#8594;</a>]]></description> <content:encoded><![CDATA[<p><em>NOTE: Here&#8217;s the <a
href="https://dl.dropbox.com/u/98476545/Wholesale.xlsx">final spreadsheet</a> for this post if you&#8217;d like to work along with Alex and Victor. No drugs needed.</em></p><p>Two days later, I was walking to class at 9 in the morning when Andre pulls up in his truck.</p><p>&#8220;Get in the car, Alex,&#8221; he said to me through bites of a breakfast burrito.</p><p>&#8220;But I&#8217;ve got class,&#8221; I protested. The other students who walked by me on Tech Parkway eyed our conversation with curiosity.</p><p>Andre squirted some hot sauce on the end of his burrito and nodded.</p><p>&#8220;I don&#8217;t give two shits what you&#8217;ve got, man. Duty calls,&#8221; he said and took another bite.</p><p>I had a data structures class that morning, and I was truly hesitant to miss it. I had already slept through four others this semester.</p><p>&#8220;Can&#8217;t we just do this later?&#8221; I asked with a sigh.</p><p>&#8220;If you want to keep the big man waiting,&#8221; Andre said with a raised eyebrow, &#8220;It&#8217;s your funeral.&#8221;</p><p>I didn&#8217;t like Andre&#8217;s choice of idioms. I muttered some profanities to myself and got in the car. We sped off.</p><p>Half an hour later I was in neither Hapeville nor Buckhead. No, of all places, I met Victor in a Barnes &amp; Noble. I couldn&#8217;t freaking believe it, but there he was sitting at a table in the coffee shop drinking a triple espresso and staring at his laptop. When he saw me walk in, he smiled and motioned me over to his table.</p><p>&#8220;Alex, my friend,&#8221; he said cheerily, &#8220;How are you this morning?&#8221;</p><p>I frowned, &#8220;I had class, but Andre pulled me away.&#8221;</p><p>Victor frowned along with me, &#8220;You should have told him to wait. I don&#8217;t mean to disrupt your schedule.&#8221;</p><p>But I could tell from Victor&#8217;s tone that he was all politeness. Of course he meant to disrupt my schedule. This was not a man who waited for anything. I took a seat next to him and draped my backpack across the back of my chair.</p><p>&#8220;Would you like something to drink?&#8221; he asked.</p><p>&#8220;Nah, I&#8217;ve already had two cups. So what&#8217;s on the agenda today?&#8221; I asked.</p><p>Victor gave me one of his cheshire cat smiles.</p><p>&#8220;Today we talk about my wholesale business,&#8221; he said.</p><p>&#8220;Wholesale?&#8221;</p><p>Victor nodded, &#8220;Yes, it used to be that I&#8217;d occasionally have more product than I needed and less cash than I needed, so I&#8217;d sell some of my product in bulk to other dealers. Sometimes even competitors. Slowly over time though, I&#8217;ve formalized this business. I handle transpo into the states and sell in bulk to a variety of clients, most operating in cities that I do not. They get a substantial discount off street value for buying in bulk, and I make good money as well.&#8221;</p><p>&#8220;OK,&#8221; I said, &#8220;So what&#8217;s the challenge?&#8221;</p><p>&#8220;Ah, you wouldn&#8217;t be here if there wasn&#8217;t a problem, right?&#8221; he asked.</p><p>&#8220;Well,&#8221; he continued, &#8220;I now have a hundred customers who buy from me regularly, and I send them deals regularly. But I want to know more about their interests. I want to know what they&#8217;re looking for. I do not know all these fellows personally. Some are friends of friends, flashing headlights in an empty parking lot, but I have their purchasing history. I was wondering what it told me about them. Whether there was a way to target them better in the future. Maybe hit them with the same deal twice if they didn&#8217;t take it the first time I contacted them, but I know they should be interested.&#8221;</p><p>&#8220;Sure, they call that retargeting,&#8221; I said.</p><p>&#8220;Yes, retargeting,&#8221; he nodded and took a sip of his espresso.</p><p>I was a bit freaked out to be talking about this in a public place, but Victor seemed not to mind, and with the sounds of the espresso machine and the grinder and folks talking on their phones, our conversation just kindof blended in.</p><p>&#8220;So can you show me the data?&#8221; I asked.</p><p>Victor pushed his laptop screen my way. On it was a spreadsheet with a tab called &#8220;Inventory&#8221; that looked like this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic1.jpg"><img
class="alignnone size-full wp-image-96" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic1.jpg" alt="" width="820" height="414" /></a></p><p>I looked the data over.</p><p>&#8220;So I&#8217;ve got deals offered on certain dates going down the rows, with the product type, the quantity, the discount off street value, the country of origin, and this last column &#8216;Ready for use&#8217;&#8230;what does that mean?&#8221; I said.</p><p>&#8220;Ready for use just means that it&#8217;s not formed into some weird brick or shoved up a teddy bear&#8217;s ass and encased in concrete,&#8221; Victor answered, &#8220;You could take it streetside the day you bought it without further processing.&#8221;</p><p>I nodded, &#8220;And then the columns are your customers where a 1 indicates that they took you up on an offer?&#8221;</p><p>&#8220;Correct,&#8221; said Victor.</p><p>&#8220;OK, so here&#8217;s what we&#8217;re going to do with this data,&#8221; I said, &#8220;We&#8217;re going to try to detect communities in it. Patterns, types of customers. We&#8217;re going to use some algorithms to find hidden segments in it that you can use to target your customers better.&#8221;</p><p>&#8220;That sounds like a perfect idea to me,&#8221; Victor said, smiling, &#8220;Where do we begin?&#8221;</p><p>&#8220;OK, I&#8217;m gonna set up a few things in this spreadsheet, and I just want you to follow along with me as best you can,&#8221; I said, &#8220;First, I&#8217;m going to put a row at the bottom of the table that totals up how many deals each customer took.&#8221;</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic3.png"><img
class="alignnone  wp-image-98" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic3.png" alt="" width="720" height="229" /></a></p><p>&#8220;Then, I&#8217;m going to make another tab called &#8216;InventoryInvert&#8217; in this spreadsheet where I&#8217;m going to take your data and transpose it by copying the whole table and doing a paste special &#8211;&gt; values on it with the transpose box checked,&#8221; I said. When I&#8217;d done that, I had a new tab that looked like this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic2.jpg"><img
class="alignnone size-full wp-image-97" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic2.jpg" alt="" width="481" height="532" /></a></p><p>&#8220;Now that I have that,&#8221; I continued, &#8220;I&#8217;m going to create a graph of customer distances in a third sheet.&#8221;</p><p>&#8220;Graph?&#8221; asked Victor.</p><p>I nodded, &#8220;Yeah, let me explain this part. Let&#8217;s imagine a network or a web, kinda like a spiderweb, where each customer is connected to every other customer. The thickness of each connection is based on how many deals the two customers both matched up on.&#8221;</p><p>&#8220;So you and I would get a point or something if we both took the same deal?&#8221; asked Victor.</p><p>&#8220;Yes,&#8221; I said, &#8220;Exactly. Except that I want to penalize people a little bit who are just going through and picking every deal, so instead of giving us a solid point, we&#8217;re going to get 1 point divided by the square root of the number of deals I took plus the square root of the number of deals you took.&#8221;</p><p>&#8220;Those are the numbers in that sum row you just added, yes?&#8221;</p><p>&#8220;Correct,&#8221; I said, &#8220;This is a concept called <a
href="http://en.wikipedia.org/wiki/Cosine_similarity">cosine similarity</a> just for your own edification.&#8221;</p><p>I created a new tab in the spreadsheet called &#8216;EdgeWeights&#8217;, and in it, I created a matrix of customers X customers where each edge weight was calculated by dragging this formula around from the top left cell:</p><p>{=IF(ROW()&lt;&gt;COLUMN(),SUMPRODUCT(Inventory!G$3:G$101,TRANSPOSE(InventoryInvert!$B7:$CV7))/(SQRT((Inventory!G$102)+SQRT(InventoryInvert!$CW7))),0)}</p><p>&#8220;What do the curly braces mean?&#8221; asked Victor.</p><p>&#8220;Ah, that&#8217;s called an array formula in Excel. Because I have to use the transpose function in my calculation, I need the curly braces. To get the curly braces, just type the formula without them and hit CTRL+SHIFT+ENTER (Apple is COMMAND+SHIFT+ENTER). They&#8217;ll appear on their own,&#8221; I answered, continuing, &#8220;So what this formula is saying is that so long as the two customers in the matrix don&#8217;t match, I want to have a weight on the edge of the graph. And I want that weight to be equal to the sumproduct of their two deal vectors divided through by the sum of the square roots of the number of deals they took. It&#8217;s just the cosine similarity calculation in an excel formula.&#8221;</p><p>I dragged the formula from the first cell in the table to the rest of the table, and the sheet looked like this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic4.jpg"><img
class="alignnone size-full wp-image-100" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic4.jpg" alt="" width="667" height="306" /></a></p><p>&#8220;So what do we do with this?&#8221; asked Victor.</p><p>&#8220;Well, we&#8217;ve got a whole bunch of edges here, but really all we care about are the most significant relationships. For each customer, who are their nearest neighbors?&#8221; I said, &#8220;So I&#8217;m going to create what&#8217;s called a trimmed nearest neighbors graph out of this, and then things are going to get interesting.&#8221;</p><p>&#8220;The first step,&#8221; I continued, &#8220;Is that I&#8217;m going to calculate the top 3-ish nearest neighbors for each customer here by first calculating the 97th percentile weight in each column.&#8221;</p><p>I added a row at the bottom of the sheet with the formula:</p><p>=PERCENTILE(B2:B101,0.97)</p><p>and dragged it across. The result looked this this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic5.png"><img
class="alignnone size-large wp-image-101" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic5-1024x516.png" alt="" width="642" height="323" /></a></p><p>I then created a new tab in the workbook called &#8217;3NN&#8217; where I pasted the same customer X customer matrix, except this time I filled the cells with the following formula:</p><p>=IF(EdgeWeights!B2&gt;=EdgeWeights!B$102,EdgeWeights!B2,&#8221;")</p><p>&#8220;So you&#8217;re only copying over those edges that are the most important?&#8221; asked Victor.</p><p>&#8220;That&#8217;s right,&#8221; I said, &#8220;And now we&#8217;re ready to get community detecting. For that, we need to leave Excel behind temporarily and move over to Gephi.&#8221;</p><p>I fired up a browser and downloaded a free copy of Gephi from <a
href="https://gephi.org/">https://gephi.org/</a>.</p><p>&#8220;What is this Gephi?&#8221; asked Victor.</p><p>&#8220;It&#8217;s a graphing software,&#8221; I said, &#8220;Basically it&#8217;s going to visualize this data for us, create pretty pictures and stuff.&#8221;</p><p>I installed the software, and saved the 3NN tab to a csv file.</p><p>&#8220;So you just load the data from the 3NN tab into Gephi?&#8221; asked Victor.</p><p>&#8220;Not quite,&#8221; I said, opening up a text editor on Victor&#8217;s machine, &#8220;I need to replace all the commas in the csv export with semi-colons first.&#8221;</p><p>I did the find-replace and saved off the file. Then I was ready to open it in Gephi. I navigated to File -&gt; Open and selected the csv file I&#8217;d created from the window. The import screen popped up, and I made sure Gephi knew that the graph I was working with was undirected and then pressed OK.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic6.jpg"><img
class="alignnone size-full wp-image-102" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic6.jpg" alt="" width="573" height="408" /></a></p><p>&#8220;Why did you select &#8216;undirected&#8217; from the graph type menu?&#8221; asked Victor.</p><p>&#8220;Because customer edges in this case go both ways. If you&#8217;re connected to me, because you like the deals that I like, then I&#8217;m connected to you for the same reason,&#8221; I said.</p><p>A jumble of points popped up on the screen:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic7.tiff.jpg"><img
class="alignnone size-large wp-image-103" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic7.tiff-1024x623.jpg" alt="" width="642" height="390" /></a></p><p>&#8220;So there&#8217;s the graph,&#8221; I said.</p><p>&#8220;It looks like shit,&#8221; said Victor with a sigh, &#8220;There&#8217;s nothing there.&#8221;</p><p>I laughed a little, &#8220;Just hang on. Don&#8217;t be impatient. We need to use a layout algorithm to pretty it up. I&#8217;m going to select &#8216;ForceAtlas 2&#8242;  from the layout menu over here on the bottom left and hit play.&#8221;</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic8.tiff.jpg"><img
class="alignnone size-full wp-image-104" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic8.tiff.jpg" alt="" width="313" height="446" /></a></p><p>Immediately the graph snapped into shape and I pressed stop on the algorithm.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic9.tiff.jpg"><img
class="alignnone size-full wp-image-105" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic9.tiff.jpg" alt="" width="249" height="222" /></a></p><p>&#8220;Now what do you think?&#8221; I asked him.</p><p>&#8220;Looks better,&#8221; he said, &#8220;So there are two communities?&#8221;</p><p>&#8220;Mmm,&#8221; I shrugged, &#8220;Let&#8217;s find out. I&#8217;m going to press the modularity button over on the right side of the screen first.&#8221;</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic10.png"><img
class="alignnone  wp-image-106" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic10.png" alt="" width="377" height="535" /></a></p><p>&#8220;That&#8217;s going to run a <a
href="http://en.wikipedia.org/wiki/Modularity_(networks)">modularity calculation</a> on the network,&#8221; I said and pressed the button. When the pop-up asked me whether or not to randomize the calculation, I clicked OK.</p><p>Instantaneously, a window with the results of the calculation popped up:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic11.tiff.jpg"><img
class="alignnone  wp-image-107" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic11.tiff.jpg" alt="" width="445" height="441" /></a></p><p>&#8220;It found 6 communities,&#8221; I said, &#8220;Let&#8217;s color them on the graph.&#8221;</p><p>I navigated to the partition section of the window in the top left corner, refreshed the drop down menu and picked modularity class. I hit the apply button and the six communities popped up in color on the graph.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic12.tiff.jpg"><img
class="alignnone size-full wp-image-108" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic12.tiff.jpg" alt="" width="727" height="432" /></a></p><p>&#8220;Ah ha,&#8221; said Victor, &#8220;So what do they mean?&#8221;</p><p>I smiled, &#8220;Well, Gephi can kinda suck for giving us that kind of insight sometimes. Depends on the graph and what you&#8217;re trying to do. But let&#8217;s dump these communities back into Excel and do some more analysis. I think we&#8217;re getting close to some insight here.&#8221;</p><p>I clicked on the Data Laboratory tab at the top of Gephi and exported each label (customer) with its assigned modularity class (community) to a csv, like so:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic13.png"><img
class="alignnone  wp-image-109" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic13.png" alt="" width="796" height="640" /></a></p><p>Next I opened this data back up in excel and copy-pasted it back into the original workbook we had open in a new tab called &#8216;Communities&#8217;.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic14.tiff.jpg"><img
class="alignnone size-full wp-image-110" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic14.tiff.jpg" alt="" width="189" height="222" /></a></p><p>I then inserted a new top row in the &#8216;Inventory&#8217; sheet and used a vlookup to assign the customer names there to their respective communities.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic16.png"><img
class="alignnone  wp-image-112" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic16.png" alt="" width="720" height="142" /></a></p><p>I created a new tab called &#8216;TopDealsByCommunity&#8217; and pasted all the deals (columns A:F) from the &#8216;Inventory&#8217; tab into the new sheet. I then added communities 0 thru 5 as headers for columns G thru L.</p><p>&#8220;What are you doing?&#8221; asked Victor.</p><p>&#8220;The way we can tell what each community means is to figure out which deals were the most important for each community,&#8221; I replied, &#8220;So what I want to do is for each deal here I want to go back to the &#8216;Inventory&#8217; tab and sum up all the ones for the customers in my group.&#8221;</p><p>I filled in the grid by dragging this formula around to all the cells:</p><p>=SUMIF(Inventory!$G$1:$DB$1,&#8221;=0&#8243;,Inventory!$G3:$DB3)</p><p>I added some conditional formatting to get a sheet like this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic17.tiff.jpg"><img
src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic17.tiff.jpg" alt="" width="828" height="185" /></a></p><p>&#8220;Now all I need to do is sort,&#8221; I said, &#8220;Let&#8217;s start with Community 0.&#8221;</p><p>I sorted, and Victor leaned in close to examine the values:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic19.tiff.jpg"><img
class="alignnone size-full wp-image-117" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic19.tiff.jpg" alt="" width="403" height="509" /></a></p><p>Victor began to laugh so loudly that a few folks in the coffee shop turned their heads.</p><p>&#8220;They are my dirt heads,&#8221; he said, pointing to the screen, &#8220;Look, they only order weed and shrooms. They&#8217;re my crunchy people.&#8221;</p><p>I nodded, &#8220;Absolutely. Let&#8217;s try Community 1.&#8221;</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic20.tiff.jpg"><img
class="alignnone size-full wp-image-118" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic20.tiff.jpg" alt="" width="395" height="517" /></a></p><p>&#8220;Hmmm,&#8221; said Victor as he studied the data, &#8220;They buy all sorts of products.&#8221;</p><p>He sat for a moment and then his eyebrows raised, &#8220;But look at the volumes. They only buy the large quantities.&#8221;</p><p>&#8220;Yeah,&#8221; I said, &#8220;And look at the ready fur use column. It&#8217;s always true.&#8221;</p><p>&#8220;Ah,&#8221; he said, &#8220;That makes sense. These are the folks who make money by moving large volume fast. They don&#8217;t want prep, and they don&#8217;t deal in piddly shit. They are my Walmarts.&#8221;</p><p>&#8220;Yeah,&#8221; I said, &#8220;Let&#8217;s check out number 5 here real quick and then I&#8217;ll leave the rest for you to interpret.&#8221;</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic23.tiff.jpg"><img
class="alignnone size-full wp-image-119" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/DataPic23.tiff.jpg" alt="" width="395" height="227" /></a></p><p>&#8220;My patriots,&#8221; Victor said smiling.</p><p>&#8220;Made in the U.S.A. baby,&#8221; I allowed myself a laugh.</p><p>Victor nodded, &#8220;My stateside producers do make some very good products.&#8221;</p><p>He looked over at me, &#8220;Thank you, Alex. This has been most insightful. Very cool stuff.&#8221;</p><p>He reached into his laptop bag and pushed a wad of bills into my hand. He clasped my hand in both of his shook it.</p><p>&#8220;You do not understand how refreshing it is to talk to someone like you. I like playing with data. It is a relief from the other demands of my position. Less messy,&#8221; he said.</p><p>He took a final swig from his cup of espresso and crushed the paper cup in his hand. The thought flitted across my mind momentarily that I had no desire to find out exactly what &#8216;messy&#8217; meant.</p><h2>Big Data-ish Tip</h2><p>Obviously, you&#8217;re going to want to move out of Excel for large datasets. A database can provide a sparse representation of this data, because you don&#8217;t actually need to save any records of when someone doesn&#8217;t take a deal. You only need the actions. Furthermore, the edge weight calculation is very parallelize-able / map-reduce-able.</p><p>If you had a big dataset that you prepped into a trimmed nearest neighbors graph, keep in mind that visualizing it in Gephi is just for fun. It&#8217;s not necessary for actual insight regardless of what the scads of presentations of tweets-spreading-as-visualized-in-Gephi might tell you (gag me). You just need to do the community detection piece. You can use Gephi for that or the libraries it uses. R and python both have a package called <a
href="http://igraph.wikidot.com/">igraph</a> that does this stuff too. Whatever you use, you just need to get community assignments out of your large dataset so that you can run things like the aggregate analysis over them to bubble up intelligence about each group.</p><p>On another note, in the problem above I treated all deals equally, but let&#8217;s say your problem was such that there were types of deals that everyone took, and they drowned out insight from less popular deals. You could alter the &#8216;Inventory&#8217; tab to have a 1/sqrt(number of people who took deal) in each cell instead of just a 1. That way, two people who took an unpopular deal have more in common than two people who took a popular one. When you&#8217;d do the aggregations / ranking out the other side of the community detection, similarly you&#8217;d want to use these modified points.</p><p>&nbsp;</p> ]]></content:encoded> <wfw:commentRss>http://analyticsmadeskeezy.com/2012/10/11/graphing-clustering-community-detection-wholesale-drug-deals-using-excel-and-gephi/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>Revenue Management for Meth Dealers in Flint</title><link>http://analyticsmadeskeezy.com/2012/10/08/revenue-management-for-meth-dealers-in-flint/</link> <comments>http://analyticsmadeskeezy.com/2012/10/08/revenue-management-for-meth-dealers-in-flint/#comments</comments> <pubDate>Mon, 08 Oct 2012 18:29:12 +0000</pubDate> <dc:creator>Alex</dc:creator> <category><![CDATA[Optimization]]></category> <category><![CDATA[Revenue Management]]></category> <category><![CDATA[Calculus]]></category> <category><![CDATA[Excel]]></category> <category><![CDATA[Price Ratio Model]]></category> <category><![CDATA[Pricing]]></category> <category><![CDATA[Revenue Optimization]]></category><guid
isPermaLink="false">http://analyticsmadeskeezy.com/?p=66</guid> <description><![CDATA[Note: Don&#8217;t forget to sign up for the Analytics Made Skeezy newsletter to receive future skeezy analytics tutorials. cheers, John When I left Victor that first time, my head was &#8230; <a
class="readmore" href="http://analyticsmadeskeezy.com/2012/10/08/revenue-management-for-meth-dealers-in-flint/">Continue Reading &#8594;</a>]]></description> <content:encoded><![CDATA[<p><em>Note: Don&#8217;t forget to sign up for the Analytics Made Skeezy newsletter to receive future skeezy analytics tutorials. cheers, John</em></p><p>When I left Victor that first time, my head was spinning. I had just done a drug dealer&#8217;s math homework. I felt the ethical weight of what I&#8217;d done for a split second and then I realized&#8230;if I hadn&#8217;t optimized his coke blending operations for him, he may have made a mistake and blended it himself outside his specs. And that could have been dangerous. So really I&#8217;m doing people a favor!</p><p>With that half-assed rationalizing of my nefarious deeds, I went to bed completely self-satisfied. I&#8217;d helped humanity and gotten free coke to boot! Well, pretty soon my stash dried up again, and I rang Andre to hook me up with some more.</p><p>&#8220;You wanna pay with your wallet or your mind?&#8221; he asked me over his cell.</p><p>Ugh, I thought, what a cheesy question.</p><p>&#8220;Like last time?&#8221; I asked.</p><p>&#8220;Yeuh, like that&#8221; he answered. He must have had all the windows down on the interstate, because his voice was coming over the line like he was in a wind tunnel.</p><p>An hour later I found myself once again getting dropped off not in Hapeville where I&#8217;d met Victor last time but in Buckhead outside the JW.</p><p>&#8220;Room 1504,&#8221; was all Andre said, and he sped off in his Escalade.</p><p>I made my way through the hotel lobby. I felt the eyes of the desk clerk on me and for a split second panicked that maybe I was walking into a sting or something. How many years does a guy get for helping a drug dealer out with the numbers, I wondered. But the desk clerk busied himself again with the computer in front of him, and I took the elevator up to the 15th floor. The JW was nicely decorated, although a little stuffy for my taste. The air in the hall was a bit humid, and its thickness seemed to play off my nervous breathing. I&#8217;d begun to sweat bullets before I even knocked on 1504.</p><p>I didn&#8217;t have to knock though. A man from the kitchen was dropping off a bottle of champagne, and when I poked my head through the door, I found Victor sitting in a bathrobe at a desk. He had a laptop open next to him, and when he reached over to take the bottle that had been left for him, he looked up and found me standing in front of him.</p><p>He gave me a quizzical look.</p><p>&#8220;The door was open,&#8221; I sputtered a little nervously as the staff sidled out of the room.</p><p>&#8220;I would wait and knock next time,&#8221; he said with a shrug, &#8220;It&#8217;s best not to surprise me. I&#8217;m jumpy at times.&#8221;</p><p>He stood and grabbed an arm chair that was pushed into the corner of the room. He dragged it over to the desk next to where he&#8217;d been sitting.</p><p>&#8220;Come join me here, and let&#8217;s talk this through,&#8221; he said, &#8220;Would you like something to drink?&#8221;</p><p>&#8220;Nah,&#8221; I said, &#8220;Long night last night. I wanna try to keep as much a clear head as possible.&#8221;</p><p>Victor smiled, &#8220;This is a good idea. What use are you to me all fuzzy?&#8221;</p><p>His toothy smile unnerved me. I didn&#8217;t like the thought of being useless to a guy like Victor. What had I gotten myself into?</p><p>&#8220;So what&#8217;s on the agenda for today?&#8221; I asked. I took a seat in the over-stuffed armchair next to Victor, and he turned his computer screen my way. He had a simple Excel spreadsheet open.</p><p>&#8220;Mr. Sheffield, I run a simple operation. I try to keep the number of non-contract employees on my books down to as few as possible,&#8221; he said, &#8220;You see, in the past, I&#8217;ve found a direct relationship between the number of employees on my books and the amount of heat coming round the corner.&#8221;</p><p>I nodded, &#8220;I can imagine that you&#8217;d want to keep the number of folks who know about all this to a minimum.&#8221;</p><p>&#8220;Yes, and so I&#8217;ve been pricing my products myself,&#8221; he said, &#8220;Sensitive things like finances, I don&#8217;t want many to know about them. But the time has come where I can&#8217;t eyeball each of my products in each city and set prices. It&#8217;s too hard.&#8221;</p><p>&#8220;Why not let your dealers set them?&#8221; I asked.</p><p>Victor smiled, &#8220;My dealers are not properly incentivized to return to me the maximum amount of revenue. Furthermore, the drug trade does not employ the most strategically minded individuals. Courageous, perhaps, but not intelligent.&#8221;</p><p>&#8220;So you want a quick and dirty way to set prices on each of your products in every market yourself?&#8221; I asked.</p><p>Victor gave me another cheshire grin, &#8220;Exactly, quick and dirty. And the data I have mostly looks like this. This is a set of monthly numbers for my meth dealers in Flint, Michigan.&#8221;</p><p>He pushed his computer screen a little my way.</p><p>I smiled, &#8220;I hear Flint&#8217;s nice this time of year.&#8221;</p><p>Victor nodded, &#8220;Flint is shit every time of year. That&#8217;s why I do so well there.&#8221;</p><p>I took a look at the spreadsheet. It was pretty straight forward.</p><p>&#8220;OK, so I&#8217;m seeing monthly demand, pricing, and revenue data,&#8221; I said, &#8220;And you&#8217;ve even got your competitor&#8217;s prices in there. Nice.&#8221;</p><p>&#8220;Meth heads shop around,&#8221; said Victor.</p><p>I laughed, but Victor gave me a serious look.</p><p>&#8220;I&#8217;m not joking. They&#8217;re broke as hell, and they&#8217;re more than willing to tell you when the guy down the street&#8217;s cheaper. Of course, they also care about quality, and like my coke, my meth is <em>at least </em>50% more pure than the competition,&#8221; Victor trailed off into thought briefly, &#8220;But up until now I&#8217;ve just been doing a straight 30% markup over cost. I know I can go higher than that.&#8221;</p><p>I nodded, &#8220;Yeah, so you&#8217;re bumping up against the fact that price is a strategic variable, but when you do cost-based pricing, you&#8217;re losing that strategic edge. Cost has nothing to do with willingness to pay.&#8221;</p><p>&#8220;Right,&#8221; said Victor, &#8220;That&#8217;s exactly what I wanted to say. So how do I fix that?&#8221;</p><p>&#8220;Quick and dirty?&#8221; I asked.</p><p>&#8220;Quick and dirty,&#8221; he repeated.</p><p>&#8220;Well, this is a revenue management problem, and since you&#8217;re already shopping competitors&#8217; rates, what we want to do is build a price optimization model that responds both to your own pricing as well as competitor pricing. It&#8217;s called a price ratio model,&#8221; I said.</p><p>Victor looked flummoxed, &#8220;I thought I said quick and dirty.&#8221;</p><p>I laughed, &#8220;Trust me. This is going to take about two minutes.&#8221;</p><p>&#8220;The first thing we want to do,&#8221; I continued, &#8220;is calculate a price ratio column in this sheet. Price ratio is just your own price divided by the average price of your competition.&#8221;</p><p>I added the column for him at the end of the table:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/MethDemandTablePR.jpg"><img
class="alignnone size-full wp-image-74" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/MethDemandTablePR.jpg" alt="" width="486" height="302" /></a></p><p>&#8220;Now what?&#8221; Victor asked.</p><p>&#8220;Well, let&#8217;s graph price ratio versus revenue just to get a sense of your customers&#8217; <a
href="http://en.wikipedia.org/wiki/Price_elasticity_of_demand">price elasticity</a>,&#8221; I said.</p><p>&#8220;Their what?&#8221; asked Victor.</p><p>&#8220;Price elasticity is just how demand changes with price changes,&#8221; I answered and pulled up a graph in Excel that looked like this:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Graph.jpg"><img
class="alignnone size-full wp-image-75" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Graph.jpg" alt="" width="667" height="468" /></a></p><p>We took a look at the graph together.</p><p>&#8220;Pretty good fit,&#8221; said Victor.</p><p>&#8220;Yeah, not bad for the real world,&#8221; I nodded, &#8220;And what we have is a fitted line that gives us the relationship between demand and price ratio.&#8221;</p><p>&#8220;So now we just need to pick the ratio that gives us the most demand?&#8221; asked Victor.</p><p>&#8220;Well, demand isn&#8217;t what you&#8217;re interested in but rather revenue,&#8221; I answered and broke out a sheet of paper.</p><p>On it I wrote these equations:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/F1.jpg"><img
class="alignnone size-full wp-image-76" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/F1.jpg" alt="" width="280" height="171" /></a></p><p>&#8220;Ugh,&#8221; said Victor with a sigh.</p><p>&#8220;Just stay with me,&#8221; I leaned forward and pointed to the graph in excel, &#8220;This function on the graph is the same as the first one I have, only I&#8217;ve put in our own price and the competitor&#8217;s average price as two separate values in a fraction p-o over p-c. You see that?&#8221;</p><p>&#8220;Yeah, so this is demand as a function of my price and my competitor&#8217;s price?&#8221; Victor asked.</p><p>&#8220;Yes, although for the moment, let&#8217;s assume that your competitor&#8217;s price is fixed, ok? Whatever p-c is, let&#8217;s assume it&#8217;s stuck there,&#8221; I answered, &#8220;That way all we need to worry about is moving our price around their price.&#8221;</p><p>Victor nodded.</p><p>&#8220;The second function here, all I&#8217;ve done is multiplied the demand function through with your own price. So now it&#8217;s a revenue function. And the first thing I notice about this revenue function is that it&#8217;s a <a
href="http://en.wikipedia.org/wiki/Quadratic_function">quadratic</a>,&#8221; I said, &#8220;In other words, it&#8217;s raised to the power of two.&#8221;</p><p>&#8220;Yeah, I see that,&#8221; said Victor.</p><p>&#8220;Furthermore, if I look at the acceleration of this function, its <a
href="http://en.wikipedia.org/wiki/Second_derivative">second derivative</a> in calculus, I can see that it&#8217;s negative,&#8221; I said and jotted down the function.</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Func2.jpg"><img
class="alignnone size-full wp-image-77" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Func2.jpg" alt="" width="188" height="94" /></a></p><p>&#8220;That means that the function has exactly one optimal price where revenue is maximized,&#8221; I said. I looked at Victor, and he seemed confused, so I drew a picture:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Graph2.jpg"><img
class="alignnone size-full wp-image-78" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Graph2.jpg" alt="" width="467" height="519" /></a></p><p>&#8220;The revenue is 0 when I give away stuff for free, then it goes up, then I get too expensive, and it goes back down,&#8221; he said.</p><p>&#8220;Exactly, and see how there&#8217;s only one optimum where the smiley face is? That&#8217;s the sweet spot we need to figure out,&#8221; I said.</p><p>&#8220;And how do we do that?&#8221; he asked.</p><p>&#8220;Well, if this were a baseball we were throwing straight up in the air, it&#8217;s the place where the speed of that baseball is zero. That&#8217;s the apex. That&#8217;s as high as the ball is gonna go,&#8221; I said, &#8220;To find that, we take the speed of our revenue function, also called the first derivative, and find out where it&#8217;s zero.&#8221;</p><p>I jotted down a couple more equations:</p><p><a
href="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Func3.jpg"><img
class="alignnone size-full wp-image-79" src="http://analyticsmadeskeezy.com/wp-content/uploads/2012/10/Func3.jpg" alt="" width="276" height="289" /></a></p><p>I spoke as I wrote, &#8220;So here I&#8217;ve taken the first derivative, which you&#8217;ll remember from high school calculus. Then I&#8217;ve set it equal to zero to find the apex. Moving terms across and dividing through, I get that my optimal price is simply 8% higher than that of my competitors.&#8221;</p><p>I looked over at Victor. He was smiling.</p><p>&#8220;8% higher eh?&#8221; he said.</p><p>&#8220;8%,&#8221; I nodded.</p><p>&#8220;Sounds like I need to brush up on taking derivatives,&#8221; he said with a shrug.</p><p>&#8220;Sure, but they&#8217;re not that hard, and there&#8217;s <a
href="http://www.webmath.com/diff.html">all sorts of sites on the internet that will take them for you</a>,&#8221; I said, &#8220;And the cool part is, you can just keep a running log of this data and readjust your pricing each month as price elasticity changes. When the economy bounces back, maybe your customers will be less price sensitive, and you can start gouging a little.&#8221;</p><p>&#8220;Don&#8217;t count on it,&#8221; Victor said, and he slapped me on the back really freaking hard. Reaching up, he grabbed the bottle of champagne and poured himself a glass. He turned around in his chair and reached into the inner breast pocket of a blazer that he&#8217;d draped across the chair back. From the blazer he pulled a wad cash held together with a rubber band and tossed it to me.</p><p>I caught it.</p><p>&#8220;What&#8217;s this?&#8221; I asked, gently weighing the wad in my hand.</p><p>&#8220;That&#8217;s five thousand dollars,&#8221; he said.</p><p>I was a bit dumbfounded, &#8220;For what?&#8221;</p><p>&#8220;For being so helpful. There&#8217;s a future for you here if you want it,&#8221; he said.</p><p>Later that night I lay in bed holding the wad of cash. I still hadn&#8217;t bothered to count it. Five grand for thirty minutes of work, I thought. That&#8217;s gotta be the easiest money I ever made. There was a voice in my head telling me to go ahead and get out of town. Quit helping Victor. Get clean and start fresh. But my excitement and adrenaline drowned the voice out. This was a sweet gig.</p><h2>Big Data-ish Rant</h2><p>Revenue Management is one of the original &#8216;Big Data&#8217; pursuits before big data was even a twinkle in your mama&#8217;s eye. But it&#8217;s been confined to enterprises like airlines, car rental companies, and hotels implementing crap like Teradata and Oracle. This field has not been democratized, so it&#8217;s kindof gone unnoticed in the big data conversation. But a system that takes company-wide hotel demand data, prices, competitor prices, yada yada, makes forecasts, and <a
href="http://www.smartplanet.com/blog/smart-takes/with-new-system-intercontinental-takes-the-guesswork-out-of-hotel-pricing/4056">optimizes future prices</a> based on inventory and demand isn&#8217;t more big data-y than some silly recommendation engine put out by some bland mobiley/socialy app, then I don&#8217;t know what is.</p> ]]></content:encoded> <wfw:commentRss>http://analyticsmadeskeezy.com/2012/10/08/revenue-management-for-meth-dealers-in-flint/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 5/19 queries in 0.016 seconds using disk: basic
Object Caching 1000/1088 objects using disk: basic

 Served from: analyticsmadeskeezy.com @ 2013-05-18 15:37:31 by W3 Total Cache -->