<?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 Jack Baker on Medium]]></title>
        <description><![CDATA[Stories by Jack Baker on Medium]]></description>
        <link>https://medium.com/@jackcbaker?source=rss-71e17bdc6394------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yu9-x1tk_8Iv2C86INEdVA.jpeg</url>
            <title>Stories by Jack Baker on Medium</title>
            <link>https://medium.com/@jackcbaker?source=rss-71e17bdc6394------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:39:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jackcbaker/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[Feature selection for forecasting algorithms]]></title>
            <link>https://medium.com/data-science/feature-selection-for-forecasting-algorithms-10598e50667f?source=rss-71e17bdc6394------2</link>
            <guid isPermaLink="false">https://medium.com/p/10598e50667f</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[forecasting]]></category>
            <dc:creator><![CDATA[Jack Baker]]></dc:creator>
            <pubDate>Mon, 23 Aug 2021 19:48:31 GMT</pubDate>
            <atom:updated>2021-08-26T13:52:32.291Z</atom:updated>
            <content:encoded><![CDATA[<h4>Features are not guaranteed to improve forecast performance. In this article we explain why, and how to perform feature selection.</h4><p>In this article, we talk feature selection for forecasting. We start by explaining why you should think twice before adding features to your forecasts; then we talk about some ways to do feature selection for forecasting models. To put things in practical terms, we demo a feature selection method that has a decent balance between performance and computational cost in R.</p><h3>Why you should think twice before including features in your forecasting models?</h3><p>For many data science models, the more features (often referred to as regressors in forecasting), the better your model accuracy will be. But forecasting is quite finickity, and this is often not the case.</p><h3>Why is this?</h3><p>We’ll break this down into a few points.</p><ol><li>Let’s imagine you want to forecast whether a coin will land heads or tails. That’s going to be a non-starter. This is because the variable you’re trying to forecast (let’s call it the target), is completely random. Some targets just don’t have any signal at all, or don’t have any regressors that provide any signal.</li><li>Let’s call the observations of the variable you have already seen the actuals. These will often contain a surprising amount of information already. The forecasting algorithm you’re using will be hell bent on picking up on this signal. Which means your feature doesn’t just have to be correlated with the target, it has to provide information that the actuals don’t. This is much rarer. For example, ice cream sales will be correlated with the weather, but it definitely won’t contain any more information than in the actuals.</li><li>You either need to know your regressor ahead of time (it needs to be <em>forward facing</em>), or you need to forecast that regressor as well. Going back to the ice cream example, this regressor is not forward facing. So if you want to know the weather a week from now, you’ll have to forecast ice cream sales ahead by a week, and then feed that into your forecasting algorithm. This adds a lot of noise to your regressor, which in turn adds noise to your forecast and makes it worse. It is rarely worth doing.</li><li>Even forward facing regressors frequently add unintended noise to your forecast, just because there is not enough signal, similar to points 1 and 2.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KE3pQBT7HFc9Sqij" /><figcaption>Photo by <a href="https://unsplash.com/@rosssneddon?utm_source=medium&amp;utm_medium=referral">Ross Sneddon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Some ways to perform feature selection for a forecasting algorithm</h3><p>There are a few ways to check if a regressor provides any useful information to a forecast. Most of these rely on a <em>walkforward backtest</em>. A walkforward backtest is where you start at a historic date (called the train upto date), you forecast using only data up to that date, then you move up to the next date and repeat, until you reach the present.</p><p>Then to evaluate your forecast, you can calculate the forecast error compared with actuals. So it is a lot like a train/test set split in classic data science problems. A tutorial of this technique is <a href="https://machinelearningmastery.com/backtest-machine-learning-models-time-series-forecasting/">here</a>. If you have two forecasts you want to decide between, you can run a backtest for each of them. The one with the lowest error would be classed as the best.</p><p>With this, here are some ways to perform feature selection, in order of increasing computational and time cost:</p><h3>1. Look at correlations between the actuals and the regressor.</h3><p>This just checks the regressor using in-sample fit, and does not cover point 2 in the previous section (does the regressor contain information the forecast doesn’t). This option is not recommended.</p><h3>2. Use the Akaike Information Criterion (AIC) of the forecast.</h3><p>This is a statistical approximation that tries to use insample fit to approximate predictive fit. See <a href="https://otexts.com/fpp3/estimation-and-model-selection.html">this chapter</a> for using the AIC for model selection.</p><p>The way this would work is you would fit your forecasting model both with and without the regressor, and check the AIC of each. The model with the lowest AIC would be the one you would pick.</p><p>This method is good, fast, and commonly used. But it is an approximation that only uses insample fit, so may not give a good estimate of predictive fit.</p><h3>3. Use linear regression on the actuals with both the current forecast and your regressor as a feature</h3><p>The key to this method is getting around point 2. We want to check how much additional predictive information our regressor gives after taking into account the information the forecast has learned.</p><p>For this method we run a single backtest using the current forecast without regressors. Then we feed both the regressor and the forecast through a linear regression that is trying to learn the actuals.</p><p>To assess how good the regressor is, we can examine whether the regressor is significant in the standard way you would assess a linear regression (i.e. check its p-value is sufficiently small). Because we have also included the forecast itself in the regression, this regression should account for what is already learned by the forecasting algorithm.</p><p>This method assesses predictive fit directly, but only needs to run one backtest. The method works particularly well when you have many regressors to check. You still just have to fit one backtest (the current forecast with no regressors), then you can use standard techniques for model selection in linear regression, such as recursive feature elimination (make sure you don’t eliminate your forecast though)!</p><h3>4. Run a forecast backtest with and without the regressor</h3><p>This method is quite simple, we run a backtest both with a forecast using the regressor, and without. We then compare the error of the two. If the error of the forecast with the regressor is significantly lower, we might use that regressor going forward.</p><p>Backtests are bread and butter of model selection in forecasting. So this method works well.</p><p>But as the number of regressors goes up, this method gets prohibitively expensive. We have to fit multiple forecasting models on each of the train upto dates.</p><h3>Demoing method 3</h3><p>We choose to demo method 3, as it offers a good balance between directly measuring predictive quality of a regressor, with computational cost. Often a backtest of the best forecasting method so far is already at hand from other experiments, which is the most computationally demanding part of this method.</p><p>To demo this practically, we’ll use R. Follow along with the <a href="https://github.com/jackcbaker/blog-notebooks/blob/main/checking_regressors.Rmd">interactive Rmarkdown</a> for this tutorial on <a href="https://github.com/jackcbaker">my github</a>. For all the packages used in this tutorial, download the <a href="https://mran.microsoft.com/snapshot/2020-10-09/web/packages/fpp3/index.html">FPP3 package</a> by running in R install.packages(&#39;fpp3&#39;). This package is a companion to the amazing <a href="https://otexts.com/fpp3/">introductory forecasting book</a> by Rob Hyndman.</p><p>The data we’ll use, is the US consumption expenditure data from the book. This is a time series of quarterly percentage changes of various measures in the US economy. The one we’re interested in forecasting is economic production, which is a measure of the health of the US economy. It can be accessed after loading in fpp3, and is called us_change. The column we want to forecast is Production. Let&#39;s plot it</p><pre>library(fpp3)<br><br>us_change %&gt;%<br>    autoplot(Production) +<br>    labs(y = &quot;Production (% change)&quot;)</pre><figure><img alt="Plot of US % change production over time." src="https://cdn-images-1.medium.com/max/672/0*ENbterr2WTymt5-O.png" /><figcaption>Plot of US % change production over time.</figcaption></figure><p>To forecast this data, we’ll fit an <a href="https://otexts.com/fpp3/expsmooth.html">ARIMA model</a> to this data, which allows regressors to be added.</p><p>To fit the linear regression on the features we need to check, we’ll need to run a backtest on our forecasting algorithm with no regressors. Let’s backtest our forecasting model on the last 50 data points, and forecast one-step ahead. The ARIMA function will automatically perform parameter tuning for the ARIMA model using AIC.</p><pre># Set seed for reproducibility<br>set.seed(13)<br>backtest_size &lt;- 50<br>n &lt;- nrow(us_change)<br>backtest_results &lt;- us_change[(n - (backtest_size - 1)):n,]<br>backtest_results$forecast &lt;- rep(NA, backtest_size)<br>for (backtest_num in backtest_size:1) {<br>    fit &lt;- us_change[1:(n - backtest_num),] %&gt;%<br>        select(Production) %&gt;%<br>        model(<br>            forecast = ARIMA(Production)<br>        )<br>    backtest_fc &lt;- fit %&gt;% forecast(h = 1)<br>    results_index &lt;- backtest_size - (backtest_num - 1)<br>    backtest_results$forecast[results_index] &lt;- backtest_fc$.mean<br>}<br><br># Let’s plot our backtest results against actuals<br><br>backtest_results %&gt;%<br>    pivot_longer(c(Production, forecast), names_to = &quot;Type&quot;) %&gt;%<br>    autoplot(value)</pre><figure><img alt="Plot of ARIMA backtest without regressors." src="https://cdn-images-1.medium.com/max/672/0*GtJ_drsDA-F7p-3U.png" /><figcaption>Plot of ARIMA backtest without regressors.</figcaption></figure><p>Notice that the forecast does fine during normal periods, but performs poorly during periods of large fluctuation. Can we use regressors to improve this?</p><p>We have modelled production data, which is typically measured using GDP. But measuring GDP takes an enormous effort, and in many countries is only done every quarter. Other data can be easier to estimate more regularly, and is more readily available. One measure this might be true for is consumer spending. This is the Consumption column in our dataset.</p><p>Let’s use a simple linear regression to see if using consumption as a regressor has any promise.</p><pre>regress_test &lt;- lm(Production ~ forecast + Consumption, data = backtest_results)<br>summary(regress_test)<br><br>## <br>## Call:<br>## lm(formula = Production ~ forecast + Consumption, data = backtest_results)<br>## <br>## Residuals:<br>##     Min      1Q  Median      3Q     Max <br>## -2.4347 -0.7459  0.1566  0.5379  2.4470 <br>## <br>## Coefficients:<br>##             Estimate Std. Error t value Pr(&gt;|t|)    <br>## (Intercept)  -0.8588     0.1889  -4.545 3.84e-05 ***<br>## forecast      0.8750     0.1406   6.224 1.23e-07 ***<br>## Consumption   1.2630     0.3158   4.000 0.000223 ***<br>## ---<br>## Signif. codes:  0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1<br>## <br>## Residual standard error: 0.9268 on 47 degrees of freedom<br>## Multiple R-squared:  0.6461, Adjusted R-squared:  0.6311 <br>## F-statistic: 42.91 on 2 and 47 DF,  p-value: 2.501e-11</pre><p>The p-value is very low for the Consumption column, well below the classic 0.05 level. This indicates including it in the forecast should improve predictive performance.</p><p>What about consumer savings (the Savings column in the dataset)?</p><pre>regress_test_savings &lt;- lm(Production ~ forecast + Savings, data = backtest_results)<br>summary(regress_test_savings)<br><br>## <br>## Call:<br>## lm(formula = Production ~ forecast + Savings, data = backtest_results)<br>## <br>## Residuals:<br>##     Min      1Q  Median      3Q     Max <br>## -3.1353 -0.5435  0.1223  0.6092  2.7229 <br>## <br>## Coefficients:<br>##             Estimate Std. Error t value Pr(&gt;|t|)    <br>## (Intercept) -0.34043    0.16657  -2.044   0.0466 *  <br>## forecast     1.08637    0.14867   7.307  2.8e-09 ***<br>## Savings     -0.01165    0.01029  -1.132   0.2633    <br>## ---<br>## Signif. codes:  0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1<br>## <br>## Residual standard error: 1.059 on 47 degrees of freedom<br>## Multiple R-squared:  0.5383, Adjusted R-squared:  0.5186 <br>## F-statistic: 27.39 on 2 and 47 DF,  p-value: 1.299e-08</pre><p>The p-value in this case is high, so we should not include savings in our model.</p><p>Let’s check our choice by including consumption in the ARIMA model and running a new backtest</p><pre>backtest_regressor_results &lt;- backtest_results<br>backtest_regressor_results$forecast_consumption &lt;- rep(NA, backtest_size)<br>for (backtest_num in backtest_size:1) {<br>    fit &lt;- us_change[1:(n - backtest_num),] %&gt;%<br>        select(Quarter, Production, Consumption) %&gt;%<br>        model(<br>            forecast = ARIMA(Production ~ Consumption)<br>        )<br>    new_regressor &lt;- select(us_change[n - (backtest_num - 1),], Quarter, Consumption)<br>    backtest_fc &lt;- fit %&gt;% forecast(new_data = new_regressor)<br>    results_index &lt;- backtest_size - (backtest_num - 1)<br>    backtest_regressor_results$forecast_consumption[results_index] &lt;- backtest_fc$.mean<br>}<br><br># Plot both backtests<br>backtest_regressor_results %&gt;%<br>    pivot_longer(c(Production, forecast, forecast_consumption), names_to = &quot;Type&quot;) %&gt;%<br>    autoplot(value)</pre><figure><img alt="Plot of ARIMA backtest with and without selected regressors." src="https://cdn-images-1.medium.com/max/672/0*Y6o6xOkDouChk18y.png" /><figcaption>Plot of ARIMA backtest with and without selected regressors.</figcaption></figure><p>It’s a little difficult to tell which forecast performed better by eye, so let’s check the MSE error</p><pre>backtest_regressor_results %&gt;%<br>    as_tibble() %&gt;%<br>    summarise(<br>        MSE_no_regressors = mean((Production - forecast)^2),<br>        MSE_consumption_regressor = mean((Production - forecast_consumption)^2)<br>    )<br><br>## # A tibble: 1 x 2<br>##   MSE_no_regressors MSE_consumption_regressor<br>##               &lt;dbl&gt;                     &lt;dbl&gt;<br>## 1              1.20                      1.01</pre><p>The MSE is lower in the backtest including consumption as a regressor, so we probably made the right choice :).</p><h3>Key Points</h3><ul><li>In forecasting, including features are not guaranteed to improve model performance, so think carefully before you do.</li><li>Feature selection in forecasting is a trade off between selection performance and computational cost.</li><li>A way to select features in forecasts that directly measures predictive performance, is to run a backtest of your forecast without regressors, then fit a linear regression model to learn actuals given your forecasts and the regressor. Select the regressor if the p-value is low.</li></ul><p><em>Originally published at </em><a href="https://jackbakerds.com/posts/forecasting-feature-selection/"><em>https://jackbakerds.com</em></a><em> on August 23, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10598e50667f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/feature-selection-for-forecasting-algorithms-10598e50667f">Feature selection for forecasting algorithms</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[A python equivalent for R markdown]]></title>
            <link>https://medium.com/data-science/a-python-equivalent-for-r-markdown-d6fba36dc577?source=rss-71e17bdc6394------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6fba36dc577</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Jack Baker]]></dc:creator>
            <pubDate>Tue, 04 May 2021 19:20:00 GMT</pubDate>
            <atom:updated>2021-06-07T20:11:12.817Z</atom:updated>
            <content:encoded><![CDATA[<h4>R markdown is a powerful tool for sharing insights. In this post we show how to write similar reports in python.</h4><p><a href="https://rmarkdown.rstudio.com/">R markdown</a> is a powerful tool for sharing insights with stakeholders. You can write snippets of R code that generate plots. This can then be compiled to a HTML or pdf file that you can share with non-technical stakeholders.</p><p>This is not as straightforward in python. Yes, Jupyter notebooks are a great way of sharing analysis with other developers. But compiling to HTML/pdf, with code snippets removed, that looks nice enough for a non-technical stakeholder, I’ve found clunky using Jupyter notebooks. R markdown also has great tools to generate <a href="https://bookdown.org/yihui/rmarkdown-cookbook/kable.html">nice looking tables</a>, not just plots.</p><p>I’ve been working with a python heavy team though, so have been trying to figure out how to generate R markdown style documents. In this post I’ll outline what I’ve been using to generate HTML reports in python, that look nice enough to share with non-technical stakeholders. The process uses a few tools.</p><figure><img alt="A photo of an insight report on a laptop" src="https://cdn-images-1.medium.com/max/1024/0*eTW89iRFpvZNzjtn" /><figcaption>Photo by <a href="https://unsplash.com/@lukechesser?utm_source=medium&amp;utm_medium=referral">Luke Chesser</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Step 1: Embedding Plots in HTML</h3><p>The first step is to embed plots into a static HTML that you can then share with others. A great tool for this is <a href="https://plotly.com/python/">plotly</a>. Plotly has a <a href="https://plotly.com/python-api-reference/generated/plotly.io.to_html.html">to_html function</a> (one of my amazing colleagues found this) which will write the plots as a HTML string, which you can then write to a file.</p><p>Plotly graphs look the part, and they allow the user to hover over the points to see what the values are; I’ve found this goes down well with customers.</p><p>Sometimes users need plots they can copy-paste though. In this case I recommend using python’s more standard plotting libraries, like <a href="https://seaborn.pydata.org/">seaborn</a> or <a href="https://matplotlib.org/">matplotlib</a>. To embed the image into HTML without needing to have a separate image file the HTML references is a bit more involved. But you can do it by encoding the image as base64 and writing directly to your HTML. Just follow the instructions in this <a href="https://stackoverflow.com/questions/48717794/matplotlib-embed-figures-in-auto-generated-html">stackoverflow post</a>.</p><figure><img alt="A picture of some HTML code" src="https://cdn-images-1.medium.com/max/1024/0*f7zTToBLo7a7hSK6" /><figcaption>Photo by <a href="https://unsplash.com/@pankajpatel?utm_source=medium&amp;utm_medium=referral">Pankaj Patel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Step 2: Setting the Layout of the HTML Document</h3><p>Great, now you can embed plots in HTML, and actually if you turn off the full_html option in plotly&#39;s to_html function, you can write as many plotly plots as you like to a html file by just appending the strings.</p><p>But what about layout, commentary, and tables of data? This is where I use python’s HTML templating libraries — which allow you to use python to generate static HTML files from templates. This technique is powerful, and used in python backend development libraries like <a href="https://flask.palletsprojects.com/en/1.1.x/">flask</a> and <a href="https://www.djangoproject.com/">django</a>. It’s quick to learn, but does require some knowledge of HTML.</p><p>I use the <a href="https://jinja.palletsprojects.com/en/2.11.x/">Jinja</a> library to generate my HTML reports (it’s one of the most popular HTML templating libraries in python).</p><h3>Step 3: Making the Report Look Nice</h3><p>For anyone that’s worked with HTML before you’ll know it takes a long time to make anything which looks presentable.</p><p>I didn’t want to spend much time on this because I wanted to generate the report as quick as possible. So I used the <a href="https://getbootstrap.com/">bootstrap</a> CSS library. This tool allows you to make your report look nice in a short amount of time (all I tend to do is wrap everything in a &lt;div class=&quot;container&quot;&gt; and maybe add some padding).</p><p>Bootstrap is basically a set of prebuilt HTML classes you can use to format your HTML. For example to make an HTML table look nice in bootstrap it’s as simple as &lt;table class=&quot;table&quot;&gt; (tables look quite ugly in standard HTML). You can add padding at the top of a title element by adding &lt;h1 class=&quot;pt-1&quot;&gt;.</p><h3>Thoughts</h3><p>As you can see, this is a fiddlier process than with R markdown (if anyone has a better way, please get in touch!). But the tools are useful to learn, especially Jinja and bootstrap which are standard tools for web development. Once you’ve learnt the libraries, and have some pre-made templates ready to go, the process gets quite quick.</p><p><em>Originally published at </em><a href="https://jackbakerds.com/posts/python-equivalent-rmarkdown/"><em>https://jackbakerds.com</em></a><em> on May 4, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6fba36dc577" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/a-python-equivalent-for-r-markdown-d6fba36dc577">A python equivalent for R markdown</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[Three ways to speed up developing your data science solutions]]></title>
            <link>https://medium.com/data-science/three-ways-to-speed-up-developing-your-data-science-solutions-6bedc7e72a4e?source=rss-71e17bdc6394------2</link>
            <guid isPermaLink="false">https://medium.com/p/6bedc7e72a4e</guid>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[notes-from-industry]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[production]]></category>
            <dc:creator><![CDATA[Jack Baker]]></dc:creator>
            <pubDate>Mon, 26 Apr 2021 20:00:00 GMT</pubDate>
            <atom:updated>2021-06-01T15:25:29.442Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://towardsdatascience.com/tagged/notes-from-industry">Notes from Industry</a></h4><h4>Your customers want results and quickly. This post suggests tips to deliver data science tools quicker.</h4><p>Your customers want results and quickly. This can be stressful as a data scientist: solutions are often experimental and results not guaranteed; you need time to think about the problem.</p><p>In this post I’ll share three ways I use to develop data science solutions faster.</p><p>I find there are a few time sinks when developing data science solutions: going down a rabbit hole or dead end, productionizing, checking your solution actually beats the current business process, and ensuring your code is free of bugs. How can we try to avoid these pitfalls?</p><figure><img alt="A rabbit inside a log with a hole in it" src="https://cdn-images-1.medium.com/max/1024/0*wilsPkz5IfNHOw-b" /><figcaption>Photo by <a href="https://unsplash.com/@rahimsofri?utm_source=medium&amp;utm_medium=referral">Rahim Sofri</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>1. Start as simple as possible</h3><p>When I start a new problem, I implement the simplest possible solution I can think of. Once this is developed and tested, I iteratively improve on it. What this gets you:</p><ul><li>A baseline you can compare all your models against. This helps stop you going down a rabbit hole: I talk about this more later.</li><li>A quick, quality start — I regularly find a baseline beats a more complex model.</li><li>A chance to develop the pipeline without worrying about intricate model headaches. I find this makes a solution easier to productionize.</li></ul><p>This also applies to iterations on your baseline. Break these down so they’re as small as possible. If you follow the third point this becomes powerful.</p><h3>2. Modularise</h3><p>Often a data science solution consists of lots of mini problems you need to solve. I recommend you break down your problem as much as possible into components.</p><figure><img alt="Pieces of lego" src="https://cdn-images-1.medium.com/max/1024/0*PxlKnf2e9BTdEJe9" /><figcaption>Photo by <a href="https://unsplash.com/@xavi_cabrera?utm_source=medium&amp;utm_medium=referral">Xavi Cabrera</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>What this gets you:</p><ul><li>You can write each modular part as separate code modules. Set these to take relatively general input and output, and your code will be much easier to productionize: all you need to write are interfaces to your particular infrastructure (which is reusable code).</li><li>Your code will be easier to test, which helps ensure it’s bug free.</li><li>If you follow the first point, your code will be reusable for future solutions.</li><li>Your baseline becomes even simpler :).</li></ul><p>For example, say you’re developing a churn model, you might have: one or two modules handling data transformation, a module that handles the model build, one that handles serving predictions, and one that handles customer visualisations.</p><h3>3. Test each iteration against your baseline, the current business process and your best model so far</h3><figure><img alt="A maths test" src="https://cdn-images-1.medium.com/max/1024/0*ZG_gut4vJe3qNkGr" /><figcaption>Photo by <a href="https://unsplash.com/@antoine1003?utm_source=medium&amp;utm_medium=referral">Antoine Dautry</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you follow what I mentioned earlier and keep your model iterations small, this can really keep you on track:</p><ul><li>You catch rabbit holes early by seeing that an iteration made no improvement.</li><li>You can hone in on which module needs most improvement.</li><li>You can fail fast — if something isn’t working, you’ll know it quickly and can manage customer expectations.</li><li>You have regular tangible results to share with customers.</li></ul><p><em>Originally published at </em><a href="https://jackbakerds.com/posts/speed-up-data-science-development/"><em>https://jackbakerds.com</em></a><em> on April 26, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bedc7e72a4e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/three-ways-to-speed-up-developing-your-data-science-solutions-6bedc7e72a4e">Three ways to speed up developing your data science solutions</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[How to move your data science solution into a hands off state]]></title>
            <link>https://medium.com/data-science/how-to-move-your-data-science-solution-into-a-hands-off-state-b2a02b1df758?source=rss-71e17bdc6394------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2a02b1df758</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Jack Baker]]></dc:creator>
            <pubDate>Sat, 17 Apr 2021 14:36:34 GMT</pubDate>
            <atom:updated>2021-05-19T18:32:37.422Z</atom:updated>
            <content:encoded><![CDATA[<h4>Some tools and tricks for putting your data science solution into production</h4><figure><img alt="Someone relaxing next to a lake" src="https://cdn-images-1.medium.com/max/1024/0*trAF7b7bw38dWWE_" /><figcaption>Photo by <a href="https://unsplash.com/@simonmigaj?utm_source=medium&amp;utm_medium=referral">S Migaj</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Once you’ve developed a data science solution it’s easy to tinker with it indefinitely: running it manually, making small changes to the output, iterating on the model.</p><p>This is not ideal — once you have a solution you’re happy with ideally you should be able to leave it running with minimal input from you, unless something falls over.</p><p>Whether you’re handing over to a support team, or will be supporting the tool yourself, this post gives some tips when you’re trying to move your solution into a hands-off state — or putting it into production.</p><p>Firstly you want to be logging. Logging is where output from your code is printed to a file so you (or the support team) can refer to it later. To move your code into a hands-off state you want to have logs that save to a file, so you can inspect these later if something goes wrong with the tool.</p><figure><img alt="A person logging in a personal journal" src="https://cdn-images-1.medium.com/max/1024/0*rzvTWOgn1mdtkG4y" /><figcaption>Photo by <a href="https://unsplash.com/@thoughtcatalog?utm_source=medium&amp;utm_medium=referral">Thought Catalog</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>What should you be logging? Any obvious things that might go wrong with the tool, such as data validation input, or the tool not being able to connect to a web service, etc. should be flagged as a warning or error and logged.</p><p>Another good rule of thumb is to flag any ‘transaction’. What I mean by this is things like reading files, connecting to a database or calling an API. These are all things that can fail and help serve as a rough guide for where your code failed and what likely went wrong. It’s a good idea to have a summary at the end of a log indicating if the tool finished successfully, and if it failed, what went wrong. A log summary is really appreciated by support teams.</p><p>Another useful tool is alerting. This is where your tool notifies you (or the support team) when something went wrong or failed. One of the most effective ways of doing this is to get your tool to message you on slack or MS teams when something’s gone wrong.</p><figure><img alt="The alert button on a car dashboard" src="https://cdn-images-1.medium.com/max/1024/0*aPsgHprrptSgFlsF" /><figcaption>Photo by <a href="https://unsplash.com/@sigmund?utm_source=medium&amp;utm_medium=referral">Sigmund</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This is very easy to do using webhooks. You can also use email for this e.g. using AWS SNS. It’s a good idea to notify you when something’s gone wrong, as well as when the tool is started and finished; then absence of these alerts will also tell you something is wrong.</p><p>Triage tables are invaluable, especially if you are handing over to a support team or someone is keeping an eye on the tool while you’re away.</p><p>Triage tables list the most common things that can go wrong with the tool, as well as the team that should be contacted to resolve this issue. For example if your tool relies on a data feed that’s managed by another team; if this breaks you can request support to contact that team directly. That way the issue can be resolved without you acting as an intermediary which wastes time for everyone. The act of doing this also forces you to think carefully about your tool and what error handling should be in place, to make sure it’s clear from the logs what went wrong.</p><p>Finally, you have to make sure you have a business’s best interests at heart. It’s easy as a data scientist to make constant iterations to a model, or to agree to every request a customer asks for. But at the end of the day, your job is to provide as much value to a business as possible. You want a model to be effective, but you don’t need it to be perfect, after a point you can probably provide more value working on a different solution.</p><p>Likewise, it’s imperative to listen to what the customer wants, but after a time of ensuring you have met customer requirements, you might be able to provide better value by building the customer a different tool.</p><p><em>Originally published at </em><a href="https://jackbakerds.com/posts/data-science-solution-to-hands-off-state/"><em>https://jackbakerds.com</em></a><em> on April 17, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2a02b1df758" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/how-to-move-your-data-science-solution-into-a-hands-off-state-b2a02b1df758">How to move your data science solution into a hands off state</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[How to tell your data science pipeline is actually working?]]></title>
            <link>https://jackcbaker.medium.com/how-to-tell-your-data-science-pipeline-is-actually-working-70317a1336f8?source=rss-71e17bdc6394------2</link>
            <guid isPermaLink="false">https://medium.com/p/70317a1336f8</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Jack Baker]]></dc:creator>
            <pubDate>Sun, 11 Apr 2021 14:36:34 GMT</pubDate>
            <atom:updated>2021-05-06T06:18:09.049Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been there — studying model output for hours to check a model is working. There’s some better ways than this. For example designing backtests to check a model does better than a baseline.</p><p>The trouble with these methods is they don’t categorically show that a model doing exactly as it is designed to do; they’re also not automated, or (as with a backtest) are expensive to run; and sometimes they’re harder to design than the model itself! Tests that are not automated mean as soon as you make changes you need to do another lengthy check or risk the model being invalid.</p><p>Other options are unit and integration tests, which are automated, but these don’t explicitly check the model is working correctly.</p><p>The way I solve this problem is test datasets. We often spend a lot of time as data scientists waiting for data to arrive. Why not create a test dataset during that time (it only takes about an hour for simple pipelines, which is a lot less than typical data lead time).</p><p>This test dataset should: be modelled off the schema of your source data; have output that, once processed through your modelling pipeline, is known exactly. For example:</p><ul><li>If you have a regression pipeline, you could generate random linearly related data and check held-out predictions match your actuals within a desired level of tolerance.</li><li>If you have a forecasting pipeline, you could check it can predict on timeseries data generated from an ARIMA process within a desired level of tolerance.</li></ul><p>This does not replace the function of a backtest: it is not checking if the model actually works well on the problem at hand. But what it does is check that your modelling pipeline is doing exactly what it’s designed to do. This is especially important when you have quite a complex pipeline which is doing multiple data transformations before applying the model. It’s easy to make a mistake with these transformations and not notice.</p><p>The test can also be automated, and is cheap to run (if you keep your test dataset small), so you get a free integration test on your full pipeline. That way if you make any changes you can just run the test again to check things are still working as expected. You can also add some tests in between different stages of the pipeline to get integration tests on different parts of the pipeline for free.</p><p><em>Originally published at </em><a href="https://jackcbaker.github.io/posts/check-data-science-pipeline-working/"><em>https://jackcbaker.github.io</em></a><em> on April 11, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70317a1336f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>