Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Motivation
Ridesharing drivers and companies, such as Uber and Lyft, can make more money by filling their cars with passengers for a higher percentage of the time they are on the road. With this in mind, I designed a Shiny app for New York City rideshare drivers that recommends a destination at which they will likely find passengers faster. The recommendation is based on the user’s current location, time, day of the week and the temperature in NYC.
Data
In 2015, the news and analytics website FiveThirtyEight obtained historical Uber pickups in NYC from the NYC Taxi & Limousine Commission by filing a Freedom of Information Law request. From this data set I used pickups from April – September 2014, as they included GPS coordinates. I supplemented this data set with hourly weather data from NOAA, the National Weather Service Forecast Office.
To review my dataset and code: Github
Visualization and Recommendation
After cleaning and merging the data, I plotted each pickup using Leaflet clusters. I added filters so the user can manually limit pickups to those made under specific temperatures, days of the week and times of day. In order to give drivers some insight over time, I added a histogram below the map showing pickups overtime across the city based on the users filter criteria.
The map responds to a user’s click, collecting the GPS coordinates at their indicated starting point. I used google’s revgeocode function to convert these GPS coordinates into the associated address. Next, I used the function distm to create a new dataset containing all pickups under the user’s selected criteria within a quarter mile radius (as the crow flies) of the selected starting point. In this new dataset (in which each row contains the GPS coordinates of one specific pickup) I added a column with the total number of other pickups in the dataset within a tenth of a mile radius of each respective pickup. I then calculated the row with the maximum value in that column (indicating a high density of other surrounding pickups) and selected the GPS coordinates in that row as the end destination. Finally, I used the function gmapsdistance (Google Maps distance matrix API) to output the time and distance from the starting click point to the ending destination.
Give it a try yourself here: ShinyApp.io
Future Work
There is a lot more work to be done to improve the quality of the recommendation in my app. I would filter my data using SQLite in order to improve the speed of my app. This would allow me to incorporate all 5.3 million pickups from the original Uber dataset (I had to take a subset to get it to run smoothly in the demo). Additionally, I would add NYC taxi data in order to have data year-round (Uber only released April – Sept. pickups). This would allow me to expand the weather data filter as variables such as rain, snow and humidity would become more meaningful. I would also factor in events occurring across the city that drive rideshare demand. Finally, I would implement predictive analytics and recommendations for drivers, such as route and time optimization, using machine learning.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.