Exploring Best District for New Café in Hong Kong
k-Means Clustering — an Unsupervised Machine Learning Algorithm
This is an image and text article. To Access the codes — Click Here
1. Introduction
1.1 Background
Hong Kong is primarily the entry into the international market because it scores high on several factors including its strategic location, productive work-force, attractive tax regime, world-class infrastructure and and an effective legal system. Many investors and entrepreneurs have chosen to set up their businesses in Hong Kong. Although Hong Kong is small in terms of the area of land, the population is comparatively large which contributes to the great business opportunities.| Victoria Harbour in Hong Kong |
1.2 Problem
Hong Kong is small, merely around 1,100 km², and the majority of Hong Kong's landscape consists of steep, undeveloped mountains and hills, which explain why Hong Kong has limited land for development. Officially, there are 18 districts in Hong Kong. The first question for a startup in Hong Kong would be where the shop will be. In the context of opening a new coffee shop, it is concerned that which district should be chosen regarding the business opportunities and competition.1.3 Stakeholders
The quantitative analysis aims to provide potential investors, or startup entrepreneurs, especially those who are interested in opening a new coffee shop with a guide to analyze the important problem scientifically. Supplement information such as rental prices of certain potential retail shops and their community facilities nearby is needed for more thorough consideration. Plus, government authorities can refer to the analysis for better understanding the city's culture diversity.2. Data
The analysis to find the best districts for new coffee shops is based on the following aspects:- number of existing coffee shops in the districts;
- population density in the districts.
The sources of data are the following to achieve their respective aims:
- Wikipedia: To obtain the district data, including names of regions, names of districts, population density;
- OpenCage Geocoder API: To look up the latitudes and longitudes of all districts;
- Foursquare API: To obtain the number of coffee shop, their types and locations in all districts.
2.1 Downloading and Preprocessing Data
Before scrapping and exploring the data, all the dependencies needed should be downloaded first. Next,
pandas is used to read the tables in the Wikipedia page and a for loop is used to scrap a 'District table'. The name of a column is adjusted and the dataframe with the column names, Region, District, Population, Area(km²), and Density(/km²) is built.
In order to utilize the Foursquare location data, it is needed to get the latitude and the longitude coordinates of each districts. OpenCage Geocoder, which is a free API that can be use to look up coordinates of places and also find out the place a set of coordinates corresponds to, is used to get the data of latitudes and longitudes of the districts.
![]() |
| The dataframe has 3 regions and 18 districts. |
You may refer to a Geocoding Tutorial from Amaral Lab. Please be aware that you need to you need to create a free account on OpenCage Geocoder, which is free.
3. Methodology
The dataset will be first explored through looking at Hong Kong as a whole area, searching for venues in the area with their categories. With the help of geopy library and Foursquare API respectively, a Hong Kong district map and a list of venues in the first explored district, Central and Western, will be created. The purpose of doing so is to test the feasibility of the code and the accuracy of the Foursquare API.After that, the same process will be done to all the districts in Hong Kong so as to generate a dataframe consisting of venues in each district. One hot encoding and GroupBy in Python will then be used to help create a new dataframe displaying the top 10 venues for each district.
Finally, k-Means Clustering is adopted to cluster the districts by looking at the similarities of the categories of the top venues in those areas.
To achieve the aim of the study, coffee-shop-dominating clusters will be avoided. By choosing the clusters or districts with coffee shop being the least common venue, the desired outcome will be ideally be produced. However, there may be more than one potential districts or clusters, so the population should then be considered to choose the best district to open a coffee shop.
4. Analysis
4.1 Exploring Hong Kong
We use the geopy library through a user_agent, called hk_explorer, to get the latitude and longitude values of Hong Kong, then create a map of Hong Kong with districts superimposed on top.| The geograpical coordinates of Hong Kong are 22.2793278, 114.1628131 |
4.2 Exploring First District in Hong Kong
We use loc to get the first district's name, latitude and longitude. After that, Foursquare API helps generate top 100 venues in the first district, Central and Western. Let's see the top 5 rows of the dataset:
We use loc to get the first district's name, latitude and longitude. After that, Foursquare API helps generate top 100 venues in the first district, Central and Western. Let's see the top 5 rows of the dataset:
One of the most powerful things is that the venues generated are categorised and this is very helpful for most kinds of analysis.
Through running the unique function, we can find that there are 160 uniques categories in the dataset.
The results are as follow:
From the result, the potential clusters are Clusters 1 to 4.
However, considering the population, Clusters 2 and 3 are far less populated, meaning that the number of potential customers is less and so the business opportunity is less desirable.
Besides, from the top 10 common venues, there is no café or coffee shop in Cluster 4. On the other hand, there are cafés in top 7 to 10 common venues in districts in Cluster 1.
Therefore, it is better to choose Cluster 4 which consists of just one district, Eastern, as the best district for opening a coffee shop.
From the analysis and results above, it is concluded to choose the Eastern district in Hong Kong to open a new coffee shop.
4.3 Exploring All Districts in Hong Kong
We create a function to repeat the same process as 4.2 to all the districts and the dataset is summarised by the function groupby.Through running the unique function, we can find that there are 160 uniques categories in the dataset.
4.4 Examining Each District
A dataframe showing top 10 common venues in each district is produced by one hot encoding and sorting the mean of frequency of occurrence of each category. Let's see the top 5 rows of the dataset:4.5 Clustering Districts
This is the main part of the analysis. We use k-means clustering and the number of clusters is set at 6 (by trial and error, the best k is 6). The clusters are visualised by folium map for better illustration of the results.The results are as follow:
- Cluster 1 (Orange Dots) - Chinese Restaurants Dominating Areas
- Cluster 2 (Purple Dot) - Undeveloped Area (1)
- Cluster 3 (Blue Dot) - Undeveloped Area (2)
- Cluster 4 (Light Green Dot) - Populated Developed Area (1)
- Cluster 5 (Cyan Dot) - Café / Coffee Shops Dominating Area (1)
- Cluster 6 (Red Dots) - Café / Coffee Shops Dominating Area (2)
5. Results
The resulting clusters are summarised as follow :- Cluster 1 (Orange Dots) - Chinese Restaurants Dominating Areas
- Cluster 2 (Purple Dot) - Undeveloped Area (1)
- Cluster 3 (Blue Dot) - Undeveloped Area (2)
- Cluster 4 (Light Green Dot) - Populated Developed Area (1)
- Cluster 5 (Cyan Dot) - Café / Coffee Shops Dominating Area (1)
- Cluster 6 (Red Dots) - Café / Coffee Shops Dominating Area (2)
From the result, the potential clusters are Clusters 1 to 4.
However, considering the population, Clusters 2 and 3 are far less populated, meaning that the number of potential customers is less and so the business opportunity is less desirable.
Besides, from the top 10 common venues, there is no café or coffee shop in Cluster 4. On the other hand, there are cafés in top 7 to 10 common venues in districts in Cluster 1.
Therefore, it is better to choose Cluster 4 which consists of just one district, Eastern, as the best district for opening a coffee shop.
6. Discussion
It is observed that the results of the study heavily rely on the venues generated from the Foursquare API. It is suggested to repeat the study with other API so as to avoid inaccurate results due to incomplete or not up-to-date venue library.7. Conclusion
From the analysis and results above, it is concluded to choose the Eastern district in Hong Kong to open a new coffee shop.











Comments
Post a Comment