<?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 James Ryder on Medium]]></title>
        <description><![CDATA[Stories by James Ryder on Medium]]></description>
        <link>https://medium.com/@jamesryder?source=rss-129087ed0602------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Jv2m76F8c2ZeldY5</url>
            <title>Stories by James Ryder on Medium</title>
            <link>https://medium.com/@jamesryder?source=rss-129087ed0602------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 20:02:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jamesryder/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[My 13 marathons in data science]]></title>
            <link>https://medium.com/@jamesryder/my-13-marathons-in-data-science-f110ed7feddb?source=rss-129087ed0602------2</link>
            <guid isPermaLink="false">https://medium.com/p/f110ed7feddb</guid>
            <category><![CDATA[running]]></category>
            <category><![CDATA[marathon-training]]></category>
            <category><![CDATA[strava]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[exploratory-data-analysis]]></category>
            <dc:creator><![CDATA[James Ryder]]></dc:creator>
            <pubDate>Sun, 05 Jun 2022 18:13:02 GMT</pubDate>
            <atom:updated>2022-07-06T10:46:45.429Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>If you’re a keen Strava user you probably know that, together with honing your marathon times or cycle workouts, you are amassing quite a personal dataset of your athletic activities. Much of this can be plotted out within the Strava app itself — you can create your own personal heat map, for example.</p><p>But always being one to do my own analysis, I was curious to find that Strava will neatly extract the years of activity into a file download. It’s easy to set up — there’s a link to request it on the same page that lets you delete your account altogether. It’s right here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*iDmJi3pUqUJXwMDeLxikwQ.png" /><figcaption>Hunt through the Strava menus, and you too can find the ‘Bulk Export’ option</figcaption></figure><p>What arrives by email several minutes later is a directory with everything that Strava has on you — the building blocks of the profile you see when logging on. It’s useful to have all the photos from the runs in one place, for example.</p><p>In fact, I hadn’t realised that I’d added so many photos to my Strava account. A few lines of Python sorts a random selection into a nice photoboard. Which tells its own story better than dry training statistics (not all of these photos are of places I’ve been running — for what it’s worth I also keep records of bike rides, occasional visits to the gym and the very occasional protest march).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oDsRx2W5GmUI8zYkE7fm9w.png" /><figcaption>Random Strava photo dump 1</figcaption></figure><h3>Step One — opening up the archive</h3><p>Every single GPS trace is there, too. My directory, representing about 8 years of faithfully syncing my activities, was about 230Mb in size. What we’ll focus on here, though, is a reasonably small file entitled ‘activities.csv’, which is the summary of everything else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*2OTkIuH8FcWYCA8UUvt-vw.png" /></figure><p>Happily, ‘activities.csv’ can be read straight into Pandas for analysis, like so:</p><pre>import pandas as pd<br>df_james = pd.read_csv(&#39;./export_3517023/activities.csv&#39;)</pre><p>And of course once everything is safely in Pandas, the real analysis can start:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*et_XkpRnesb9gMEkpp2s5Q.png" /><figcaption>My running activity neatly imported to Pandas</figcaption></figure><p>Here’s a plot of every running training session between 2014 (when I started my Strava account) and 2022.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IvAmGqsSjO6WcY6ABFz6ng.png" /><figcaption>Short runs (under 15km) in blue; longer runs (over 15km) in green and marathons (approximately 42km) in red</figcaption></figure><p>What this shows is that I’ve run 13 marathons over the eight years of my Strava account. What it also displays, from study of the red dots, is that my marathons are not nicely spaced over time . My pre-marathon training programme is also a disorganised mess. This is because I tend to run when I’m in the mood and when I have the time. I also enjoy trail running, which accounts for many of the data points shown above.</p><p>Occasionally over these eight years I found myself in the habit of training with a club, corresponding roughly to the ovals sketched out in the diagram. There was also periods of months at a time when I motivated myself to run the same distance route weekly, or more than weekly, which accounts for the blue dots shown in a row. But generally I prefer chaos and unpredictability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*xS3tgUsiHWlYys-bgJSkxQ.png" /><figcaption>Time taken for each marathon</figcaption></figure><p>… and with erratic training comes erratic race times. My most recent attempt — the Paris marathon in October 2022, was also my Personal Worst time! Assuming that I’m going to turn over a new leaf for the next marathon, I wanted to use data science to see if I could learn anything for what to do next time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*97FzXFdDmVhy4AY_ti1wBg.png" /><figcaption>Random Strava photo dump 2</figcaption></figure><h3>Step Two — calculating ‘features’ from the data</h3><p>I used Pandas to extract the data for the 24 weeks of training prior to each marathon — I’ve designated this the overall marathon training period. Within this I subdivided this into three sections —</p><ul><li><strong>the build-up phase (weeks 1 to 12)</strong>. No particular marathon focused training here — most guides advise maintaining regular runs as a way to maintain fitness prior to dedicated training.</li><li><strong>the ‘sort-of-training’ phase (weeks 13 to 18)</strong>. Many marathon training guides advise to start doing long runs and speed work here.</li><li><strong>the ‘real training’ phase (weeks 19 to 24)</strong>. In my mind, with six or fewer weeks left to go, the marathon is clearly on the horizon. If I have the time for it, I make a deliberate effort to do more long runs during this time span, though often life (or minor injuries) gets in the way.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*HjPxzAHtCbNtJdx5OjSKnw.png" /><figcaption>Paris marathon number 1: the red bars display the total accumulated distance per week. The yellow, blue and green box relate to the mean training distance over the respective training period.</figcaption></figure><p>Above is the summary plot of my first marathon — due to no training at all in weeks 1 to 8, the mean distance in the first 12 weeks is 10k. Then a more consistent performance of about 35k per week in the ‘sort-of-training’ phase (I was taking part in Saturday long runs with a club). Finally, the ‘real training’ phase saw a drop to around 28k per week. Either I was distracted, or was training cautiously to avoid aggravating an injury.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*bQTkdAMzB2sfBpOg6qrJPg.png" /><figcaption>all other marathons: the red bars display the total accumulated distance per week. The yellow, blue and green box relate to the mean training distance over the respective training period.</figcaption></figure><p>Here is the summary for the other 12 marathons. As can be seen, sometimes the number of kilometres per week is very close between the three phases. Other times there is a steady increase as the marathon date nears, and in some instances the final six weeks involves a decrease in training.</p><p>Beyond prescribing the total number of kilometres run per week, training guides also recommend the following:</p><ul><li><strong>a weekly long run programme</strong></li><li><strong>weekly speed runs and/or hill training</strong></li></ul><p>To investigate this I repeated the analysis above by calculating the total weekly distance ran as long runs (which I defined as an activity longer than 15km) and the total distance ran as speed runs (which I defined as a training speed below a pace of 4:30 minutes per km) and again working out the mean distance of each for the three training phases.</p><p>There were some other datapoints from the training that I thought might correlate with marathon performance, and, crucially, could also be extracted from the data that I had to hand:</p><ul><li><strong>the temperature on race day</strong> — most recently Strava records this automatically, but it is missing from the earlier records. Happily, it’s possible to extract the information for each date and location in question from satellite reanalysis data, from the Copernicus data store. I extracted the relevant temperature at 10am local time in each case.</li><li><strong>my age on race day</strong> — I thought this might be interesting as a feature, though my inclination was that my erratic training regime might be more influential than the ravages of time</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gGVEJrvNxsW7pyLbpA0m3w.png" /><figcaption>Random Strava photo dump 3</figcaption></figure><h3>Step Three —checking for correlations</h3><p>I then looked into the correlation of each of the features against each marathon finishing time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*Y7Uq1PcbpPZEW4x_y65G2w.png" /><figcaption>marathon finishing time in minutes against a) mean weekly distance in the ‘real training’ phase; b) mean weekly distance in the ‘sort-of-training’ phase; c) mean weekly distance in the ‘build-up’ phase; d) temperature on race day</figcaption></figure><p>The figure above demonstrates the correlation (or lack of one) between marathon finishing time and four of the twelve features. I was interested to see that there’s visually a strong correlation between mean weekly distance in the ‘real training’ phase, but less so for mean weekly distance in the earlier preparation phases. There’s also a weak but discernible trend between marathon time and the temperature on race day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*eOGBqjL3zCW3_zQFDssf7A.png" /><figcaption>correlation between each of the features and elapsed marathon time in minutes</figcaption></figure><p>I haven’t plotted everything out, but here’s the correlation between each feature and the elapsed marathon time. Naively I’d expect more training in every phase would improve the marathon time, but only activity in the ‘real training’ period has a negative correlation below -0.5. Conversely, a larger mean long run in the ‘sort-of-training’ periods has a positive correlation above 0.5.</p><h3>Step Four— checking for correlations</h3><p>I decided to set up a simple linear regression model — the simplest type of machine learning model that there is. I based the model on the features with correlation of magnitude greater than 0.5 — that’s to say:</p><ul><li>the mean km per week in the ‘real training’ phase</li><li>the mean long runs per week in the ‘sort-of-training’ phase</li><li>the mean long runs per week in ‘real training’ phase</li><li>the temperature on race day</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*H8a_eaA7VVmZxeCZvahV-Q.png" /></figure><p>The figure above shows the results of splitting the dataset (of only 13 points) between a training set (10 points) and test set (3 points), with the actual finish time on the x-axis and the predictions of the model on the y-axis. The green line represents an exact fit, so at first sight the test data point are not far away from the actual values. The root mean square error using these specific sets is 4.9 minutes.</p><p>But to get a better description, we can conduct a cross validation test over five different selections of test and training sets:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*2S7YJI9o1gfO8tJjPT0RRQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*WROf2ki5X7WTccXjKDSPLw.png" /></figure><p>So the mean root mean square error is below 6 minutes, with a standard deviation of 1.13 minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4oU8hcaBDU6rEi0W6gV9dw.png" /><figcaption>Random Strava photo dump 4</figcaption></figure><h3>Step Five— … what should my training plan be next time?</h3><p>Now that we have a model, I can start planning my next marathon project. Ambitiously, I’ll tell the model I will be running 60k per week during the ‘real training’ phase, with an average weekly long run of 25k during that period. During the ‘sort-of-training’ it would seem that over ambitious long runs are detrimental, so I’ve set an average weekly long run of 18k during this period. And I’ll assume a temperature of 15°C on race day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*PtTO9xurF4WjwlgDsUyMHg.png" /></figure><p>And the answer is 178.5 minutes! So the sub-three hour marathon is on after all. I look forward to updating this story with the next data point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*KPgYLmbz2yRpOhCSBHaVfQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yT7kCqsV7ZQcAGk-_2FJOA.png" /><figcaption>Random Strava photo dump 5</figcaption></figure><h3>Reflections on training paces</h3><p>It wasn’t the main part of the exercise, but there’s a lot of emphasis in training programmes on speedwork, and the relative benefits of slow and steady runs. I was interested by a recent Facebook post linking to <a href="https://runningmagazine.ca/sections/training/marathon-lessons-from-molly-seidel-train-slow-to-run-fast/">an article</a> in Canadian Running magazine, in which a data scientist/coach analysed the training routine of accomplished marathon runner Molly Seidal. As per below, he divided her Strava training into different categories, and found that only a very small fraction of her training volume was at 5k pace (which equates to a fast pace for distance runners).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*TKdJG1FfNkExC9Kh4az1Qw.png" /><figcaption>Tweet from Alan Couzens where he categorises the training routine of a top athlete by training pace</figcaption></figure><p>I conducted a similar analysis of my pre-marathon training programme for Barcelona, my most successful marathon. Of course the running pace allocated to each category is much slower than that of Molly Seidel — the y-axis is average distance covered per training week in the twelve weeks leading up to the marathon (the same time frame as Couzens uses above), whereas to sort the training into categories I used a pace equivalent to my target times for a race (always 20 minutes for a 5k, 42 minutes for 10k, 1h30 for a half marathon and 3h10 for a full marathon, regardless of how realistic a target any of these might be). But my training follows an even more unbalanced distribution, with roughly 94% of it falling within the ‘steady’ or ‘easy’ category.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*Uo2zlQ5AseMWgpY7XUVZkw.png" /><figcaption>Categorizing a mean training week of my Barcelona marathon preparations by training pace</figcaption></figure><p>The analysis below plots every training run on a plot of elapsed time (so *including* stops for traffic/water etc.) against distance covered. Clearly the typical pace slows as the distance increases, with the exception of actual races. The outlying points are mostly trail runs, with a lot more climbing and descending, coupled with uneven terrain and navigation, all of which acts to slow the mean pace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*JSmYi73fA_bq6hVIK5S2PQ.png" /><figcaption>Plotting elapsed time versus distance gives an idea of typical training pace (n.b. elapsed time isn’t the same as Strava running time — the latter has pauses removed, so is less realistic)</figcaption></figure><p>I also extracted the GPS tracks from the marathon data (making heavy use of <a href="https://thatmaceguy.github.io/python/gps-data-analysis-intro/">this</a> invaluable resource) to plot out the pace run at different points during the race (I applied a rolling average to smooth out aberrations and so the first and last two km are clipped from the graphs). I suppose what I was interested in seeing here was if clever race day tactics could compensate for inadequate training. At first sight, I would conclude that by race day there’s not much that can be done — I always start at roughly the same pace, of about 4.5 minutes per km. My most successful marathon — Barcelona, is the once race where I manage to maintain this pace throughout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*ARTYfTWbVYNdlxro-ary5Q.png" /><figcaption>A rolling average of the pace run during my different marathon attempts — spot the outlier!</figcaption></figure><h3>Conclusions</h3><p>Well, I’m sure that this hasn’t been the most thorough of exercises. I’m certainly not a sports scientist, though there is insight to be gained from downloading my data from Strava and poking around in it. Of course any insight from this analysis applies to me and me only, and maybe not even that… Here’s a summary of the findings:</p><ol><li>There’s more photos attached to my Strava dataset than I realised, but these are probably the best way to relive the event</li><li>The biggest keys to success in a marathon are a high average distance in the six weeks prior to the race, coupled with a high long run distance in that period, preceded by a lower but still significant average distance in the six weeks before that. Of course, it goes without saying there needs to be some longer term preparation, or I’d likely be injured if I maintained those effort levels leading up to a big race. I suppose this goes to confirm what I already know — distance running, more than almost any activity in life, seems to be a function where outcomes directly relate to long-term effort.</li><li>Speed training doesn’t seem to be a big issue for me, though I suspect if I set my sights higher as to what constituted a ‘speed run’ and so on, I’d be faster overall (though repeat the above point about injury).</li><li>Regardless of the level of preparation I’ll likely start the eventual marathon at the same pace no matter what, but more often than not suffer in the end! Some things never change…</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f110ed7feddb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>