<?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 Caitlin McFink on Medium]]></title>
        <description><![CDATA[Stories by Caitlin McFink on Medium]]></description>
        <link>https://medium.com/@mcdonnell.cait?source=rss-d036bb066e38------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ymYJFMgf0qiLJg2D.</url>
            <title>Stories by Caitlin McFink on Medium</title>
            <link>https://medium.com/@mcdonnell.cait?source=rss-d036bb066e38------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 13:36:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mcdonnell.cait/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 really drives higher life expectancy?]]></title>
            <link>https://medium.com/data-science/what-really-drives-higher-life-expectancy-e1c1ec22f6e1?source=rss-d036bb066e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1c1ec22f6e1</guid>
            <category><![CDATA[development-indicators]]></category>
            <category><![CDATA[health]]></category>
            <category><![CDATA[life-expectancy]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[who]]></category>
            <dc:creator><![CDATA[Caitlin McFink]]></dc:creator>
            <pubDate>Sun, 04 Feb 2018 07:59:14 GMT</pubDate>
            <atom:updated>2018-02-11T18:09:32.392Z</atom:updated>
            <content:encoded><![CDATA[<h3>Machine learning to predict life expectancy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AR3HtlgkpJI1nIqogCzrXQ.jpeg" /></figure><p>We’re in an unprecedented era where humans are living longer and longer (<a href="https://www.washingtonpost.com/national/health-science/us-life-expectancy-declines-for-the-first-time-since-1993/2016/12/07/7dcdc7b4-bc93-11e6-91ee-1adddfe36cbe_story.html?utm_term=.9b347e44271f">although 2015 &amp; 2016 were a scary blip in the otherwise upward trend)</a>. It’s no secret, though, that life expectancy varies widely across the globe.</p><p>As a biomedical engineer, I’ve always attributed living longer with increased access to modern science and healthcare. To test this assumption and understand what actually best predicts life expectancy, I explored country-level data across a subset of the World Health Organizations’s 1,345 development indicators (from 1960- 2015).</p><p>I pared the data down to a subset of indicators that were not only reasonably related to life expectancy, but also representative of the main indicator categories (Economic Policy &amp; Debt; Health; Infrastructure; Poverty; Private Sector &amp; Trade; Public Sector; Social Protection &amp; Labor).</p><p>Of these, the most statistically significant indicators of life expectancy was access to sanitation. Using sanitation alone to predict life expectancy had 77% accuracy and showed that a a one-year increase in life expectancy is associated with every 0.25% of the population with access to modern sanitation facilities.</p><h4>“Up and to the right”</h4><p>Pretty much no matter how the data is cut, life expectancy trends between 1960 and 2015 look like sales projections in a startup pitch deck: up and to the right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vRHtsWkEPIptsycX." /><figcaption><strong>Life span by country income levels: </strong>The gap between high and low income countries is closing</figcaption></figure><p>Classifying countries based on income levels, we can see how economics impact health: a higher income is associated with a longer life expectancy, continuously between 1960 and 2015. High income countries see a steady, but slower, increase in life expectancy; middle income countries experienced large growth in the 1960s and saw a corresponding up-tick in life expectancy. In low income countries, life expectancy gains all but stopped between mid-80s — mid-90s, followed by a strong increase in life expectancy in recent years. Regional groupings (bottom graph) reveal which geographies drove the changes in the 1960 and 1980s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*71ICSiHWCmJJJubO." /><figcaption><strong>Life expectancy by region: </strong>Sub-saharan Africa (red, bottom) has a noticeable plateau in the mid-80s, coinciding with the HIV/AIDs epidemic.</figcaption></figure><p>I pared down the 1.3k development indicators to a representative subset of 21. Running a correlation on these metrics vs. life expectancy provides a quick assessment for relative importance.</p><p>Life expectancy has the highest positive correlation with: sanitation (r = 0.88), GDP per capita (r = 0.698), and health spend per capita (r = 0.63). There’s a strong negative correlation with: % of population in rural areas (r = -0.80) and adolescent fertility (r = -0.77).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/0*0lE-aQ6Z7VoGeyym." /><figcaption>In case you’re new to reading heat maps: A dark red square indicates a high positive correlation between the column &amp; row header; whereas a blue square represents a negative relationship.</figcaption></figure><h4>Machine learning to predict life expectancy</h4><p>To determine which indicators are statistically significant, and to predict life expectancy, I ran a few different models with various combinations of features. This application is a perfect use case for regression, which determines the relationship between one dependent variable (life expectancy) and a number of independent variables (development indicators).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/0*emDZjFFc-oqQbSqn." /><figcaption><strong>Actual vs. predicted ( model) life expectancy: </strong>The model tends to better predict higher life expectancy, and does not preform as well for lower life expectancies (as indicated by wide-spread data in the bottom left).</figcaption></figure><p>Using the entire subset of 21 features was 89.7% accurate, and showed that sanitation and rural population (%) were both statistically significant.</p><p>Even with just these two variables, this model predicts life expectancy with 80.4% accuracy. On average life expectancy is 63 years with a one-year increase for every 0.18% increase in access to sanitation and 0.11% decrease in the percentage of population living in rural areas. Adding healthcare spend to the model only slightly increases accuracy (81%).</p><p><strong>Probing into sanitation</strong>: To dig deeper into how sanitation specifically, I evaluated access to sanitation against statistics on child mortality rates. Not surprisingly, there’s a strong negative correlation between sanitation and mortality: as sanitation improves, mortality rates decrease for neonates, infants, and children under 5.</p><p>Sanitation as the key predictor of life expectancy — specifically child mortality — was unexpected, yet logical. Poor sanitation conditions increase the risk of sharing life-threatening contagions.</p><blockquote><em>According to the </em><a href="http://www.who.int/mediacentre/factsheets/fs330/en/"><em>World Health Organization</em></a><em>, diarrheal disease, the leading cause of death for children under five, is spread by poor sanitation conditions:</em></blockquote><blockquote>‘Diarrhoea is a symptom of infections caused by a host of bacterial, viral and parasitic organisms, most of which are spread by faeces-contaminated water.’</blockquote><p>Once sanitation has been improved in communities, initiatives could address other key indicators of life expectancy (e.g. education, health care, adolescent fertility). And, because sanitation is highly-correlated with childhood mortality, addressing on sanitation first should result in more children who would benefit from additional initiatives.</p><p><a href="https://github.com/gussie/Springboard_data_science/tree/master/Predicting_Life_Expectancy">gussie/Springboard_data_science</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1c1ec22f6e1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/what-really-drives-higher-life-expectancy-e1c1ec22f6e1">What really drives higher life expectancy?</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[To bike or not to bike?]]></title>
            <link>https://medium.com/data-science/sf-bike-share-predictions-e15316ce300f?source=rss-d036bb066e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/e15316ce300f</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-modeling]]></category>
            <category><![CDATA[predictive-modeling]]></category>
            <category><![CDATA[random-forest]]></category>
            <dc:creator><![CDATA[Caitlin McFink]]></dc:creator>
            <pubDate>Sat, 27 Jan 2018 03:39:08 GMT</pubDate>
            <atom:updated>2018-02-11T18:10:20.759Z</atom:updated>
            <content:encoded><![CDATA[<h3>To bike or not to bike? Machine learning to model availability in San Francisco’s bike share program</h3><p>Bike share programs are cropping up in cities across the world, providing flexible transportation for professionals and tourists alike. Bike share systems are commonly built with “docking stations” where users can check out and return bikes. In 2013, San Francisco launched their bike share program which, as of 2015, had 70 stations throughout the city.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0BT-TWw3D50DKAhW6zVHIA.png" /><figcaption>Imagine if cities had communal road bikes like this…!</figcaption></figure><p>Bike share programs offer challenges for both the program owners (cities) and users (riders). For example, cities often manually redistribute bikes between stations to ensure availability of both bikes and docks (slots to return bikes). Cities also need to use rider data to inform where future bike stations should be installed. For users, the main questions is: If I leave home/work now, will there be a bike at the nearest station when I arrive? The uncertainty of bikes at a given station has strong business implications, as unpredictable bike supply can deter ridership and stagnate demand. This project focuses on user challenges of bike availability.</p><p>This project evaluates current ridership trends and predicted bike availability (within 30 minutes of a request) for the San Francisco bike share system. The three main sections of this project include: exploratory data analysis, a simple deterministic model, and two machine-learned models (1 with temporal &amp; commute features, and 1 with the addition of weather data). Of all the features, the greatest predictor of future bike availability is current bikes at the station, followed by week, month, and commute hours. Of the weather features, cloud coverage was the strongest predictor — not a surprise if you’re familiar with San Francisco’s weather!</p><p>The machine learned model with advanced feature engineering out-performed the other two models model, with a false positive rate of 15% and a false negative rate of 0.01%.</p><h3>Data overview</h3><p>The following publicly available data were used (<a href="https://www.kaggle.com/benhamner/sf-bay-area-bike-share/data">source</a>):</p><ul><li>status: minute-by-minute update of the number of bikes and number of docks available for each of the 70 stations</li><li>weather: zip-level daily weather patterns for the SF Bay Area</li><li>station: metadata for each station (n = 70)</li><li>trips: trip-level records, includes date, start/end time, start/end station ID, start/end station name, bike ID, rider subscription type, and trip duration</li></ul><h4>Exploratory data analysis</h4><p>After grouping riders by subscription type (Subscriber: monthly or annual member, and Customer: casual pay-as-you-go rider), I explored seasonal, weekly, and daily ridership patterns. All timeframes highlight distinct patterns for Subscribers vs. Customers, supporting the hypothesis that Subscribers are commuters and Customers are largely tourists.</p><p>Customer ridership peaks in Aug/Sept/Oct and sees a lull around the winter holidays. This could be due to tourism trends or weather influencing whether casual commuters bike (Fall is notoriously San Francisco’s best season, and Winter — when we’re not in drought — is very wet).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UlObkRmiBGEa_9btNkEmBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*gSbRG7HO39KnytuCue4dbw.png" /><figcaption><strong>Daily (2013–2015) </strong>(left): Daily ridership increased since implementation. Customer ridership shows seasonal patterns, peaking in Aug/Sept/Oct and with a lull around the holidays. <strong>Annual</strong> (right): Subscriber ridership dips around holidays: week 22 (Memorial Day), 27 (July 4th), 36 (Labor day), 46/47 (Thanksgiving), &amp; 51/52 (Christmas &amp; New Years). Excluding holidays, ridership increases slightly in the first half of the year, peaking in summer (week 34/35) in ideal bike weather. Customer ridership also increases slightly with local maximum during holidays and a global max during Labor Day; rides start to drop off in the Fall.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ti8jsUb3SPEOPPSHs5YW8Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*NDnQpEa2zjwnn0IRztnFLQ.png" /><figcaption><strong>Weekly </strong>(left): High weekday ridership for Subscribers with a large drop (~1/5) on weekends. Customers have a reverse trend with ~2x rides on weekends vs. the beginning of the week. <strong>Hourly </strong>(right): Subscribers show a distinct bi-modal daily usage pattern, with peaks during AM &amp; PM commute hours, and a small increase during lunch. Customers get a later start (as one does on vacation), with steady usage 11am until the early evening.</figcaption></figure><h4>Assumptions</h4><p>Now that we’ve understood the rough trends of data and user behavior, the next step is to build a simple deterministic model for predicting bike availability. From a rider’s perspective, bike availability is a binary concern: Is a bike available? Yes or no. Thus, a binary classifier is appropriate. Note, from my experience, not all bikes in a bike share system are functional. Therefore, the classifier is adjusted slightly, and all models classify whether there are at least 2 bikes available at a station at a given time.</p><p>We can see in the plots above that different stations exhibit different patterns. Stations in residential areas, for example, see bikes decrease in the morning and increase in the evening. Conversely, stations near offices see the reverse trend. This justifies a simplifying assumption for our predictive models: we can build independent models for each station, thereby explicitly choosing to omit correlations between the behavior of different stations.</p><h4>Data pipeline</h4><p>All three models rely on preprocessing steps such as data filtering, harmonizing / simplifying data types, and feature engineering. To support faster processing and easier recovery from kernel crashes (raw status datafile is 2.5 GB), preprocessing is implemented Python scripts that persist output data. Together, these transformation stages constitute a data pipeline that feed into the models.</p><ol><li>Converts human-readable timestamp into epoch milliseconds.</li><li>Generates a test dataset (for the simple model) where rows satisfy two conditions: (1) day of month is less than given max day of month (e.g. if max_day_of_month &lt;5, returned test set contains the 5 days of each month, ~13%). (2) day of week equals the given day of week in ISO format(day_of_week = 3 since current deterministic model is calculated for Wednesday).</li></ol><p>For both machine learned models (starting with the output from Step 1):</p><ol><li>Adds two new columns (1-appropriate model time; 2-true bike availability for t+30 minutes) for each row in the dataset if the timestamp of the row is within 30-minutes of a specified model time (in array). Otherwise, it drops the row from the dataset.</li><li>Adds the following discretized datetime columns to the dataset: ISO day of week (1–7); ISO month (1–12); Commuter flags as 3 binary columns; non-commute hours (1/0); AM commute (1/0) — status update between 7 and 09:00; PM commute (1/0) — status update between 16 and 18:00.</li><li>Adds the true number of bikes at a station in t+30 mins.</li></ol><h3>Model building</h3><h4>Deterministic model</h4><p>For comparison against the machine learning models we’ll ultimately build, let’s create a deterministic model to calculate a per-station change in bike availability over 30-minute intervals. The change in bike availability is approximated using least squares — which fits a curve that minimizes the sum of the squares of the difference between the dependent variable (bike availability) in the dataset and the value predicted by the linear function (time = x). To build the model, I use daily traffic patterns identified above to define appropriate model times. Based on high demand, the following 30-minute intervals were modeled: Morning (7:30, 8, 8:30, 9AM) &amp; Evening (4, 4:30, 5, 5:30, 6PM). The least squares fit line is calculated for each station, and bike availability predicted as: current bike availability + (slope of least squares line x 30).</p><pre>popt_all_stations = []<br>row_headers = []<br><br><strong>for</strong> i <strong>in</strong> station_ids:<br>    s = station_availability(i, n_bikes= n_bikes, dow= dow)       <br>    popt_single = []<br>    <strong>for</strong> j <strong>in</strong> start_times:<br>        start_time = pd.to_datetime(j)<br>        end_time = start_time + delta<br>        df = s.between_time(start_time.time(), end_time.time())<br>        xdata = df.index.minute<br>        ydata = np.array(df.bikes_available)<br>        popt, pcov = optimization.curve_fit(func, xdata, ydata)<br>        popt_single.append(popt[1])<br>    popt_all_stations.append(popt_single)<br>    row_headers.append(i)<br>    <br><em># reshape model ouput with time as column headers, station as index</em><br>df = pd.DataFrame(popt_all_stations)<br>df.columns = start_times<br>df.index = row_headers<br><br><em># Convert model from minute-by-minute change in bike availabilty --&gt; total change during </em><br><em># model window (e.g. the 16:00 model applies to status updates between 16:00 and 16:29)</em></pre><pre>model = df*29<br>model[&#39;station_id&#39;] = model.index<br>model = pd.melt(model, id_vars = [&#39;station_id&#39;])<br>model.head()</pre><p>I’ll evaluate all models together below.</p><h4>Simple machine learned model</h4><p>The first machine learning model uses simple features, engineered from the status timestamp: day of week, month, commute hours (non-commute, AM, or PM). The pre-processing is performed in the data pipeline — primarily because Jupyter notebook could not handle mapping future bike availability to each row in the status table. As mentioned, for riders the issue of bike availability is binary; riders do not care how many bikes are available, but rather that there is <em>a</em> bike. In this case, we’ll use a Random Forest Classifier, which will help use later tease apart the relative importance of our features.</p><p>The output is one model per station (70); the importance of each model’s features are summarized below. Using .describe(), we’re able to also glean insights into the variance of feature importance across stations. Across the board, current bike availability is the most predictive feature of future bike availability. To a lesser degree, the month and day of week are predictive. Commute times play little importance.</p><pre>pd.DataFrame(feature_imp, columns=X_train.columns).describe()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*63DQHHlygxVAU9Y7wH_T7Q.png" /></figure><h4>Machine learned model 2: Advanced feature engineering</h4><p>Now that we’ve seen a basic machine learning model, the next step is to add more sophisticated features with the hope of improving model performance. In particular, various aspects of weather (e.g. temperature, precipitation) are key determinants when commuters select their mode of transportation. In the next models we’ll pull in a host of daily weather features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*gHJDmfpnzRRFat0Y0jECGg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*lo5X2Gl4sLuzEQjkm9L7uA.png" /><figcaption>Could temperature and wind speed help predict bike demand? There are clear seasonal patterns that could feasibly drive bike usage.</figcaption></figure><p>As with the first ML model, this model is station-specific. For a quick comparison, the weather-augmented model is created for a single station — station #2.</p><p>The feature importance method for random forest shows the relative importance for the features in the weather-augmented model (i.e. both the original ML model features, as well as the additional new weather features). We see that current bike availability is still far and beyond the best predictor of future bike availability. Day of week, AM commute, and non-commute hours are also decently important features from the original model. Of the newly-added weather features, cloud cover is the most important feature, followed by max dew point, min dew point, and max humidity. In a city with unpredictable weather and notorious cloud cover (I’m looking at you, Karl), it’s no surprise that cloud cover impacts bike ridership (and therefor bike availability).</p><p>*In case you’re not familiar with San Francisco, the daily fog is so intense and routine in summer, that it is fondly referred to as Karl.</p><h3>So which one is “better”?</h3><p>To answer this question, we must agree on how to appropriately evaluate the models. Accuracy, a common default evaluation metric, won’t fly here due to severe class imbalance (e.g. one class has a clear majority in the data). Only a small subset of the bike stations do not have sufficient bike availability during model times. In fact 96.6% of the stations have bikes available during the given time periods. Therefore, a classifier that predicted ALL stations have available bikes all the time would have 96% accuracy… but this would be a horrible classifier. A confusion matrix provides better metrics for assessment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*c0CEWH_RgvHVk60ToQNpGw.png" /><figcaption>Confusion matrix</figcaption></figure><p>From a rider’s perspective one of the most important metrics is false positive rate: the ratio of false positives (number of negative events wrongly categorized as positive) and total number of actual negative events. In other words: If a model says a bike will be available in 30 minutes, will there actually be a bike when the users arrive?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*ARcTZp0Y3ghCjH_3srSr9A.png" /><figcaption>Comparison of evaluation metrics for all three models (2 machine learned models, and one simple deterministic model).</figcaption></figure><p>For the most important metrics for users — false positive rate and false negative rate — both machine learned models outperforms the simple deterministic model. Specifically, the weather-augmented random forest model is far superior to the simple model in terms of false positive rate (one-third of the simple model’s FPR) and false negative rate (0.01% vs. 0.66% for the simple model).</p><h3>Possible extensions</h3><p>Beyond running additional machine learning classifiers (e.g. SVM, logistic regression) for comparison, this dataset holds rich potential for further feature engineering, including:</p><ul><li>Historical rate of change of bikes availability (e.g. slope of least-squares line as with simple model)</li><li>Number of rides started / ended at the station in the previous x-minute window — providing insights into station popularity otherwise lost in the station status update (e.g. if 1 trip starts at Station A as another trip ends at Station A, the number of bikes available would be static)</li><li>Trip start/end time popularity (e.g. use the first derivative to find local max &amp; min number of trips)</li><li>Mapping zip-level daily weather data with each station, rather than the Bay Area mean.</li></ul><p><a href="https://github.com/gussie/Springboard_data_science/tree/master/Bike_share_availability_classifier">gussie/Springboard_data_science</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e15316ce300f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/sf-bike-share-predictions-e15316ce300f">To bike or not to bike?</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>