Can you build a model to help you choose an AirBnb Room in Seattle?
By: Bruno Do Val
Tags: Python, Pandas, Airbnb, Scikit Learn, Udacity Nanodegree

We will work our way into the model answering three business questions:

1 — When is the most expensive season to rent a place in Seattle? Are the prices going up in general?

2 — What are the characteristics of the room available in Seattle?

3 — Can we predict the pricing of the accommodation based on parameters that the user can input before looking at each listing?

You can check all the files used in this analysis and the Jupyter Notebook with the python 3.x program also used in my git repository in https://github.com/bruno-doval/Project-1/blob/main/project-1.ipynb

The data

The first step will be to take a look at the data by assuring that the format is adequate to be used in the analysis. Basically the columns that are numbers are configured to be “int’s” and “float’s” and the columns that have dates on it are to be put in datetime format.

Here is an example of the calendar’s file with the data already cleaned:

calendar file

In the calendar dataset we have from jan-2016 to jan-2017 the listings in Seattle, their price and if they are available or not.

In the listing dataset we can see the characteristics of the properties such as size, location, price, information about the host, etc.:

The first rows and columns in the listing dataset

Analysis 1: Listing Prices throughout the year

Tourism is known to be subject to seasonality, but how was the average pricing of Seattle during the year of 2016?

Using the calendar DataFrame (named cal) imported in python through Pandas and plotting the matplotlib library we have:

cal.groupby(['date']).agg({'price':'mean'}).plot()

Daily average prices in Seatle

We can also remove the weekly seasonality by plotting the rolling average of the prices in a seven day window:

cal.groupby(['date']).agg({'price':'mean'}).rolling(window=7).mean().plot()

Weekly average prices in Seattle

From this imagens we can conclude that the most expensive times to rent a room in Seattle are between the months of July and September.

Also, is important to notice that the prices are generally going up if we compare the months of January of 2016 and 2017. In the beginning of 2016 they were about 120 dollars and by the and of the year they were trending up to 140 dollars.

Analysis 2: Listing’s characteristics

Using the listing DataFrame we are now going to take a look in what kind of room there were in Seattle using the scrapped data from Jan-4th of 2016.

K ind of property available:

listing.groupby('property_type').count().sort_values(by='id',ascending=False).id.plot.bar()

Quantity of Listings per Property Type

listing.groupby('room_type').count().sort_values(by='id',ascending=False).id.plot.bar()

Quantity of Listings per Room Type

The Seattle’s listings are mostly Apartment’s or Houses with the entire property available.

Location of the property:

listing.groupby('neighbourhood_group_cleansed').count().sort_values(by='id',ascending=False).head(15).id.plot.bar()

plt.ylabel("# of listing")

Quantity of Listing per Neighbourhood

The busiest neighborhoods are Capitol Hill, Downtown and the Central Area.

listing.groupby('neighbourhood_group_cleansed').mean().sort_values(

by='price',ascending=False).head(15).price.plot.bar()

plt.ylabel("Avg Price ($)")

Average Price per Neighbourhood

The most expensive neighborhoods are Magnolia, Queen Anne and Downtown

Lastly we can see the location (using the average Latitude an Longitude of the listing) of the most expensive neighborhoods:

fig, ax = plt.subplots()

plt.scatter(price_heat_map.latitude,

price_heat_map.longitude,

c=price_heat_map.price,

) for i in price_heat_map.iterrows():

ax.annotate(i[1].neighbourhood_group_cleansed,(i[1].latitude,i[1].longitude)) plt.colorbar()

plt.show()

Neighborhood price in a Map

The most expensive neighborhoods are located close to the downtown area and to the south form it, whereas the cheapest ones are further to the north, west and east.

Analysis 3: The linear model

What are the factors that define price?

Let’s take a look at the correlation between the numeric values in the listing DataFame:

fig, ax = plt.subplots(figsize=(15,15))

sns.heatmap(listing[numeric_listing].corr(), annot=True, fmt=".2f")

correlation matrix

We van see here that the price is more correlated to the size related factors such as square feet, number of rooms, beds, bathrooms — witch is intuitive, but we know that location also plays a great role in pricing.

So, for this model we will consider the following columns, assuming that they can be know beforehand by the user to apply this model and predict the price he or she is going to pay:

['latitude',

'longitude',

'accommodates',

'bathrooms',

'bedrooms',

'beds',

'square_feet',

'price',

'guests_included',

'extra_people',

'minimum_nights',

'maximum_nights',

'review_scores_value',

'host_is_superhost',

'neighbourhood_group_cleansed',

'host_has_profile_pic',

'host_identity_verified',

'property_type',

'room_type',

'bed_type',

'instant_bookable',

'cancellation_policy',

'require_guest_profile_picture',

'require_guest_phone_verification']

Using the test/train method in scikit learn (available in my github repo) we were able to predict the price with de R square of 0.58 in the train data and 0.60 on the test data.

Conclusion

We have gained much more understanding of the Seattle market in 2016. We now know the hot season for the prices, where are the neighborhoods that have more listings and at what price.

We have also build a model to predict pricing based on what a person would be looking for in a room and this model predicted the price with an R squared of 0.6 — witch is not so great, but is coherent with the few parameters used on this research.

If you have any questions check my repository or send me a comment here on medium.

Thank you for you attention!