Machine Learning News Hubb
Advertisement Banner
  • Home
  • Machine Learning
  • Artificial Intelligence
  • Big Data
  • Deep Learning
  • Edge AI
  • Neural Network
  • Contact Us
  • Home
  • Machine Learning
  • Artificial Intelligence
  • Big Data
  • Deep Learning
  • Edge AI
  • Neural Network
  • Contact Us
Machine Learning News Hubb
No Result
View All Result
Home Artificial Intelligence

How to Find an Apartment with a Short Commute | by Dávid Guszejnov | Mar, 2023

admin by admin
March 12, 2023
in Artificial Intelligence


A guide on how to make a customized commuter’s map of your home city using data science and Google Maps API

Last year I got a job in Massachusetts at the Center for Astrophysics in Cambridge. When looking for nearby apartments, one of my key requirements was that it shouldn’t take too long to commute to work. Since Boston has a fairly built up public transportation system (MBTA) with several subway lines, it was not obvious in which neighborhoods I should even be looking for apartments. So I decided to make a map of the Greater Boston area showing how long it takes to commute to my workplace during morning rush hour. This post details how I made the map and how you can do one for yourself. You can find the source on GitHub.

Warning: If you want to do a similar project (i.e., a map for a different destination/city) you have to get your own API key. Google Maps allows you to do a moderate number of calls for free per month, so it is possible to do a project like this for free. However, you must be very careful, it is easy to go over the limit and then be charged hundreds of dollars.

Calculating Commute Times

The first step was to get a map of the Boston area and create a mapping between it and GPS coordinates (i.e., latitude and longitude for each pixel). On this map we can define a grid of points where we will calculate the travel time. To reduce the number of API calls I chose to make my grid points more dense near the center and less dense on the outskirts. Note that Google Maps automatically “snaps” to nearby roads, so we don’t need to worry about whether our grid points are actually on a road.

Once we have the grid, we just need to call Google Maps and use its Distance Matrix API to calculate the travel times to our destination. However, there are a few subtleties to keep in mind when calculating travel times:

  1. We need to specify the time of the day. Since I would be commuting to my workplace during the morning rush hour I set an arrival time of 9 AM.
  2. Google Maps can provide travel times for driving, biking and taking public transportation. For my project I picked public transportation only.
  3. Most forms of public transportation are fairly infrequent in the US, even during rush hour (e.g., buses coming only every 15 minutes). This can introduce an error in our travel time calculation, so to reduce its effects I decided to calculate the travel times for 2 more arrival times (8:45, 8:52) and take the minimum of the three values. This essentially means that I would be willing to come into work a bit sooner if that means not waiting at the bus stop for 20 minutes.

Commute Time overlaid on City Map

Once we have the commute times for each grid point, we can visualize them on the city map with a filled contour plot.

Map of Greater Boston colored by commute time to the Center of Astrophysics in Cambridge (blue cross); image by author

As expected, commute time increases with distance, but we can also notice anomalies, points physically further being closer by commute time. There are even embedded islands of lower commute times. This is due to the structure of the MBTA network. For example, living near the Kendall/MIT subway station we can get to our destination within 30 min, but if we lived several streets closer to our destination we would need to take a bus and would get there later. There are also small islands from where it is not possible to reach our destination (e.g., train repair center in East Cambridge).

Commute Distance of Boston Neighborhoods

While this map is helpful, it would be better to have something we could use to filter results from apartment listing websites. Most of these sites list which neighborhood each apartment belongs to, allowing us to filter for it. So, it would make sense for us to translate our commute time map into a map of neighborhoods. First, let’s just make a map of the Boston neighborhoods.

Neighborhood map of the Boston area, x marks the location of my workplace; image by author

We could try to draw a map of the Boston neighborhoods where the distance of any point to my workplace (the new origin) is proportional to the commute time (instead of the physical distance). We can accomplish this by changing the distance of each pixel relative of the origin to be proportional to the commute time, while keeping their relative direction the same.

phi = np.arctan2(y_image,x_image)
x_new = commute_time * np.cos(phi)
y_new = commute_time * np.sin(phi)

This will distort the image, and lead to uneven pixel sizes (i.e., some pixels will be crowding each other, some will have gaps between them). We can correct for that by doing a Voronoi diagram and coloring the resulting cells according the the color of the corresponding pixel.

from scipy.spatial import Voronoi, voronoi_plot_2d
vor = Voronoi(np.vstack((x_new,y_new)).T)
voronoi_plot_2d(vor,ax=ax,show_points=False,show_vertices=False,line_width=0.0)
...
#Colorize the Voronoi plot
for i,region in enumerate(vor.regions):
color = ...
polygon = [vor.vertices[k] for k in region]
plt.fill(*zip(*polygon),c=color)
Map of Boston neighborhoods scaled with commute time; image by author

With this map we can quickly see which neighborhoods are close enough for us to commute from. Note that some areas in adjacent neighborhoods get mixed (e.g., Downtown area). This is due to the presence of high speed public transportation (e.g., subway), which makes it faster to commute from a station one stop further than from an apartment that is a 5 minute walk from the current station.

This project began with me looking for an apartment from which my commute wouldn’t be too long(< 45 min). This means I should mainly be looking for apartments in Cambridge, Somerville, Belmont, Arlington, Allston, Watertown and the Downtown area. Of course there are other considerations when buying an apartment (rent, noise etc.). In the end I rented an apartment near the boundary of Cambridge and Arlington.

If you want to try to do the same for your city, check out the source on GitHub.



Source link

Previous Post

Sistema de Recomendación Python y Machine Learning

Next Post

5 Ways to Apply AI to Small Data Sets

Next Post

5 Ways to Apply AI to Small Data Sets

Bonus post: AI misreported paint colors

BrainChip Integrates Akida with Arm Cortex-M85 Processor, Unlocking AI Capabilities for Edge Devices

Related Post

Artificial Intelligence

Creating Geospatial Heatmaps With Python’s Plotly and Folium Libraries | by Andy McDonald | Mar, 2023

by admin
March 19, 2023
Machine Learning

Algorithm: K-Means Clustering. The ideas of the preceding section are… | by Everton Gomede, PhD | Mar, 2023

by admin
March 19, 2023
Machine Learning

A Simple Guide for 2023

by admin
March 19, 2023
Artificial Intelligence

How Marubeni is optimizing market decisions using AWS machine learning and analytics

by admin
March 19, 2023
Artificial Intelligence

The Ethics of AI: How Can We Ensure its Responsible Use? | by Ghulam Mustafa Shoaib | Mar, 2023

by admin
March 19, 2023
Edge AI

Qualcomm Unveils Game-changing Snapdragon 7-series Mobile Platform to Bring Latest Premium Experiences to More Consumers

by admin
March 19, 2023

© 2023 Machine Learning News Hubb All rights reserved.

Use of these names, logos, and brands does not imply endorsement unless specified. By using this site, you agree to the Privacy Policy and Terms & Conditions.

Navigate Site

  • Home
  • Machine Learning
  • Artificial Intelligence
  • Big Data
  • Deep Learning
  • Edge AI
  • Neural Network
  • Contact Us

Newsletter Sign Up.

No Result
View All Result
  • Home
  • Machine Learning
  • Artificial Intelligence
  • Big Data
  • Deep Learning
  • Edge AI
  • Neural Network
  • Contact Us

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.