<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Werlindo Mangrobang on Medium]]></title>
        <description><![CDATA[Stories by Werlindo Mangrobang on Medium]]></description>
        <link>https://medium.com/@werlindo?source=rss-b4007413e9e6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*jxvuvc-fus5Km8JDXUXkeg.png</url>
            <title>Stories by Werlindo Mangrobang on Medium</title>
            <link>https://medium.com/@werlindo?source=rss-b4007413e9e6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:16:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@werlindo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What’s in the Black Box?]]></title>
            <link>https://medium.com/data-science/whats-in-the-black-box-8f36b262362e?source=rss-b4007413e9e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f36b262362e</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ice-plots]]></category>
            <category><![CDATA[partial-dependence-plots]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Werlindo Mangrobang]]></dc:creator>
            <pubDate>Wed, 05 Jun 2019 18:48:57 GMT</pubDate>
            <atom:updated>2019-06-10T14:41:10.508Z</atom:updated>
            <content:encoded><![CDATA[<h4>A distillation of <a href="http://web.stanford.edu/~hastie/Papers/pdp_zhao_final.pdf">”Causal Interpretations of Black-Box Models” by Zhao and Hastie</a>.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HZc1TTjEQahATR5K" /><figcaption>Photo by <a href="https://unsplash.com/@christianfregnan?utm_source=medium&amp;utm_medium=referral">Christian Fregnan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>You may be familiar with the authors of “Causal Interpretations of Black-Box Models” — Qingyuan Zhao and Trevor Hastie — particular Trevor Hastie. Perhaps <a href="http://www-bcf.usc.edu/~gareth/ISL/">this</a> rings a bell?:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*TAmLOA7nitK2NpgvVTBDhA.png" /><figcaption>James, Gareth, et al. <em>An Introduction to Statistical Learning: with Applications in R</em>. Springer, 2017.</figcaption></figure><p>It certainly did for me, as this text was one of my first entry points to learning data science. You may also remember Hastie’s name from reading the <a href="http://ww.web.stanford.edu/~hastie/Papers/Glmnet_Vignette.pdf">docs</a> of the glmnet package as you tried to figure out what the heck went wrong with your R code. Or that might have just been me.</p><p>It was because of this that I was curious to read Zhao and Hastie’s paper. The following is what I learned!</p><h4>Black Box</h4><p>Machine learning (ML) models, while having surpassed parametric models in predictive performance, have the downside of being considered to be black boxes by non-technical users; their relative opacity makes them hard to interpret. Consider the figure below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*NmF_JOMlOYZA1Kg2zynDhQ.png" /><figcaption>Zhao &amp; Hastie. 2018. Causal Interpretations of Black-Box Models. <a href="http://web.stanford.edu/~hastie/Papers/pdp_zhao_final.pdf">http://web.stanford.edu/~hastie/Papers/pdp_zhao_final.pdf</a></figcaption></figure><p>The ‘nature’ of the model is ‘boxed’ up, out of view of its users and customers. That’s important because a core question is: What <strong>features</strong> are <strong>important</strong> to the output(s) of the model? Figuring that out is hard when you can’t easily ‘see’ what’s happening in your model.</p><p>Zhao and Hastie talk about three ideas related to <strong>feature</strong> <strong>importance</strong> :</p><ol><li>We can treat the ML model as a function and ask which feature has the most impact on the output. Think <a href="https://www.theanalysisfactor.com/interpreting-regression-coefficients/">beta coefficients</a> of a regression model.</li><li>If we don’t have coefficients then perhaps we can<a href="https://christophm.github.io/interpretable-ml-book/feature-importance.html"> measure the ‘importance’ </a>of a feature by how much in ‘contributes’ to the model’s predictive accuracy.</li><li>The third is what Zhao and Hastie focus on, what they refer to as <strong>causality</strong>. They describe it as follows:</li></ol><blockquote>If we are able to make an intervention on Xj (change the value of Xj from a to b with the other variables fixed), how much will the value of Y change?</blockquote><p>The stated goal of their paper then is to:</p><blockquote>…explain when and how we can make causal interpretations after fitting black-box models.</blockquote><h4>Causality</h4><p>Zhao and Hastie use the example of <strong>grades</strong> and <strong>study hours</strong> to demonstrate the concept of causality. Let’s consider a formula where:</p><pre>Grade = [Some Constant Factor] <br>        + (Some Multipicative Factor)x(Hours Studied) <br>        + (Random Error)</pre><p>This makes intuitive sense to us: generally, the more hours you study, the better grades you get. In other words, one might argue that <strong>studying more hours</strong> <em>causes</em> <strong>higher grades</strong>.</p><p>What about the other way around? What if all we had were the grades students received? With some manipulation of the above, we could arrive at something like:</p><pre>Hours Studied = [Some Other Constant Factor] <br>                + (Some Other Multipicative Factor)x(Grades) <br>                + (Random Error)</pre><p>Does this mean that if a teacher gives a student an ‘A’ instead of a ‘B’ the student will study more hours? Of course not!</p><p>For instance, in the <strong>grades</strong> formula above, perhaps we added another feature,<strong> hours worked </strong>(at a job outside of school). If we broadly assume that the working hours are necessary for <a href="https://www.cnbc.com/2017/10/04/students-who-work-actually-get-better-grades-but-theres-a-catch.html">financial support</a>, then the working hours would likely have a causal effect on study hours, and not vice versa. Therefore, hours studied would be a causal descendent of hours worked.</p><h4>Partial Dependence Plots</h4><p>One tool that is useful for causal interpretation is the <a href="https://christophm.github.io/interpretable-ml-book/pdp.html">partial dependence plot</a> (PDP). They are used to glean a feature’s marginal impact on the model’s predicted outcomes. To massively simplify, we can think of it as just plotting the average predicted outcome (vertical axis) for each potential value of a feature (horizontal axis). And for a PDP to be useful for causal inference, the variable in question can’t have any other variables between it and the target variable be a causal descendent. Otherwise, interactions with any descendants can cloud interpretation.</p><p>For example, the following PDP shows that average predicted bike rentals generally go up with higher temperatures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0WSzxYalTWGagenfljZkmQ.png" /><figcaption>I too don’t like to bike when it’s humid, or windy. <a href="https://christophm.github.io/interpretable-ml-book/pdp.html">https://christophm.github.io/interpretable-ml-book/pdp.html</a></figcaption></figure><p>Let’s dive into another example using that old chestnut, the <a href="https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_boston.html">Boston housing dataset</a>. The dataset presents a target of median home value in Boston (MEDV) and several features, such as per capita crime rate by town (CRIM) and nitric oxides concentration (NOX, in parts per 10 million (pp10m)). It doesn’t take much domain expertise to inspect these and the <a href="https://www.kaggle.com/c/boston-housing">rest of the available features</a> to conclude that none could reasonably be a causal descendant of NOX. It’s <em>more likely</em> that NOX is affected by one or more of the other features — “the proportion of non-retail business acres per town” (INDUS), for one — than for NOX to affect INDUS. This assumption allows us to use a PDP for causal inference:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*x0Vv8LKYBXSpY2WSxkJS2A.png" /><figcaption>When nitric oxide concentration increased past 0.67 pp10m, Bostonians said <a href="https://en.wikipedia.org/wiki/Nitric_oxide"><strong>NO</strong></a> to higher house prices. Groan.</figcaption></figure><p>Note that this plot centers on the vertical axis to mean=0. What we may infer from the above is that median home prices seem to be insensitive to NOX levels until around 0.67 pp10m, at which median home levels drop by about $2,000.</p><h4>Individual Conditional Expectation plots</h4><p>But what if we are unsure of the causal direction of our features? One tool that can help is an <a href="https://christophm.github.io/interpretable-ml-book/ice.html">Individual Conditional Expectation</a> (ICE) plot. Instead of plotting the average prediction based on the value of a feature, it plots a line for each observation across possible values of the feature. Let’s dig into ICE plots by revisiting our NOX example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*biyiWoBbrNocUswowQwIpg.png" /><figcaption>Nice ICE, baby. Please stop.</figcaption></figure><p>This ICE plot seems to support what we saw with the PDP: the individual curves all appear to be similar in shape and direction, and like before, drop down in ‘level’ around NOX = 0.67.</p><p>But we already theorized earlier that NOX is a causal descendent of one or more of the other features in the dataset, so the ICE plot only serves to confirm what the PDP showed.</p><p>What if we explored a different feature, “weighted distances to five Boston employment centers” (DIS)? One may argue that a feature such as CRIM, could be a causal descendant of DIS. If we look at an ICE plot for DIS:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*T7Q8no5lxou_Oc4W3Y8l8A.png" /></figure><p>We find a mix of patterns! At higher levels of MEDV, there is a downward trend as DIS increases. However! At lower levels of MEDV, we observe some curves showing DIS having a brief positive effect on MEDV, up to around DIS=2 or so, and then becoming a negative effect.</p><p>The takeaway is that the ICE plot helps us identify that this feature is likely <strong>indirectly affecting the target</strong>, due to <strong>interactions</strong> with one or more other features.</p><p>For another application of ICE plots, let us consider an example using the ubiquitous “<a href="https://archive.ics.uci.edu/ml/datasets/auto+mpg">auto mpg</a>” dataset. The following plot shows that <strong>acceleration</strong> has some causal effect on <strong>MPG</strong>, but likely through interactions with other features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*T0oVb1f2oU15Y7n-BMLyig.png" /></figure><p>Notice the difference in the behavior of the lines at the top (somewhat increasing in <strong>MPG</strong>), middle (decreasing), and lower third (increasing again) of the plot!</p><p>If we look at the other features in the dataset, we find one for <strong>origin</strong>, which is the geographical origin of the auto. This feature is arguably a causal ancestor of <em>all</em> features — you need to have a place to build the car before you can build it! (A gross oversimplification, I know, but still). Being as such, it will likely have many interactions involved with its causal relationship with <strong>MPG</strong>.</p><p>Can ICE plots still be useful here, even though the feature is ‘far upstream’? You bet! Let’s start with looking at a trusty boxplot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*kBy_SjilxB0iMdntVum0Lg.png" /><figcaption>American cars guzzle gas. At least in this dataset.</figcaption></figure><p>This plot shows a very noticeable difference in <strong>MPG</strong> between autos from these three regions. But does this tell the whole story?</p><p>Consider the following two ICE plots. The first shows <strong>[US (1) or Europe(0)]</strong> versus <strong>MPG</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*vPyitBMCCxKFjiC-0kJ5QQ.png" /><figcaption>US (1) vs. Europe (0)</figcaption></figure><p>… and the second shows <strong>[Japan (1) or Europe(0)]</strong> versus <strong>MPG</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*fX3H83oVJAaWnttawsaCqg.png" /><figcaption>Japan (1) vs. Europe (0)</figcaption></figure><p>While at first, via the boxplot, it seemed that there is a significant difference in <strong>MPG</strong> attributable to <strong>origin</strong>, the ICE plots show that the pure impact might be a little smaller when considering interactions with other features: the slope for the majority of these lines are flatter than the boxplot would have us imagine.</p><h4>Boxing It Up</h4><p>When dealing with so-called black-box algorithms, we need to use smart methods to interpret the results. One point of view to do that is through inferring causality. Some tools can help with that:</p><ul><li>Partial Dependence Plots (PDPs)</li><li>Individual Conditional Expectation Plots (ICE Plots)</li><li>Your or your team’s own domain knowledge! While we increasingly have many fancy tools to employ in the name of data science, it can’t replace hard-earned domain knowledge and well-honed critical thinking skills.</li></ul><p>Thanks for reading!</p><p>Work files <a href="https://github.com/MangrobanGit/blog_black_box">here</a>.</p><p><em>Please feel free to reach out! | </em><a href="https://www.linkedin.com/in/werlindo/">LinkedIn</a> | <a href="https://github.com/MangrobanGit">GitHub</a></p><p><strong>Sources:</strong></p><p>Breiman. <em>Statistical modeling: The two cultures.</em> Statistical Science, 16(3):199– 231, 2001b.</p><p>James, Gareth, et al. <em>An Introduction to Statistical Learning: with Applications in R</em>. Springer, 2017.</p><p>Molnar. <em>Interpretable Machine Learning.</em> <a href="https://christophm.github.io/interpretable-ml-book/">https://christophm.github.io/interpretable-ml-book</a> Accessed June 2019.</p><p>Pearl, 1993. <em>Graphical models, causality and intervention</em>. Statistical Science, 8(3):266–269.</p><p>Zhao &amp; Hastie. 2018. <em>Causal Interpretations of Black-Box Models</em>. <a href="http://web.stanford.edu/~hastie/Papers/pdp_zhao_final.pdf">http://web.stanford.edu/~hastie/Papers/pdp_zhao_final.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f36b262362e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/whats-in-the-black-box-8f36b262362e">What’s in the Black Box?</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prophet-able Forecasting]]></title>
            <link>https://medium.com/data-science/prophet-able-forecasting-5abf837ace3b?source=rss-b4007413e9e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5abf837ace3b</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[prophet]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[time-series-forecasting]]></category>
            <dc:creator><![CDATA[Werlindo Mangrobang]]></dc:creator>
            <pubDate>Thu, 16 May 2019 17:56:50 GMT</pubDate>
            <atom:updated>2019-05-16T23:57:40.796Z</atom:updated>
            <content:encoded><![CDATA[<h4>Getting started with Prophet, Facebook&#39;s open source time series forecasting library (in Python)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kiLhwgfqplmsa9QgUfXjKQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@isaacmsmith">Isaac Smith</a> on <a href="https://unsplash.com/">Unsplash</a></figcaption></figure><p>If you google “<em>time-series forecasting</em>”, most of the <a href="https://www.google.com/search?q=time+series+forecasting&amp;rlz=1C5CHFA_enUS805US805&amp;oq=time+&amp;aqs=chrome.0.69i59l2j69i57j69i60l3.869j0j1&amp;sourceid=chrome&amp;ie=UTF-8">first search results</a> you’ll get will involve <a href="https://en.wikipedia.org/wiki/Autoregressive_integrated_moving_average">autoregressive integrated moving average</a> modeling (ARIMA) or <a href="https://machinelearningmastery.com/exponential-smoothing-for-time-series-forecasting-in-python/">exponential smoothing</a> (ETS). And with good reason! There are popular options available for performing applying these time-series forecasting methods, both in R and Python. One of the first forecasting tools I started playing around with are the ARIMA and ETS models in the forecast package in R, led by the influential <a href="https://otexts.com/fpp2/">Rob Hyndman</a>.</p><p>One of the most gee-whiz options in <a href="http://pkg.robjhyndman.com/forecast/">forecast</a> is to use <a href="https://www.rdocumentation.org/packages/forecast/versions/8.7/topics/auto.arima">auto.arima</a>. The name says it all; it will &#39;automatically&#39; determine a best-fit ARIMA model, based on the selected information criterion (<a href="http://www.koenbro.com/information-criteria-aic-aicc-bic/">AIC, BIC, or AICc</a>). Time-series forecasting made easy!</p><p>These days, though, I prefer to use Python. And with another quick google search, I spot a <a href="https://www.alkaline-ml.com/pmdarima/">potential Python analog</a>. But for <strong>this</strong> post, I’d like to spend our time getting to know another forecasting Python library: Prophet.</p><h4>What is Prophet?</h4><p>Introduced in 2017, Prophet is a forecasting library developed by Facebook, with implementations in R and Python. It was developed with two goals in mind: First, to create scalable, high-quality forecasts for the business, and second, to have a rigorous methodology behind the scenes, but have its parameter levers be intuitive enough for traditional business analysts to adjust.</p><p>For this post we will be doing a <em>brisk</em> stream-of-consciousness-esque <strong>quick-start tutorial:</strong></p><ul><li>Installing in Python</li><li>Setting up the data</li><li>Fitting the model and predicting</li><li>Inspecting the results</li></ul><p>Let’s do this!</p><h4>1. Installing in Python</h4><p>If some of the following is a little terse for your taste, I simply followed directions on Prophet’s <a href="https://facebook.github.io/prophet/docs/installation.html">installation guide</a>. Also, I’m on a Mac, so YMMV with the following if you’re on Windows, etc.</p><p>I went to the Installation page on the project’s <a href="https://facebook.github.io/prophet/docs/installation.html">github.io site</a> and followed the directions for Python. As mentioned there, the library has a major dependency on pystan. On my first attempt, I actually <em>missed</em> the part where it says to pip install pystan <strong>first</strong> before pip installing fbprophet (the actual name of the Python library). Of course, I DID THE EXACT OPPOSITE, and things were NOT HAPPY.</p><p>BUT:</p><p>I’m also on the Anaconda distribution of Python, so I was able to eventually get everything working by simply following the <strong>Anaconda instructions:</strong></p><p>In terminal:</p><p>conda install gcc</p><p>…and then following any prompts accordingly.</p><p>Once that’s done, do the following:<br>install -c conda-forge fbprophet</p><p>Phew! That was close. I was afraid this post was going to end right here.</p><h4>2. Setting up the data</h4><p>The project site also provides a very clear <a href="https://facebook.github.io/prophet/docs/quick_start.html#python-api">Quick Start</a> that I ran through to sniff-test that everything worked as intended. I’ll leave it up to you, dear reader, to do the same, and highly encourage it. One can never get <a href="https://en.wikipedia.org/wiki/Outliers_(book)">enough reps</a>. What I <strong>will</strong> walk through, though, is another dataset of my choosing, to start getting used to the API.</p><h4>Case Study: Looking at bike share trips</h4><p>For this first dataset, we are looking at a dataset on bike share trips in Los Angeles. I pulled down a .csv from Kaggle. Don&#39;t tell anyone, but I believe I&#39;m the first person to have ever thought of that. Just kidding! Seriously though, I would have loved to have scraped something, but ran out of time. So Kaggle it is.</p><p>You can find the data <a href="https://www.kaggle.com/cityofLA/los-angeles-metro-bike-share-trip-data/downloads/los-angeles-metro-bike-share-trip-data.zip/26">here</a>.</p><p>If you have the <a href="https://github.com/Kaggle/kaggle-api">Kaggle API</a> installed you can just download directly to your folder of choice by copying the API command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*CQNfbp5vkTgwRJ2SKxSkYA.png" /><figcaption>Anyone know how to resize this?</figcaption></figure><p>and then pasting into terminal and running it, like so:<br>kaggle datasets download -d cityofLA/los-angeles-metro-bike-share-trip-data</p><p>Another YMMV-type blocker: I then had issues with the downloaded file’s permissions when I tried to unzip it. But I resolved it by:<br>chmod 600 los-angeles-metro-bike-share-trip-data.zip</p><p>..which gave me full <a href="http://www.thinkplexx.com/learn/article/unix/command/chmod-permissions-flags-explained-600-0600-700-777-100-etc">read/write permissions</a> on the file. Then I was able to unzip it:<br>unzip los-angeles-metro-bike-share-trip-data.zip</p><p>OK! Let’s set up the dataframe for running through the Prophet object. Note that the model is expecting very specific column names and types; to quote:</p><blockquote>The input to Prophet is always a dataframe with two columns: <em>ds</em> and <em>y</em>. The <em>ds</em> (datestamp) column should be of a format expected by Pandas, ideally YYYY-MM-DD for a date or YYYY-MM-DD HH:MM:SS for a timestamp. The <em>y</em> column must be numeric, and represents the measurement we wish to forecast.</blockquote><p>Full <a href="https://github.com/MangrobanGit/blog_tutorial_1/blob/master/blog_tutorial.ipynb">Jupyter notebook</a> of all the code is available at <a href="https://github.com/MangrobanGit/blog_tutorial_1">this GitHub repository</a> (complete with all my false starts!) but a cleaned up version is as follows:</p><pre>import pandas as pd          # Dataframes. <br>import plotly_express as px  # Plotting.</pre><pre># Get dataset<br>bikes = pd.read_csv(&#39;./data/metro-bike-share-trip-data.csv&#39;)</pre><pre># Start time is string, convert to data<br>bikes[&#39;ds&#39;] = pd.to_datetime(<br>                 bikes[&#39;Start Time&#39;].apply(lambda st : st[:10])<br>                                           , format=&#39;%Y-%m-%d&#39;)</pre><pre># Aggregate by trip start date<br>trips = bikes.groupby([&#39;ds&#39;]).agg(<br>                                 {&#39;Trip ID&#39;: &#39;count&#39;}).reset_index()</pre><pre># Rename columns<br>trips.columns = [&#39;ds&#39;, &#39;y&#39;] # Column names required by fbprophet API</pre><pre># Plot: reasonability check <br>px.scatter(trips<br>          ,x=&#39;ds&#39;<br>          ,y=&#39;y&#39;<br>          ,title=&#39;LA Daily Bike Share Trips - Jul 16 to Apr 17&#39;<br>          ,labels={&#39;y&#39;:&#39;Trips&#39;,&#39;ds&#39;:&#39;Day&#39;})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*zyPfjnVa3YsSJ6x8ebGY1w.gif" /><figcaption>Is that Plotly Express’ music I hear? <a href="https://towardsdatascience.com/plotly-express-yourself-98366e35ad0f">Shameless, shameless plug</a>.</figcaption></figure><h4>3. Fitting the model and predicting</h4><p>Next, we’ll run through an example of running a forecast:</p><ul><li>Fitting the model</li><li>Predicting on our model</li></ul><p>First, let’s instantiate our model and fit it on our dataset:</p><pre>from fbprophet import Prophet     #Importing here for visibility</pre><pre># Create Prophet object and fit<br>m_bikes = Prophet(yearly_seasonality=True<br>                 , weekly_seasonality=True)               #All defaults<br>m_bikes.fit(trips)</pre><p>The object Prophet has many parameters that can be set to tune the model. For example, seasonality settings such as daily_seasonality, weekly_seasonality, and yearly_seasonality are just some of the options that can be tuned. For example, I think there might be some weekly and/or yearly patterns for bike-share rentals. For fun, let’s see what happens if we set weekly_seasonality and yearly_seasonalityto True.</p><p>Next, we can then perform predictions using the model. the Prophet object has a handy method calledmake_future_dataframe that can create a dataframe with a specified number of future dates, relative to the training data (days is the default periods). For example, below we tack on 60 days after our training data’s last day.</p><pre># Create dataframe with appended future dates<br>future = m_bikes.make_future_dataframe(periods=60) #Days is default<br>future.tail()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/104/1*G7cfCqs0V7Q48s-xPo3FLw.png" /></figure><p>Once, that dataframe is set up, we can then run predictions on that ‘test’ set:</p><pre># Forecast on future dates <br>forecast = m_bikes.predict(future)</pre><pre># Look at prediction and prediction interval<br>forecast[[&#39;ds&#39;, &#39;yhat&#39;, &#39;yhat_lower&#39;, &#39;yhat_upper&#39;]].tail()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*I8UgTASmg2RtnBhnUXOt1A.png" /></figure><h4>4. Inspecting the results</h4><p>We already got a sneak preview into the predictions by looking at the tail of the forecast dataframe we created. Let’s visualize it though to get the big picture.</p><p>It just so happens that our Prophet object also includes a plot method to do just that! Here’s the plot of the fit/forecast (line (<em>y_hat</em>) and shaded area (<em>prediction interval</em>)) versus the actuals (scatter):</p><pre># Plot the forecast vs actuals<br>m_bikes.plot(forecast)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*aqiQcO1PDDBCaL6Ruzmzqw.png" /><figcaption>Not bad. Could potentially use some more data cleaning (outliers?) and parameter tuning.</figcaption></figure><p>In addition, there are plots for the forecast components as well! For example, since we explicitly set weekly_seasonality and yearly_seasonalityto True, there will be component plots specifically for them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*MScCTh_Bx8eeWxFHDEFWAA.png" /><figcaption>Wooh! There’s nothin’ like summer in the city.</figcaption></figure><p>We could definitely use more historical data, but if we take these plots at face value, it appears there is a late summer spike in trips, and then it gradually dips over the fall. Furthermore, during the week, peak riding seemed to happen mid to late weekdays. That might not completely pass the sniff-test of my anecdotal observations if these were Seattle bike-shares, but hey, L.A. is probably a completely different market. The point is though we were able to create some decent forecasts in a short amount of time!</p><h4>So much more…</h4><p>If we had more time to dive in more we could start looking at the aforementioned parameters to further tune the forecasts. These include not only seasonality for different periods, but specific holiday effects, providing specific changepoints for trend (e.g.you don’t have a perfectly linear baseline trend, such as in the example above), accounting for saturation points, and more. Again, details can be found in the <a href="https://facebook.github.io/prophet/docs/installation.html">documentation</a>, and I would highly encourage reading the <a href="https://peerj.com/preprints/3190/">white paper</a> to gain a deeper understanding of the underlying methodologies.</p><p>That’s all we have time for, I hope this has been useful. Thanks for reading!</p><p>Work files <a href="https://github.com/MangrobanGit/blog_tutorial_1">here</a>.</p><p><em>Please feel free to reach out! | </em><a href="https://www.linkedin.com/in/werlindo/">LinkedIn</a> | <a href="https://github.com/MangrobanGit">GitHub</a></p><p><strong>Sources:</strong></p><p><a href="https://facebook.github.io/prophet/">https://facebook.github.io/prophet/</a></p><p>Taylor SJ, Letham B. 2017. Forecasting at scale. <em>PeerJ Preprints</em> 5:e3190v2 <a href="https://doi.org/10.7287/peerj.preprints.3190v2">https://doi.org/10.7287/peerj.preprints.3190v2</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5abf837ace3b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/prophet-able-forecasting-5abf837ace3b">Prophet-able Forecasting</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Plotly Express Yourself]]></title>
            <link>https://medium.com/data-science/plotly-express-yourself-98366e35ad0f?source=rss-b4007413e9e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/98366e35ad0f</guid>
            <category><![CDATA[plotly]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Werlindo Mangrobang]]></dc:creator>
            <pubDate>Mon, 13 May 2019 04:30:26 GMT</pubDate>
            <atom:updated>2019-05-21T05:52:05.305Z</atom:updated>
            <content:encoded><![CDATA[<h4>A quick stroll through basic visualizations using Plotly Express, in Python.</h4><p>I’ve recently discovered <a href="https://medium.com/@plotlygraphs/introducing-plotly-express-808df010143d">Plotly Express</a>, and I am very excited to add it to my toolbox, and for it’s potential.</p><p>For those who are unfamiliar with Plotly (or even more confused why there would be a <em>need</em> for an <strong>express</strong> version), let’s get you up to speed.</p><p>Plotly is a <a href="https://plot.ly/graphing-libraries/">visualization library</a> available on a number of platforms, including Java, Python, and R (where my own past personal, albeit limited experience with Plotly lies) as well as through Plotly’s (the organization) <a href="https://plot.ly/feed/#/">commercial product</a>. Plotly is awesome because you can create highly interactive visualizations, as opposed to static visualizations via matplotlib or seaborn (matplotlib’s cooler sibling). For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*RACV7j01g2RBZGO36tuZpw.gif" /><figcaption><a href="https://mangrobang.shinyapps.io/Project_Draft_AV/">https://mangrobang.shinyapps.io/Project_Draft_AV/</a></figcaption></figure><p>But the downside (at least for me) was that getting anything done in Plotly always felt like <strong>a lot</strong> of lines of code. For example, the code for the preceding plot looks like this (some data set up not included for brevity):</p><pre>p &lt;- plot_ly(draft<br>                 , x = ~Rnd<br>                 , y = ~First4AV<br>                 , type = &quot;scatter&quot;<br>                 , mode = &quot;markers&quot;</pre><pre>, color = ~draft$Position.Standard<br>                 , colors = brewer.pal(8, &quot;Spectral&quot;)<br>                 , marker = list(size = 10, opacity = .25 )<br>    ) %&gt;%<br>      # Plot the average for each draft round<br>      layout(title = &quot;Accumulated AV over First 4 Years of Player Careers by Draft Round, Yrs 1994-2012&quot;) %&gt;%<br>      layout(xaxis = xx, yaxis = yy) %&gt;%<br>      add_trace( data=avg.4.AV, x = ~Rnd, y = ~avg.F4.AV, type = &quot;scatter&quot;<br>              , name = &quot;Avg 4-Yr AV&quot;, color=I(&quot;lightpink&quot;), mode=&quot;lines&quot; ) %&gt;%<br>      # Plot the predicted value<br>      add_trace(x = input.rnd, y = mod.draft.pred(), type = &quot;scatter&quot;<br>              , mode = &quot;markers&quot;<br>              , marker = list(symbol=&#39;x&#39;,size=15, color=&#39;black&#39;)) %&gt;%<br>      layout(annotations = jj) %&gt;%<br>      layout(annotations = pr)</pre><pre>p</pre><p>Note that the above is written in R, not Python, because that’s where most of my past experience with Plotly has been. But what I’ve seen and used in Python seems similar in syntactical complexity.</p><p>What Plotly Express does, is create an even higher-level wrapper around the base Plotly code, so the syntax is simpler. To me, that means easier to learn and easier to build coding muscle memory. Less copying and pasting code from old projects or Stack Overflow!</p><p>To put it through the paces, I thought it would be useful to run through some standard exploration plots. When we’re done, we’ll hopefully end up with a handy cheat sheet for Plotly Express!</p><h4>Prep! (and prefacing thoughts)</h4><ol><li>For our test data I found this <a href="https://www.kaggle.com/magshimimsummercamp/superheroes-info-and-stats#superheroes_info.csv">fun dataset</a> on Kaggle on superheroes (hey, I just saw Avengers:Endgame!):</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vVi3nUMpi-Uf3iY84V4_AA.png" /><figcaption>Multiple Spider-Men and Captains America? Yes, the multiverse exists!</figcaption></figure><p>2. Code for getting and scrubbing the data, as well as the snippets below can be found in this <a href="https://github.com/MangrobanGit/blog_px/blob/master/blog_2.ipynb">jupyter notebook here</a>.</p><p>3. If you haven’t installed it or imported yet:</p><pre># Install<br>pip install plotly_express</pre><pre># Import<br>import plotly_express as px</pre><p>4. We’ll assume you have some conceptual familiarity with the plots shown below, so we won’t be deep-diving into the pros and cons of each. But we’ll also add some thoughts and references when available.</p><p>5. The look of the following plots vary wildly because I was curious as to the look and feel of the various <a href="https://medium.com/@plotlygraphs/introducing-plotly-py-theming-b644109ac9c7">built-in templates</a> (i.e. themes). So, apologies if that’s annoying, but like I mentioned, I’m trying to flex all of Plotly Express’ muscles.</p><h4>Plotting Univariate Data</h4><p>Let’s cover a couple of classic ways to perform univariate exploration of <strong>continuous</strong> variables: Histograms and Boxplots.</p><p><strong>Histogram (Univariate)</strong>:</p><pre>px.histogram(data_frame=heroes_clean<br>     , x=&quot;Strength&quot;<br>     , title=&quot;Strength Distribution : Count of Heroes&quot;<br>     , template=&#39;plotly&#39;<br>     )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*VZfYFVz8perywrKGvpg7qw.gif" /><figcaption>Not the prettiest histogram.</figcaption></figure><p>You can read more about how cool histograms are <a href="https://medium.com/@johnnaujoks/extreme-makeover-histogram-edition-fdb824d7e58">here</a>.</p><p><strong>Boxplot (Univariate):</strong></p><p>…And the boxplot. So elegant in its simplicity.</p><pre>px.box(data_frame=heroes<br>    , y=&quot;Speed&quot;<br>    , title=&quot;Distribution of Heroes&#39; Speed Ratings&quot;<br>    , template=&#39;presentation&#39;<br>    )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*owNlBjH6A8DxL8aGpwZXBA.gif" /><figcaption>Boxplot.</figcaption></figure><p>More can be found on boxplots <a href="https://medium.com/@hussein.sajid7/data-visualization-box-plot-989b69967834?sk=97e0c9969b829920eb6b3d6fdb6db411">here</a>, <a href="https://dev.to/annalara/deconstructing-the-box-and-whisker-plot-11f3">here</a>, and <a href="https://medium.com/@larrychewy/the-box-and-the-bees-7d0b6ded65db">here</a>. But if you find boxplots to be a bit <em>square</em>, perhaps a violin plot will do?</p><p><strong>Violin Plot</strong></p><pre>px.violin(data_frame=heroes<br>          , y=&quot;Speed&quot;<br>          , box=True<br>          , title=&quot;Distribution of Heroes&#39; Speed Ratings&quot;<br>          , template=&#39;presentation&#39;<br>         )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*EjWgpjZ3CPosoUU7SbGOHg.gif" /><figcaption>More of an upright bass plot.</figcaption></figure><p><a href="https://en.wikipedia.org/wiki/Violin_plot">Violin plots</a> are becoming increasingly popular. I like to think of them as boxplot’s cooler, better-looking sibling. Ouch.</p><p>But what if the variable or feature you want to explore is <strong>categorical</strong>, not continuous? In this case, you’ll probably want to start with a bar chart to get a feel for counts of values.</p><p><strong>Bar Chart (Univariate)</strong></p><pre>px.bar(data_frame=heroes_publisher<br>       , x=&#39;publisher&#39;<br>       , y=&#39;counts&#39;<br>       , template=&#39;plotly_white&#39;<br>       , title=&#39;Count of Heroes by Publisher&#39;<br>      )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*SU3VA5w6c7FQxULrePzi0A.gif" /><figcaption>Remember when NBC’s Heroes was cool?</figcaption></figure><p>Here’s a quick primer on <a href="https://medium.com/@Infogram/the-dos-and-donts-of-bar-charts-bd2df09e5cd1">bar charts</a>.</p><p>Univariate analysis is all well and good, but really, we usually want to compare variables to other variables to try to tease out interesting relationships, so we can build models. So let’s keep building our plotly-express superpowers on some examples of bivariate techniques.</p><h4>Plotting Bivariate Data</h4><p>Let’s start with comparing <strong>continuous</strong> variables <strong>versus continuous</strong> variables.</p><p><strong>Scatter Plot</strong></p><pre>px.scatter(data_frame=heroes<br>           , x=&quot;Strength&quot;<br>           , y=&quot;Intelligence&quot;<br>           , trendline=&#39;ols&#39;<br>           , title=&#39;Heroes Comparison: Strength vs Intelligence&#39;<br>           , hover_name=&#39;Name&#39;<br>           , template=&#39;plotly_dark&#39;<br>          )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*zMJ7vnB8F_UXx-M0ZXkx_g.gif" /><figcaption>If a theoretical character has 0 Strength, they at least rate 57 in Intelligence. Hmm.</figcaption></figure><p><a href="https://medium.com/@mia.iseman/in-praise-of-scatterplots-and-bubble-charts-e1f39548ee84">Scatter plots</a> are the tried and true way of comparing two continuous (numeric) variables. It’s a great way to quickly assess whether a relationship exists between the two variables.</p><p>In the example above, we further give ourselves a helping hand at spotting a relationship by adding a <a href="https://en.wikipedia.org/wiki/Ordinary_least_squares">trendline</a>. It appears that there is a weak positive correlation between Strength and Intelligence.</p><p><strong>Line Plot</strong></p><pre>px.line(data_frame=heroes_first_appear_year<br>        ,x=&#39;Year&#39;<br>        ,y=&#39;Num_Heroes&#39;<br>        ,template=&#39;ggplot2&#39;<br>        ,title=&quot;Number of Heroes by Year of First Appearance&quot;<br>        ,labels={&quot;Num_Heroes&quot;:&quot;Number of Heroes&quot;}<br>       )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ZtMFuL9T13sla35MsB0X-A.gif" /><figcaption>The early ’60s was a big turning point in comic superheroes.</figcaption></figure><p>A special case of continuous versus continuous comparison are <strong>time series</strong>. The classic way to do this is with a <a href="https://medium.com/@patrickbfuller/line-plot-7b4068a3a9fc">line plot</a>. Almost always the date/time variable will be along the x-axis while the other continuous variable is measured along the y-axis. And now you can see how it changed over time!</p><p>What if we want to <strong>compare categorical versus continuous</strong> variables? Well, it turns out that we can just use univariate techniques, but just “repeat” them! One of my favorite ways is using a stacked histogram. We can make a histogram for our continuous variable, for each value of a categorical variable, and then just stack them!</p><p>For example, let’s revisit our histogram from prior, on Strength, but this time we&#39;d like to see the data separated out by Gender.</p><p><strong>Stacked Histogram</strong></p><pre>px.histogram(data_frame=heroes[~heroes.Gender.isna()]<br>             , x=&quot;Strength&quot;<br>             , color=&#39;Gender&#39;<br>             , labels={&#39;count&#39;:&#39;Count of Heroes&#39;}<br>             , title=&quot;Strength Distribution : Count of Heroes&quot;<br>             , template=&#39;plotly&#39;<br>            )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*VDfpxIs_xpYXkg--INdsVg.gif" /><figcaption>I’m guessing the big bar for 10–19 is non-superpowered characters, like Batman. Nerd.</figcaption></figure><p>Maybe the stacks are confusing to you and just want to see the bars grouped by bins:</p><p><strong>Stacked Histogram (grouped bins)</strong></p><pre>px.histogram(data_frame=heroes[~heroes.Gender.isna()]<br>             , x=&quot;Strength&quot;<br>             , color=&#39;Gender&#39;<br>             , barmode = &#39;group&#39;<br>             , labels={&#39;count&#39;:&#39;Count of Heroes&#39;}<br>             , title=&quot;Strength Distribution : Count of Heroes&quot;<br>             , template=&#39;plotly&#39;<br>            )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*If6o48ZZ36IsIlfEA1ZIPQ.gif" /></figure><p>…Or if either of those looks were too visually busy for you, then maybe you just want a plot for each category value. You’ll see this sometimes called faceting (or at least that’s what I’ve come to call it).</p><p><strong>Faceted Histograms</strong></p><pre>px.histogram(data_frame=heroes[~heroes.Gender.isna()]<br>             , x=&quot;Strength&quot;<br>             , color=&#39;Gender&#39;<br>             , facet_row=&#39;Gender&#39;<br>             , labels={&#39;count&#39;:&#39;Count of Heroes&#39;}<br>             , title=&quot;Strength Distribution&quot;<br>             , template=&#39;plotly&#39;<br>             )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*djbefzmm7pjAW20eu1mUfg.gif" /></figure><p>Wow, I’m histogrammed out. Let’s look at applying the same faceting/splitting concept to box plots.</p><p><strong>Split Box Plot</strong></p><pre>px.box(data_frame=heroes[~heroes.Gender.isna()]<br>        , y=&quot;Speed&quot;<br>        , color=&quot;Gender&quot;<br>        , title=&quot;Distribution of Heroes&#39; Speed Ratings&quot;<br>        , template=&#39;presentation&#39;<br>        )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*SJ5PSLN82ddKehzWDR5RHQ.gif" /></figure><p>And whatever box plots can do, violin plots can as well!</p><p><strong>Split Violin Plot</strong></p><pre>px.violin(heroes[~heroes.Gender.isna()]<br>        , y=&quot;Speed&quot;<br>        , color=&quot;Gender&quot;<br>        , box=True<br>        , title=&quot;Distribution of Heroes&#39; Speed Ratings&quot;<br>        , template=&#39;presentation&#39;<br>       )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*lRgV1RvJMvP363CNn6_ljg.gif" /><figcaption>‘Agender’ characters have higher median (and likely mean) Speed.</figcaption></figure><p>So what about if you want to just compare <strong>categorical versus categorical </strong>values? If that’s the case you usually want to look at relative counts. So stacked bars are a good way to go:</p><p><strong>Stacked Bar Chart (Categorical vs Categorical)</strong></p><pre>px.histogram(data_frame=heroes<br>             ,x=&quot;Publisher&quot;<br>             ,y=&quot;Name&quot;<br>             ,color=&quot;Alignment&quot;<br>             ,histfunc=&quot;count&quot;<br>             ,title=&quot;Distribution of Heroes, by Publisher | Good-Bad-Neutral&quot;<br>             ,labels={&#39;Name&#39;:&#39;Characters&#39;}<br>             ,template=&#39;plotly_white&#39;<br>            )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*hXO4hKJVxjfQs_0dTqBMfw.gif" /><figcaption>Marvel and DC Comics are pretty top heavy with ‘Good’ characters.</figcaption></figure><p>Digression: It turns out that stacked bar charts are way easier using .histogram since it gives access to histfunc, which allows you to apply a function to the histogram. This saves steps from having to aggregate first (which you may have noticed was done for the bar chart above).</p><h4>Plotting Three or More Variables</h4><p>We may be sensing a pattern here. We can turn any univariate visualization into a bivariate one (or more) by using another visual element, such as color; or by faceting/splitting along category values.</p><p>Let’s explore adding a <strong>third variable</strong>. A common technique is to add a <strong>categorical variable</strong> to a scatter plot using <strong>color</strong>.</p><p><strong>Colored Scatter Plot</strong></p><pre>px.scatter(data_frame=heroes[~heroes.Gender.isna()]<br>           , x=&quot;Strength&quot;<br>           , y=&quot;Intelligence&quot;<br>           , color=&quot;Alignment&quot;<br>           , trendline=&#39;ols&#39;<br>           , title=&#39;Heroes Comparison: Strength vs Intelligence&#39;<br>           , hover_name=&#39;Name&#39;<br>           , opacity=0.5<br>           , template=&#39;plotly_dark&#39;<br>           )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*HPzGIAOd-y4R9ScYCcjngA.gif" /><figcaption>Similar relationships across Alignments.</figcaption></figure><p>Maybe <em>this</em> data is not that interesting with the added category, but categories really stand out when you find the right pattern, such as with the classic <a href="https://archive.ics.uci.edu/ml/datasets/iris">iris data set</a>…like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W3hG5XoTr4QZbg3SeqpQRA.png" /><figcaption>credit: <a href="https://www.plotly.express/">https://www.plotly.express/</a></figcaption></figure><p>But going back to our original scatter plot with color, what if we wanted to add on a <strong>third continuous variable</strong>? How about if we tied it to the <strong>size</strong> of our markers?</p><p><strong>Scatter Plot, with Color and Size</strong></p><p>Below we add the continuous Power variable as the <strong>size</strong> of the markers.</p><pre>px.scatter(data_frame=heroes[~heroes.Gender.isna()]<br>           , x=&quot;Strength&quot;<br>           , y=&quot;Intelligence&quot;<br>           , color=&quot;Alignment&quot;<br>           , size=&quot;Power&quot;<br>           , trendline=&#39;ols&#39;<br>           , title=&#39;Heroes Comparison: Strength vs Intelligence&#39;<br>           , hover_name=&#39;Name&#39;<br>           , opacity=0.5<br>           , template=&#39;plotly_dark&#39;<br>          )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*1QkG515_X3QYSURiSEzBxA.gif" /><figcaption>Wow, Galactus is tops in Strength, Intelligence, and Power!</figcaption></figure><p>One thing I noticed is that the legend doesn’t automatically add a legend for <strong>Size</strong>. That’s a little annoying. What can I say, Plotly Express has already spoiled me over the course of this post!</p><p>We’ve barely begun to scratch the surface of what’s possible, based on what I’ve seen in the documentation. We can go on and on, but let’s end our exploration on a couple more examples.</p><p><strong>Scatter Matrix</strong></p><p>Scatter matrices perform <strong>pair-wise scatter plots </strong>on a set of continuous variables, which you can then customize with <strong>colors, symbols, etc. to stand for categorical variables</strong>.</p><pre>px.scatter_matrix(data_frame=heroes[~heroes[&#39;Gender&#39;].isna()]<br>                  , dimensions=[&quot;Strength&quot;, &quot;Speed&quot;, &quot;Power&quot;] <br>                  , color=&quot;Alignment&quot;<br>                  , symbol=&quot;Gender&quot; <br>                  , title=&#39;Heroes Attributes Comparison&#39;<br>                  , hover_name=&#39;Name&#39;<br>                  , template=&#39;seaborn&#39;<br>                 )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Y9zbKXmKYB1wwlv_GQAblQ.gif" /><figcaption>Maybe a future release will have the option to toggle the diagonal plots into a histogram (or some other univariate plot).</figcaption></figure><p><strong>Scatter with Marginal Plots</strong></p><p>That was neat, but this next one I really like for its simplicity. The idea is you can add <strong>any of the</strong> <strong>univariate plots </strong>we’ve covered to the <strong>margins of a scatter plot</strong>.</p><pre>px.scatter(data_frame=heroes[~heroes.Gender.isna()]<br>           , x=&quot;Strength&quot;<br>           , y=&quot;Speed&quot;<br>           , color=&quot;Alignment&quot;<br>           , title=&#39;Strength vs Speed | by Alignment&#39;<br>           , marginal_x=&#39;histogram&#39;<br>           , marginal_y=&#39;box&#39;<br>           , hover_name=&#39;Name&#39;<br>           , opacity=0.2<br>           , template=&#39;seaborn&#39;<br>          )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*v2KDLTqivG5BhmSsioKYEA.gif" /></figure><p>Whew! That…was a lot. But I think it’s a good start on creating a quick reference to the more common plotting techniques, all using <strong>plotly express</strong>. I’m really digging what I’ve seen so far (everything we’ve done in this post are technically one-liners!) and look forward to their future updates! Thanks for reading.</p><p><em>Please feel free to reach out! | </em><a href="https://www.linkedin.com/in/werlindo/">LinkedIn</a> | <a href="https://github.com/MangrobanGit">GitHub</a></p><p><strong>Sources:</strong></p><p><a href="https://www.plotly.express/">https://www.plotly.express/</a></p><p>plotly. Introducing Plotly Express, 20 Mar 2019, <a href="https://medium.com/@plotlygraphs/introducing-plotly-express-808df010143d">https://medium.com/@plotlygraphs/introducing-plotly-express-808df010143d</a>. Accessed 11 May 2019.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98366e35ad0f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/plotly-express-yourself-98366e35ad0f">Plotly Express Yourself</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why data science.]]></title>
            <link>https://medium.com/data-science/why-data-science-326fe9031d89?source=rss-b4007413e9e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/326fe9031d89</guid>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Werlindo Mangrobang]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 00:05:37 GMT</pubDate>
            <atom:updated>2019-05-21T05:53:08.193Z</atom:updated>
            <content:encoded><![CDATA[<h4>or, why I decided to attend Flatiron School’s data science immersive bootcamp.</h4><p>Everybody loves Venn diagrams, myself included. If you don’t know what they are, well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i7-0oOK2T4-e_b6dHtXNvg.png" /><figcaption>Source: me.</figcaption></figure><p>A specific one in particular sticks out in my memory. A few years ago, I saw (if not this exact one, then some version of it) the following Venn diagram describing “Data Science”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oC2rV-Yu7o_IwiPwDUQIWg.png" /><figcaption><a href="http://drewconway.com/zia/2013/3/26/the-data-science-venn-diagram">http://drewconway.com/zia/2013/3/26/the-data-science-venn-diagram</a></figcaption></figure><p>…and there have been others who have put <a href="https://towardsdatascience.com/the-essential-data-science-venn-diagram-35800c3bef40">their own twist</a> on it since the original made the internet rounds. At any rate, upon reading it I recall thinking, “this <em>kind of</em> describes my skill-set!”</p><p>Let’s unpack that “<em>kind of”</em>.</p><p>In college, I earned my <a href="http://www.washington.edu/">undergraduate</a> majors in Statistics (BS), Economics (BS), and Business (BA). Apparently, I really liked going to school. I ended up with three majors because I was about to graduate with an Economics degree, when that spring, I learned about the <a href="https://www.soa.org/future-actuaries/what-is-an-actuary/">actuarial</a> profession at a career week panel. I was attracted to what was described: <a href="https://www.soa.org/education/exam-req/default">tangible achievements</a> that usually translated to career progression, and a typically <a href="https://beanactuary.org/why/?fa=balance-of-work-life">even work-life balance</a>. My master plan thus transformed into getting educated in Statistics, as well as Business.</p><p>Math and Statistics Knowledge? Check.</p><p>After college, I went to work for a local health insurance company as an entry-level actuarial analyst. I then grinded my way to the highest designation of the profession, known as a <a href="https://www.soa.org/future-actuaries/earning-credentials/">Fellow</a> (FSA). This required <a href="https://pathways.soa.org/asa">exams</a>, exams, and <a href="https://pathways.soa.org/fsa">more exams</a>. It typically takes six to ten years to pass all those exams; it took me eight (Did I mention that I think I like going to school?). Overall, I’ve been working at this organization for over a decade. You work someplace long enough, you can’t help but master some sort of domain knowledge.</p><p>Substantive Expertise? Check.</p><p>Besides the mathy/statsiness of my Stats and Econ degrees, I also majored in Business, with a concentration in Information Systems. This exposed me to the technical tools of the business world, which really resonated with me. Courses like databases, programming with Visual Basic and HTML, scratched an itch that started with introductory programming courses in my pre-engineering prerequisites (when I thought I wanted to be an engineer).</p><p>I would further ply those tools in my part-time job as a data entry clerk for a research study. I constantly tinkered with and automated parts of the Access database that served as the data collection application for the study. This, in turn, led to referrals to build custom Access database applications for friends of co-workers. In subsequent years this has evolved to doing things like combining a Tableau front end with a Teradata back end and tying them <a href="https://github.com/tableau/TabPy">together with Python</a> algorithms developed by colleagues to create a dynamic application.</p><p>Hacking Skills? Check.</p><p>So while I felt my skills touched on these three distinct sets, there is one intersection that I’ve felt deficient in for a few years now (this is what I meant by <em>kind of!</em>):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*5a8uhPkH4KP-Q5fOYxkn_A.png" /><figcaption>Source: <a href="http://sitn.hms.harvard.edu/flash/2017/recommended-machine-learning-helps-choose-consume-next/">http://sitn.hms.harvard.edu/flash/2017/recommended-machine-learning-helps-choose-consume-next/</a> | figure by <em>Jeep Veerasak Srisuknimit</em></figcaption></figure><p>Machine Learning.</p><p>As an actuary, I believe our work and skill set very much overlaps with what I understand to be those of a ‘data scientist’. We typically work with (very) large sets of data to build analyses and models to ‘predict’ what’s going to happen. For example, a traditional role in health insurance actuarial sciences is predicting ultimate claims dollar volume for a time period, before we even see that actual claim documentation from the health care providers.</p><p>Over the past few years, we have witnessed the explosion of ‘data science’ as an area of practice, and what I felt was missing in my professional development (and that is greatly valued in data scientists) is depth and practiced knowledge in modern machine learning.</p><p>I mean, I’ve <em>done </em>machine learning. If you’ve used the <a href="https://support.office.com/en-us/article/slope-function-11fb8f97-3117-4813-98aa-61d7e01276b9">SLOPE</a> function in Excel: congratulations, you’ve run a linear regression! But in a space where new algorithms are coming out <a href="https://www.groundai.com/project/foveabox-beyond-anchor-based-object-detector/1">by the week</a>, I’ve felt I’ve been falling behind further and faster.</p><p>One of my first attempts at modernizing my toolbox was attending a predictive modeling 3-day bootcamp offered by the Society of Actuaries. While the bootcamp offered examples and inspiration to bring back to work, it wasn’t a replacement for actually <em>doing</em> the work with something <em>meaningful</em>. And as other similar bootcamps and seminars came up I would go to them, and come away with similar results. A lot of inspiration, some knowledge, but not the muscle memory or confidence.</p><p>In search of ways to continue to fill the gap, I’ve pursued other learning opportunities, such as Coursera and DataCamp courses. Last year, the Society of Actuaries, recognizing the need to update its’ members skills in the face of data science (<em>solely this author’s opinion!</em>) began offering a <a href="https://www.soa.org/programs/predictive-analytics-certificate/">Predictive Analytics Certificate Program</a>, and I jumped at the opportunity. I participated in the program from April 2018 through September 2018 and officially earned my certificate. I learned <strong>a</strong> <strong>lot </strong>and I’m thankful for the great basis in the knowledge it provided me. While I had victories in applying some of what I’ve learned to projects (isn’t <a href="https://en.wikipedia.org/wiki/Random_forest">random forest</a> a great name?), I still suffered from <a href="https://en.wikipedia.org/wiki/Impostor_syndrome">impostor syndrome</a>. I was this guy with letters after his name and certificates but still didn’t feel up to snuff.</p><p>I felt I had more to catch up on. Python had become the de facto <a href="https://www.kdnuggets.com/2017/08/python-overtakes-r-leader-analytics-data-science.html">machine learning language of choice</a> (<em>opinion!</em>), and the certificate program I’d just completed had used R (which I actually like!). I’d dabbled in using Python with projects for a while, but never in an extensive or meaningful way, mainly limited to small tasks. So when I saw a “Python Bootcamp for Actuaries” being offered at the end of February 2019 in Denver I, again, jumped at it.</p><p>In the weeks leading up to that trip, I then stumbled onto Flatiron School on the internet. I honestly don’t remember how I got there, but, obviously, I stuck around to see what they offered, and became intrigued with the idea of doing a data science bootcamp. The prior year, while conversing with a trainer for our data science software about his background, he mentioned that he had graduated from a data science immersive bootcamp in New York. While fascinated by the idea of it, I immediately dismissed it as being impossible. <em>When </em>would I go? <em>Where</em> would I go? I work full-time! I have a family!</p><p>But this time something was different. I had completed the certificate program and still felt something was missing. I sensed this was my last shot at not being an impostor anymore. So I submitted an application to Flatiron and started on the free bootcamp pre-work.</p><p>I traveled to the Python bootcamp and had my admissions interview over Zoom the day I flew in. Attending the Python bootcamp actually helped augment the good vibes I had towards applying to Flatiron. While the bootcamp was ostensibly about Python and had a lot of great content, there was also much thought leadership being offered on the topic of actuaries evolving with data science. I left Denver excited at the opportunity to continue digging into learning and practicing Python and further developing my machine learning chops. Flatiron would be the way I would pursue this goal.</p><p>So that leads us to the present. I am a Flatiron Data Science Immersive Bootcamp student. And it’s nothing like I’ve ever experienced. With all due and great respect to my other bootcamp experiences:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*10WCjwY1QuYgkEcBfRDN9Q.jpeg" /></figure><p>Thanks for reading. <em>Please feel free to reach out! | </em><a href="https://www.linkedin.com/in/werlindo/">LinkedIn</a> | <a href="https://github.com/MangrobanGit">GitHub</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=326fe9031d89" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/why-data-science-326fe9031d89">Why data science.</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>