<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/tree-troubles-predicting-sidewalk-damage-resulting-from-trees-in-nyc/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.nycdatascience.com/student-works/capstone/tree-troubles-predicting-sidewalk-damage-resulting-trees-nyc/"> R – NYC Data Science Academy Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>Introduction</h2>
<p>Tree roots growing under sidewalks often cause cracking or lifting of the pavement once the tree surpasses a certain size. This creates significant tripping hazards for pedestrians, and liability issues for property owners. Furthermore, the cost of repairing such damage is in excess of <a target="_blank" rel="nofollow" href="http://joa.isa-arbor.com/request.asp?JournalID=1&ArticleID=3047&Type=2">$100 million per year in the United State</a>s. As such, this project seeks to:</p>
<ul>
<li>Predict the likelihood that a particular tree will result in sidewalk damage.</li>
<li>Elucidate the factors most involved in causing such damage.</li>
<li>Develop application to help recommend trees species and other steps to reduce the likelihood of future sidewalk damage.</li>
</ul>
<h2>Dataset</h2>
<p>In <a target="_blank" rel="nofollow" href="https://data.cityofnewyork.us/Environment/2015-Street-Tree-Census-Tree-Data/pi5s-9p35/data">2015 NYC</a> conducted volunteer-powered campaign to map, count, and care for all of the city’s street trees. This dataset consist of:</p>
<table>
<tbody>
<tr>
<td>
<ul>
<li>432,564 Live Tree</li>
<li>14,099 Dead Tree</li>
<li>40% Sidewalk Damage</li>
<li><a target="_blank" rel="nofollow" href="https://www.portlandoregon.gov/trees/?c=59508&a=424017">Average DBH</a> of 11.6 inches</li>
<li>132 Different Species</li>
</ul>
</td>
<td><img src="https://i1.wp.com/www.nycgovparks.org/pagefiles/90/independent-mappers-390.jpg?w=456&ssl=1" data-recalc-dims="1"></td>
</tr>
</tbody>
</table>
<p><span>The ultimate dataset consisted of the following features “tree_id”, “year”, “tree_dbh”, “health”, “spc_latin”, “spc_common”, “root_stone”, “root_grate”, “root_other”, “trunk_wire”, “address”, “zipcode”,  “boro_name”, “longitude”, “latitude”, “block_code”, “sidewalk”. Details on these terms can be found at the dataset link above. </span></p>
<h2>Technology Pipeline</h2>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/tech_pipeline-1.png"><img sizes="(max-width: 684px) 100vw, 684px" alt="tech_pipeline" class="wp-image-17899" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/tech_pipeline-1.png?resize=456%2C193" data-recalc-dims="1"></a></p>
<p>The technology employed is a mixture of Python, R, and Java. Python scripts are used for performing data cleaning and merging, as well as web scraping tree species data from <a target="_blank" rel="nofollow" href="http://leafsnap.com/">leafsnap.com</a>. R scripts are used for performing numerical and visual EDA and for running machine learning algorithms.  For the desktop analysis application and to generate heatmaps (see below), Java is used.  Java will also be used to develop a mobile application.</p>
<h2>Visual Overview Of Data</h2>
<p><a target="_blank" rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/trees_tree_dbh.png"><img sizes="(max-width: 1024px) 100vw, 1024px" alt="trees_tree_dbh" class="wp-image-17900" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/trees_tree_dbh-1024x484.png?resize=456%2C216" data-recalc-dims="1"></a></p>
<p>In order to quickly check for a relationship between tree diameter and sidewalk damage a heatmap is generated by sorting the data by increasing diameter (from 3 to 70 inches). The magenta color represents the different species of trees. The red and greens pixels represent “damage” or “no damage” to the sidewalk respectively. One key takeaway here is that there isn’t an obvious relationship between sidewalk condition and tree diameter. Another take away is that even though there are 132 tree species in the dataset, only a small number make up most of the trees planted (see bar plot below).</p>
<p><a target="_blank" rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/barplot.png"><img sizes="(max-width: 659px) 100vw, 659px" alt="barplot" class="wp-image-17901" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/barplot.png?resize=456%2C244" data-recalc-dims="1"></a></p>
<h2>Variable Association</h2>
<p>The associations between the predictor variables in the dataset and sidewalk condition is also compared using either a <a target="_blank" rel="nofollow" href="https://www.r-bloggers.com/example-8-39-calculating-cramers-v/">Cramers V</a> function or the <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/ICC/ICC.pdf">ICC package</a> in R.  The strength of association ranges from 0 to 1, with a value of 1 indicating perfect association between two variables.</p>
<p><a target="_blank" rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/association-1.png"><img sizes="(max-width: 681px) 100vw, 681px" alt="association" class="wp-image-17903" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/association-1.png?resize=456%2C203" data-recalc-dims="1"></a></p>
<h2>Clustering (Unsupervised Learning)</h2>
<p><span>Clustering was done by first generating a dissimilarity matrix using the “<a target="_blank" rel="nofollow" href="https://stat.ethz.ch/R-manual/R-devel/library/cluster/html/daisy.html">gower</a>” distance, then using the “<a target="_blank" rel="nofollow" href="https://stat.ethz.ch/R-manual/R-devel/library/cluster/html/pam.object.html">pam</a>” function to find the best number of clusters. Using sample datasets (1000 obs) containing all the geolocation related features (i.e. address, zipcode, boro name, longitude, latitude), the optimal number of clusters found is 6. These clusters more or less corresponds to the boro the trees are located in. See image below.<a target="_blank" rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/cluster_6.png"><img sizes="(max-width: 684px) 100vw, 684px" alt="cluster_6" class="wp-image-17904" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/cluster_6.png?resize=456%2C192" data-recalc-dims="1"></a></span></p>
<p><span>Removing all geolocation related features, with the exception of longitude and latitude, the optimal number of cluster is now found to be 2 which corresponds to the sidewalk condition of either damage or not damaged.</span></p>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/cluster_2.png"><img sizes="(max-width: 954px) 100vw, 954px" alt="cluster_2" class="wp-image-17905" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/cluster_2.png?resize=456%2C141" data-recalc-dims="1"></a></p>
<h2>Classification (Supervised Learning)</h2>
<p>The <a target="_blank" rel="nofollow" href="http://topepo.github.io/caret/index.html">R Caret package</a> was used to run various machine learning classification algorithms on full dataset using the typical 80/20 (train/test) split validation method. The accuracy results are outlined below.</p>
<ul>
<li>Logistic Regression
<ul>
<li>GLM: 75.8%</li>
<li>GLMNet: 75.8%</li>
</ul>
</li>
<li>KNN: 76.9%</li>
<li>Naive Bayes: 73.2%</li>
<li>Tree Based Classification
<ul>
<li>GBM: 77.3%</li>
<li>XGBoost: 77.9%</li>
</ul>
</li>
<li>SVM (radial kernel): 77.1%</li>
<li>Neural Net: 77.4%</li>
</ul>
<p>Overall, the accuracy results for these algorithms was fairly close and given the nature of the problem, simple the Logistic Regression models were found to be well suited for use in the analysis application described below.  As for what features are most important in determine sidewalk damage, both the tree based and logistics regression models are in overall agreement that having blocks around the trees (root_stone), tree diameter, and location play important roles.<a target="_blank" rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/fimportance.png"><img sizes="(max-width: 994px) 100vw, 994px" alt="fimportance" class="wp-image-17906" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/fimportance.png?resize=456%2C157" data-recalc-dims="1"></a></p>
<h2>Analysis Application “NYC Tree Insights”</h2>
<p>In order to make the models useful for use by non technical users, a desktop applications that performs analysis on the “dead trees” data to predict the potential for sidewalk damage at various years (10, 20, 30, 50, 75) in the future is has been developed.</p>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/application1-1.png"><img sizes="(max-width: 1024px) 100vw, 1024px" alt="application1" class="wp-image-17908" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/application1-1-1024x579.png?resize=456%2C258" data-recalc-dims="1"></a></p>
<p>Additionally, the application also allows for rapid visual analysis by making use of bar plots and links to Google Maps to view the area and even the dead tree in question.</p>
<p><a target="_blank" rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/application2-1.png"><img sizes="(max-width: 1024px) 100vw, 1024px" alt="application2" class="wp-image-17910" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2016/12/application2-1-1024x481.png?resize=456%2C214" data-recalc-dims="1"></a></p>
<h2>Conclusion</h2>
<p>By making use of the NYC 2015 Tree Census dataset, a classification model, with an accuracy of over 75% in predicting root induced sidewalk damage was developed.  Moreover, a Java based desktop application was developed around this model to help stake holders assess the likelihood sidewalk damage in the future if a certain species of tree is planted at a particular location.  The next steps for this project are:</p>
<ul>
<li>Migrate machine learning backend to Amazon services</li>
<li>Create web application</li>
<li>Create mobile application</li>
</ul>
<p>The post <a target="_blank" rel="nofollow" href="http://blog.nycdatascience.com/student-works/capstone/tree-troubles-predicting-sidewalk-damage-resulting-trees-nyc/">Tree Troubles — Predicting Sidewalk Damage Resulting From Trees In NYC</a> appeared first on <a target="_blank" rel="nofollow" href="http://blog.nycdatascience.com/">NYC Data Science Academy Blog</a>.</p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.nycdatascience.com/student-works/capstone/tree-troubles-predicting-sidewalk-damage-resulting-trees-nyc/"> R – NYC Data Science Academy Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/kxLW42E9F8s"></a></div>