<?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 Joe Bender (jazzathoth) on Medium]]></title>
        <description><![CDATA[Stories by Joe Bender (jazzathoth) on Medium]]></description>
        <link>https://medium.com/@iv.been.joe?source=rss-3b40836030bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Zip5uC1sbfNGsnv2.jpg</url>
            <title>Stories by Joe Bender (jazzathoth) on Medium</title>
            <link>https://medium.com/@iv.been.joe?source=rss-3b40836030bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 15:36:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iv.been.joe/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[Growing a Decision Tree:]]></title>
            <link>https://medium.com/@iv.been.joe/growing-a-decision-tree-f0514d43a0ca?source=rss-3b40836030bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0514d43a0ca</guid>
            <category><![CDATA[predictive-analytics]]></category>
            <category><![CDATA[lambda-school]]></category>
            <category><![CDATA[decision-tree]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Joe Bender (jazzathoth)]]></dc:creator>
            <pubDate>Sat, 25 May 2019 23:07:29 GMT</pubDate>
            <atom:updated>2019-05-25T23:07:29.242Z</atom:updated>
            <content:encoded><![CDATA[<p><em>The Tanzania Water Pumps project.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*91Fjm1tyXAvnzr-LyAC3oA.jpeg" /></figure><p><em>~~Insights and lessons on modeling with decision trees in Lambda School’s Tanzania Water Pumps project, from a data scientist in training.~~</em></p><h4>Intro:</h4><p><em>~or~ I’m starting to feel like a real Data Scientist.</em></p><p>My cohort at Lambda School just participated in a Kaggle Competition for a final unit project. For most of us, this was our first experience in the sport of competitive data science that is Kaggle. and was just the ‘good learning experience’ that the folks at Lambda School intended. The process of modeling over and over again this week gave me a much more intuitive sense of how to approach predictive modeling, and the nuances of decision trees.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D2GSh_VWd4wHh2LfvE9DfQ.png" /><figcaption>Pump functionality by age and location.</figcaption></figure><p>For this project, we were challenged to predict water pump failures in rural Tanzania using a set of data consisting of just about every feature of water pumps that some bureaucrat at the UN could think of. The Data only contained a few useful numeric features from the outset: GPS coordinates, and the quantity of water available. Most of the remaining were string categoricals.</p><p>My background experience is in the hard sciences (physics in particular) and I have experience working with most of the classic mathematical regressions. The data set for this challenge stubbornly refuses to be brought to heel by any such neat, orderly means. As can be seen in the above plots, there are patterns, but none of them follow smooth differentiable curves without weeks of feature engineering.</p><h4>Baselines:</h4><p><em>Planting your tree:</em></p><p>Before we start growing our tree, we need somewhere to plant it: A baseline, the dumbest, simplest prediction possible. Predict the majority. In this case there were three possible states for a pump. ‘Broken — not pumping’, ‘Broken still pumping’, and ‘Working — pumping water and doesn’t need fixing.’ My baseline of “they are all working” got about 55% accuracy. That is the lowest you should ever see, the ground, the floor. It’s all up from here. If your tree isn’t doing at least this well, something is terribly wrong. Pull it up by the roots, light it on fire and start over.</p><h4>The Workflow:</h4><p><em>‘Gardening’</em></p><p>Tree based models are aptly named. I found that the analogy goes well beyond their structure. The entire process of developing a tree based model can be compared to gardening or tending an orchard. I start out with a simple tree, a sapling if you will, limited in size to run quickly. I feed it lots of features, with simple encoding schemes, looking for patterns. Then I begin to prune. Remove features, do b, and improve my accuracy. When I’ve reached a plateau on accuracy, I begin engineering, encoding and adding in features again, and repeat the cycle.</p><h4>Overfitting:</h4><p><em>Letting it grow wild:</em></p><p>Another useful, if time consuming tactic is to give your tree space to grow and just see what happens. Searching for the best hyperparameters via sklearn’s RandomSearchCV method, I would open up the number of estimators (10 to 300) and max depth (2 to 50) and let it run about 200 different combination. This took took somewhere in the neighborhood of an hour and a half with the fans on my workstation screaming and the processors maxed out. This will almost inevitably overfit, but it provides a useful starting point and makes sure you are not missing anything important. I did this somewhere around my third or fourth ‘gardening cycle.’</p><h4>Getting Focused:</h4><p><em>Pruning:</em></p><p>Just like a real fruit tree, pruning your model back is an important part of the cycle, as the complexity inevitably gets out of control. I found the Shapley explainer plot of feature importance to be incredibly helpful in the latter part of my model’s development. Early on in the process, I discovered that most feature engineering beyond encoding wrecked my accuracy and confused my trees. I probably made over one hundred explainer plots, and was able to discover that outliers in water quantity and age was being adversely effected by outliers and water quantity numbers were too close together for the tree model’s liking. I compressed age by taking the log and squared water quantity, and improved my accuracy by an entire percentage point. This was the only time feature engineering produced a positive result, and proved the value of looking for patterns in feature importance.</p><p><em>~Explainer plot example:~</em></p><p>Below are feature importance plots for a correctly predicted pump that was “Working but needs repair”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*KOhZwZcpw1LV02LFSrCwIw.png" /><figcaption>Feature importance for predicted probability of “Working “</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*-pOht2Dyn-yldAnMSTK4Eg.png" /><figcaption>Feature importance for predicted probability of “Working but needs repair”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*Cckvba68_RyMWrdiT41yUA.png" /><figcaption>Feature importance for predicted probability of “Broken”</figcaption></figure><h4>Making Predictions:</h4><p><em>Harvest Time!</em></p><p>There are many ways of measuring performance of your model, which are by no means specific to decision trees. Since this data needed classification, accuracy is the easiest, but in the circumstances (broken water pumps in Tanzania), considerations over which pumps to check include labor availability, geographic location, effectiveness of the repairs, and even the utility of the pump in question to the local population. In any case, the tree will return probabilities of each class for the predicted sample. The threshold probability for answering the question “should we send out a repairman” can be set constant or controlled by other factors from the data, as previously mentioned.</p><h4>Other Insights:</h4><p><em>~or~ What a Tree Wants.</em></p><p>As mentioned earlier, I am more familiar with classic regressions. Modeling with decision trees, I had to learn to think about them in a completely different way. For instance in a linear or logistic regression model, you would need to be very careful with any ordinal encoding, as any numeric label will be treated as an ordinal feature. Even binary encoding needs to be done wisely because the category encoded as 1 is treated as ‘greater’ than 0. This is much less important to a tree. Unintentional ordinality can certainly be picked up as noise, but a well pruned tree should filter it out. Missing values can also be treated differently. If there is a useful pattern to the missing values, I just assigned them a distinct value from the rest of the data (usually 1 or 2 standard deviations from max- or minimum) and the tree will pick them out. Assigning them to the mean or median is usually counterproductive.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0514d43a0ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>