Samvel Kocharyan
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
Sign up
Beta
Spinner

Analysis: Samvel Kocharyan

https://www.linkedin.com/in/samvelkoch/
2022, [email protected]

Which tree species should the city plant?

📖 Background

You work for a nonprofit organization advising the planning department on ways to improve the quantity and quality of trees in New York City. The urban design team believes tree size (using trunk diameter as a proxy for size) and health are the most desirable characteristics of city trees.

The city would like to learn more about which tree species are the best choice to plant on the streets of Manhattan.

💾 The data

The team has provided access to the 2015 tree census and geographical information on New York City neighborhoods (trees, neighborhoods):

Tree Census
  • "tree_id" - Unique id of each tree.
  • "tree_dbh" - The diameter of the tree in inches measured at 54 inches above the ground.
  • "curb_loc" - Location of the tree bed in relation to the curb. Either along the curb (OnCurb) or offset from the curb (OffsetFromCurb).
  • "spc_common" - Common name for the species.
  • "status" - Indicates whether the tree is alive or standing dead.
  • "health" - Indication of the tree's health (Good, Fair, and Poor).
  • "root_stone" - Indicates the presence of a root problem caused by paving stones in the tree bed.
  • "root_grate" - Indicates the presence of a root problem caused by metal grates in the tree bed.
  • "root_other" - Indicates the presence of other root problems.
  • "trunk_wire" - Indicates the presence of a trunk problem caused by wires or rope wrapped around the trunk.
  • "trnk_light" - Indicates the presence of a trunk problem caused by lighting installed on the tree.
  • "trnk_other" - Indicates the presence of other trunk problems.
  • "brch_light" - Indicates the presence of a branch problem caused by lights or wires in the branches.
  • "brch_shoe" - Indicates the presence of a branch problem caused by shoes in the branches.
  • "brch_other" - Indicates the presence of other branch problems.
  • "postcode" - Five-digit zip code where the tree is located.
  • "nta" - Neighborhood Tabulation Area (NTA) code from the 2010 US Census for the tree.
  • "nta_name" - Neighborhood name.
  • "latitude" - Latitude of the tree, in decimal degrees.
  • "longitude" - Longitude of the tree, in decimal degrees.
Neighborhoods' geographical information
  • "ntacode" - NTA code (matches Tree Census information).
  • "ntaname" - Neighborhood name (matches Tree Census information).
  • "geometry" - Polygon that defines the neighborhood.

Tree census and neighborhood information from the City of New York NYC Open Data.

# Setup 
import pandas as pd
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import missingno as msno
trees = pd.read_csv('data/trees.csv')
trees
neighborhoods = gpd.read_file('data/nta.shp')
neighborhoods

💪 Challenge

Create a report that covers the following:

  • What are the most common tree species in Manhattan?
  • Which are the neighborhoods with the most trees?
  • A visualization of Manhattan's neighborhoods and tree locations.
  • What ten tree species would you recommend the city plant in the future?

Methodology:

  1. Understand quantitative statistics in the dataset (such as the Top10 species and neighborhoods, etc).
  2. Estimate the condition of trees using available data (including numerical and categorical features).
  3. Create a custom metric to estimate species.
  4. Conduct a study on a stratified sample.
  5. Select the Top15 species based on the created metric.
  6. Compare the intersections of sets: recommended Top15 versus real Top10.
  7. Involve a subject matter expert (SME) to reduce the recommended Top15 species to a Top10 based on species characteristics not considered in the original set (such as compatibility, impact on natural balance, climate suitability, soil conditions, space constraints, ornamental value, wildlife habitat, and natural balance).
# 'spc_common'will be used a lot here. Let's fix it style with Capitalisation

trees['spc_common'] = trees['spc_common'].str.capitalize()
# There are empty cells in 'spc_common' and 'health' labels. And what is the type of that missingness? 

msno.matrix(trees)
plt.show()
# MNAR (Missingness Not At Random) is obvious in 'spc_common' and 'health' labels. 
# But missingness correlation will should approve that as well. 
# Wow... 1 is perfect. 

msno.heatmap(trees)
plt.show()
Hidden output
# Let's have a look at those rows with missing data. 

missing_trees = trees[trees["spc_common"].isnull()]

missing_trees.head()
# Aghhh... Just a dead trees. How many dead trees in the census? 

dead_trees = trees[trees["status"] == 'Dead']
print(dead_trees.shape)

Dead can dance... Or no?

‌
‌
‌
  • AI Chat
  • Code