Where to travel next? A guide to building a recommender system for POIs

Maha Amami
Towards Data Science
4 min readSep 24, 2021

--

Source

In the last article, I wrote about how to make your own movie and book recommender system. In the following, I am going to describe step by step how to build a recommender system that suggests new places to visit based on user preferences, geographical influence, and social influence.

The recommendation approach is presented in the article iGSLR: Personalized Geo-Social Location Recommendation: A Kernel Density Estimation Approach”, Zhang and Chow, SIGSPATIAL’13.

I will present step by step the implementation of their approach using Surprise Library.

Loading the dataset and pre-processing

The dataset I used was gathered from the social media Gowalla. It consists of 36,001,959 check-ins by 407,533 users in 2,724,891 POIs.

It includes the datasets of users check-ins information, user’s friends information, locations information, and users information.

I selected only users who have more than 5 check-ins and less than 50 to reduce the computing time but you can of course work with the entire data.

The final training dataset should contain all the information of POIs and the user information joined together with no redundant information, to do so:

  1. I joined both check-ins data frame and location data frame using the place id

2. I calculated the frequencies of visited locations from the obtained data frame df_checkins_location to remove the redundancy of rows

3. I joined both df_frequencies and df_locations to obtain the final training dataset

The entire dataset is then loaded in surprise

The authors of the article designed a recommender system leveraging social and geographical influences to express user preferences.

Social influence

The authors observed that users usually turn to friends to seek recommendations for books, movies, or POIs. They usually prefer to travel to POIs that were highly recommended by their friends rather than a random place.

They proposed to calculate the social influence of a user using the following steps:

(1) Measuring her/his similarity with each of her/ his friends.

Social similarity between two users
  • F(u) is the set of freinds of user u

Implementation

First I created a data frame that associates each user to her/his friends.

List of friends for each user in the dataset

(2) Using this similarity in a collaborative filtering formula

Social collaborative filtering rating prediction
  • r_vi is the frequency of the user v visiting the POI i

To obtain the r_vi we need to use the function below:

The implementation of the predicted rating is calculated using the function below:

(3) Transforming the prediction of the POI to a probability score

where

  • L is the list of all POI

Geographic influence of locations

The authors proposed to leverage the distance between every pair of locations visited by the same user. For instance, users who used to travel around the world would like to have suggestions of POIs outside the country, on the contrary users who usually visit POIs around their living areas wants recommendations of nearby POIs.

As the distance distribution changes from one user to another, it is calculated as follows:

Distance distribution estimation

where

  • d_ij is the distance between a POI to recommend and a POI already visited by the user
  • D_u is the list of distances of all pairs of POI visited by user u
  • K(.) is a normal kernel function
Normal kernel function
  • h is a smoothing parameter that is an optimal bandwidth.
Optimal bandwidth

The final probability of a user visiting a new POI is calculated as follows:

Geo probability of a user visiting a new location (POI)

Final formula

The social influence and geo influence probabilities are summed up to estimate for a user u the relevance score of a POI.

Conclusion

That s it! This recommender system can help you to decide about your next travel in case you think that distance from the POI and your friends recommendations are important factors to choose. You can send me a message via LinkedIn to get the entire code. Stay tuned for more code on recommender systems.

Gig by GIPHY

--

--

I write about data sciences, feminism, books, and my experience in academia