GreenBuildings1

# GreenBuildings 1: Exploratory Analysis & Outlier Removal¶

1. Introduction

2. Exploratory Data Analysis

3. Connecting To BigQuery

4. Removing Visual Outliers

5. Removing Outliers With Isolation Forests

6. Recomendations & Next Steps

## Introduction ¶

I started this project a while back with a goal of taking the 2016 NYC Benchmarking Law building energy usage data and do something interesting with it. I originally attmpted to clean and analyze this data set to try to find ways to reduce builings' energy usage and subsequently their green house gas emissions. After a few iterations I thought it might be interesting to see if I could predict the emission of green house gases from buildings by looking at their age, energy and water consumption as well as other energy consumption metrics. This is somewhat of a difficult task as the data was very messy and in this first blogpost I will cover how to perform,

• Exploratory data analysis
• Identify and remove outliers

Since I will completing this project over multiple days and using Google Cloud, I will go over the basics of using BigQuery for storing the datasets so I won't have to start all over again each time I work on it. At the end of this blogpost I will summarize the findings, and give some specific recommendations to reduce mulitfamily and office building energy usage. The source code for this project can be found here.

### Data¶

The NYC Benchmarking Law requires owners of large buildings to annually measure their energy and water consumption in a process called benchmarking. The law standardizes this process by requiring building owners to enter their annual energy and water use in the U.S. Environmental Protection Agency's (EPA) online tool, ENERGY STAR Portfolio Manager® and use the tool to submit data to the City. This data gives building owners information about a building's energy and water consumption compared to similar buildings, and tracks progress year over year to help in energy efficiency planning.

Benchmarking data is also disclosed publicly and can be found here. I analyzed the 2016 data and my summary of the findings and recommendations for reducing energy consumption in New York City buildings are discussed in the conclusions post.

The data comes from the year 2016 and is quite messy and a lot of cleaning is necessary to do analysis on it. The cleaning process was made more difficult because the data was stored as strings with multiple non-numeric values which made converting the data to its proper type a more involved process. One thing to keep in mind through out this post is that this is self-reported data, meaning our data is mostly biased, containinig outliers. Therefore, I will go over a few techniques for removing outliers in post.

## Exploratory Data Analysis ¶

Since the cleaning was more tedious I created external functions do handle this processes. In addition, I also created functions to handle transforming and plotting the data. I kept these functions in seperate files Cleaning_Functions.py and Plotting_Functions.py respecively so as to not clutter the post. We import these functions along with other basic libraries (Pandas, Matplotlib and Seaborn) as well as read in the data file below:

Here is we specifify a few datatypes as integers while reading in the Excel using the read_excel function from Pandas

There are about 13,233 buildings with different types of energy usage, emissions and other information. I'll drop a bunch of these features and only keep the following,

• Reported NYC Building Identification Numbers : [BINs]
• NYC Borough, Block and Lot : [BBL]
• Street Number : [Street_Number]
• Street Name : [Street_Name]
• Zip Code : [Zip_Code]
• Borough : [Borough]
• Year Built : [Year_Built]
• DOF Benchmarking Status :[Benchmarking_Status]
• Site EUI (kBtu/ft$^{2}$) : [Site_Eui]
• Natural Gas Use [N(kBtu) : [Nat_Gas]
• Electricity Use (kBtu): [Elec_Use]
• Total GHG Emissions (Metric Tons CO2e) : [GHG]
• ENERGY STAR Score : [Energy_Star]
• Water Use (All Water Sources) (kgal) : [Water_Use]

The terms in the square brackets are the column names used in the dataframe. In addition, we must do some basic feature engineering. The reported data gives us the metrics (NAT_Gas, Elec_Use, GHG, Water_Use) in terms of total volume. Using these metrics in comparing buildings of different sizes is not a fair comparison. In order to compare them fairly we must standardize these metrics by dividing by the square footage of the buildings giving us each metrics' intensity. We therefore have the following features,

• Nautral Gas Use Intensity (kBtu/ft$^{2}$) : [NGI]
• Electricty Use Intensity (kBtu/ft$^{2}$) : [EI]
• Water Use Intensity (kga/ft$^2$) : [WI]
• Total GHG Emissions Intensity (Metric Tons CO2e / ft$^2$) : [GHGI]
• Occupancy Per Square Foot (People / ft$^2$) : [OPSQFT]
• Age (years)

I wrote a basic function called initial_clean(). to clean the data create the additional features. We call it on our dataset and then get some basic statistics about the data:

The above table is only a summary of the numrical data in the dataframe. Just looking at the count column we can immediately see that there are a lot of missing valus in this data. This tells me that this data will be rather messy with many columns having NaNs or missing values.

It also looks like there is a lot of variation within this dataset. Just looking at the Site_EUI statistic, the 75th percentile is is 103 (kBtu/ft²), but the max is 801,504.7 (kBtu/ft²). This probably due to the number of different types of buildings in the city, as well as the fact that contains outliers.

The next thing I would like to see is how many of the buildings in NYC are passing the Benchmarking Submission Status:

Most buildings are in compliance with the Department of Finance Benchmarking standards. Let's take a look at the violators:

There's not much we can learn from this, if we can look to see if certain zip codes have more buildings in violation. First thing we do is group by the zip codes and count them to get the number of violations per zip code:

Now we want to visualize the the number of violators per zip code. To make things interesting we will create an interactive choropleth map using the Bokeh Library. Bokeh is a great vizualization tool that I have used in the past. We get the shapes for New York City zip codes as a geojson file from this site. The geojson file can be read into a dataframe using GeoPandas.

We can see the basic contents of the GeoPandas dataframe:

I noticed only a few of the zipcodes had actual names, so I wrote a script (GetNeighborhoodNames.py) to scrape this website to obtain each neighborhood's name. I pickled the results so we could use them here:

We can attach them to our GeoPandas dataframe by joining them (on zip code),

Next, we'll left join our count of violators-per-zipcode zips_df to above dataframe and fill in the zip codes that do not have violations with zeros:

Now before we can use Bokeh to visualize our data we must first convert the GeoPandas dataframe to a format that Bokeh can work with. Since I already covered this in a previous blog post I won't go over the details, but here I used a slightly modified version of the function from that post:

Next we set bokeh io module to be in the notebook and use the function I wrote make_interactive_choropleth_map to create the in-notebook zipcode choropleth map: