Sunday, October 27, 2019

Applied Data Science - Capstone project




Applied Data Science - Capstone Project
Using location based and clustering to build recommendation system


          I.     Introduction Business Problem.

Ho Chi Minh city is largest city of Vietnam which have nearly ten million in terms of population and have a lot of non-residents such as business travelers or tourists. The statistics showed that there was more than 6 million international tourist visited Ho Chi Minh city in the first nine months of 2019. This is amazing number for any related business and this is the reason why a group of young investors would like to find a good location to start their business by setting up a restaurant or coffee shop in this crowded and dynamic city. The investor would like to leverage the data analyse advise them where is good location to open their business.
From this standpoint, there are several ways of approach such as identify where are the most attractives of people in the city or where are the business centres and so on. One of the approaches is using available location-based data to analyse it and make the recommendation.

        II.     Description of Data

In solving this problem, the location data comes from a csv file which define the latitude, longitude and other information of all the cities in Vietnam as well as its neighborhoods. This is the sample data of city and its neighborhoods:

Source file: https://raw.githubusercontent.com/dodtoan/Coursera_Capstone/master/vn.csv
Obviously, this data is raw data and need to be cleaned before actually use. The cleaned data can be used as "source" data to explore further venues in every single neighborhood using FourSquare API. There are some unnecessary fields should be removed cause Foursquare just need the latitude and longitude of the cities only and the purpose of the analyse just focuses on the Ho Chi Minh city so other city information would be removed too. The data after cleansing would be like:

By exploring the venue data from Foursquare, clustering algorithm would be applied to categorize the neighborhoods into several clusters which they have the similar properties and from that view, the good location to start cafe/restaurant business can be suggested.
To make a suggestion, some properties of data from Foursquare would be leverage to analyse to find the pattern and relation between the venues. They are:
1.    Name of venue;
2.    Categories;
3.    Latitude;
4.    Longitude;

      III.     Methodology

Stated in the business problem, the expectation outcome is a recommendation where is a suitable location to settle a restaurant. This kind of question would be good use case to utilize unsupervised machine learning and more precise, it is K-mean clustering algorithm and integrate the outcome with Foursquare API and folium library to visualize the result.
Let take a detail look into the data. The source data of location based for Ho Chi Minh city and its neighborhood has the size of (19,4), it means there are 19 neighborhoods in the investigated area.

With the folio library, the data set can be represented on the map as below:

From this point, the next step is using Foursquare to explore the venues in the neighborhoods. Cause the limited of the subscription, there is maximum of 100 venues in results and the radius for the exploration was set for 700m. This make a result as below:

The result showed that there were 98 venue categories found. To analyze each neighborhood and how the relative with its venues, above data need to be standardized. After applying the get_dummies() method in Python and merging the result, the new dataset looks like:

This dataset is still complicated to analyze cause there are 98 venues categories which most of them may not relevant to the features need to analyse then it would be transform to the new shape. The good idea is shortening the result into the top 5 common venues. After transforming the dataset, the new result would be:

It is obviously found that now the dataset had only 18 cities instead of 19 cities at the beginning. This missing will be discussed later but the new dataset is good enough to analyse.
It is time to apply the K-mean clustering algorithm. Before running the K-mean to the dataset, it would be necessary to find out what is best K. Using the Elbow method, the result showed that the K would be 3 or 4 but let’s take 3.

     IV.     Result:

Applying K-mean algorithm with K=3, merged with the original data, the result showed in the table below with 3 clusters:

Using folium library to visualize the result on the map, the clusters will be represented:

By exploring more detail on each cluster, the data showed that, it is recommended:
(i)             to open the restaurant, the good location is in the Cluster 0 which contains the neighborhoods as below:

(ii)           to open the coffee shop, the good location is in the Cluster 2 which contains the neighborhoods as below:

       V.     Discussion

Even though the algorithm generated the recommendation but actually there are several points need to be considered.
Firstly, from the data source point of view, it was not rich enough to analyse. It is both from the city data. To improve this barrier, the more detail data source would be collected, such as location of neighborhood at the ward level instead of district level as current situation.
Secondly, the business proposal used the simple features to analyse, that is venue categories. It would be suggested that the more features will be applied in the future version of the solution, such as venue price, venue like, venue rate.
These above limitations can be obviously found in the report when there is one missing city in the final result and the optimal K in the Elbow method looked not really good.

     VI.     Conclusion

Absolutely, machine learning could resolve many business problems nowadays but by this study, the important thing is the data for analyzing would be detail enough and also requires the analyst pay pretty much attention on exploring the data. Almost of the algorithms are integrated in the libraries and save a lot of effort in the data science project. In this example project, despite the are several aspects need to be improved but it definitely showed the result to audience in a pretty much visual way.


Sunday, November 18, 2012

Tỷ lệ vàng

Bài viết đã lâu, đăng trên mail list của câu lạc bộ Ham Nhậu, hehe, nhưng hôm qua nhân hiểu lầm 1 câu hỏi của bạn Kiến Vịt, đành giữ lời hứa mà post lên đây, hi vọng đúng ý của bạn:

==========================

Trong lúc cả nước sục sôi khí thế rút tiền khỏi banking system để mua vàng, Eric xin góp vui với ngày hội non sông bằng 1 đề tài cũng Vàng, hehe nhưng nó lại là Vàng trong Khoa học, Nghệ thuật và tất nhiên cả Kinh doanh nữa. 

1. Euclide and tỷ lệ Vàng.

Trước hết, xin mời quý dzị quay lại thời kỳ trước công nguyên để gặp gỡ nhà toán học lừng danh Hy Lạp và tất nhiên cả thế giới so far. 

Ổng tên Euclide, phiên âm tiếng Ta là Ơ-clit, mà quý dzị đã biết tới qua các tiên đề và định lý trong hình học. 

Inline image 1
Euclide (330-275 trước Công nguyên)

Dưng hôm nay chúng ta sẽ làm quen với 1 khái niệm ít được nhắc đến của ông:Tỷ lệ Vàng (Golden Ratio), ổng phán: 

Nếu 2 đoạn thằng a, b được vẽ sao cho (a+b)/a = a/b thì tỷ lệ đó được gọi làTỷ lệ Vàng, và tỷ số trên được gọi là φ.
Inline image 1 
Inline image 3

Bọn đệ tử của ổng sau này dùng phương trình bậc 2 tính như sau: (a+b)/a = a/b = φ 
=> a= b*φ 
=> …. 
=> φ = (1+sqrt(5))/2 = 1,6180339887.....

Bình tĩnh chưa đến đoạn hay nhất, tạm chia tay ông Euclide ở đây.

2. Fibonacci chuỗi.

Tiếp theo, mời quý dzị tưởng nhớ lại chuỗi số Fibonacci, được đặt theo tên của người tìm ra, nó là dãy nài: 1, 1, 2, 3, 5, 8, 13,..  Quy luật của chuối số thì chắc quý dzị đã nhận ra, hehe.

Các bô lão biết tuốt sau đó phát hiện ra: lấy số (n+1) chia cho số n trong dãy trên, thì sẽ được 1 số hội tụ dần về một hằng số gọi là phi, tức là ông này này: φ và cũng là ông ở trên kia đấy: 1,618.. hehe, nhất lộc nhất phát, số đẹp hẩy? 

(chia ngược lại n/(n+1) cũng sẽ ra 1 hằng số khác: 0,618..., nhưng mạn ko bàn ở đây, nó dành cho các ông lướt sóng, oánh casino,.. vươn vươn tự tiềm hiểu)

Bắt đầu có chuyện từ đây, hehe. 

Làm tý chân dung cho các ổng đỡ ghen tị nhau trên Thiên đàng đã:

Inline image 2
Leonardo Fibonacci (1170-1250)

Các bạn già hói lập tức phát hiện ra điểm quan trọng này và thấy rằng, tất cả các hình ảnh, vật thể,.. nếu tuân theo Tỷ lệ Vàng này thì đẹp mắt, cuốn hút, ưa nhìn, thiện cảm, ... hehe.

Sau đây là màn múa minh hoạ:

- Một Ông Người được cho là cân đối nếu thoả mãn các tỷ lệ vàng:


- Chiều cao / đỉnh đầu đến đầu ngón tay = Ф 
- Đỉnh đầu tới đầu ngón tay / đỉnh đầu tới rốn (hoặc cùi chỏ) = Ф 
- Đỉnh đầu tới rốn (hoặc cùi chỏ) / đỉnh đầu tới ngực = Ф 
- Đỉnh đầu tới rốn (hoặc cùi chỏ) / chiều rộng đôi vai = Ф 
- Đỉnh đầu tới rốn (hoặc cùi chỏ) / chiều dài cẳng tay = Ф
- .... còn nhiều nữa, search đi quý dzị, hehe.

Tuy nhiên, Eric phải thừa nhận là đặc điểm này chỉ có ở bọn mọi rợ mắt xanh mũi lõ da trắng, chứ chủng tộc thượng đẳng da vàng mắt híp mũi tẹt chúng ta thì hình như không cần, khà khà.

Chúng ta nhẽ đang ở tỷ lệ chì hoặc đất sét! Xem thêm Ông nài:
Inline image 18
Tượng ông David - do cô Michelangelo nặn

- Cũng rất dễ tìm thấy trong tự nhiên việc áp dụng nghiêm ngặt các tỷ lệ này, ví dụ như Ông Ốc đây:

Inline image 5
Ổng được tự nhiên thiết kế tuân theo tỷ lệ Vàng dư thế nài:
Inline image 6

Tức là nối các đường tròn nội tiếp các hình vuông có độ dài cạnh là dãy số Fibonacci lại với nhau, sẽ ra hình xoắn ốc nhé, kinh chưa, hè hè.

- Và các Chị Hoa, Cô Lá này nữa:


Inline image 16
Inline image 17

- Hoặc như cô gì xinh xinh, do ông gì giỏi giỏi vẽ, hehe, Eric quên mất tên đây:

Inline image 7
Mona Lisa - painted by Leonardo da Vince

- Hoặc trong các công trình kiến trúc, từ cổ đại đến hiện đại:

Inline image 8
Đền cổ Hy Lạp


Nhà thờ Đức bà Paris

Inline image 11
Somewhere around the world

- Hoặc như sản phẩm thời thượng của ông bạn thân quá cố của Eric:

Inline image 12
Inline image 14
Inline image 13

Còn rất nhiều các ví dụ khác, dễ dàng tìm thấy trên Gúc, mời quý dzị, hehe.

3. Lửng luận (not Kết luận)

Túm lại, Tỷ lệ vàng là có thật, được ứng dụng rộng rãi và còn được gọi là tỷ lệ của Chúa (God's ratio - Nhìn vào tự nhiên sẽ thấy, kể cả Galaxy)

Hiểu về tỷ lệ này, nó giúp chúng  ta trả lời câu hỏi tại sao nhà của Ta xây lên, dù mắc tiền nhưng rất xấu xí và nhanh lỗi mốt, sản phẩm chúng ta làm ra, cả thế giới gần như không ai chấp nhận, hehe.

Các quý Anh Chị, từ khi còn chưa muộn, hãy cho con mình tiếp xúc với những khái niệm này, để từ nhỏ, những hình ảnh đẹp mắt, những tỷ lệ vô hình sẽ ăn sâu vào tâm trí của chúng, để lớn lên chúng thành những Ông Người có tỷ lệ Vàng về tư duy, góp phần tạo ra các giá trị Vàng, hehe. Sến quá, nhưng mà không sai phỏng các quý Anh Chị?

Bài này tạm dừng ở đây. Quý dzị nào muốn kiếm Vàng thật từ Vàng Tỷ lệ có thể tự Gúc thêm, không có cái gì miễn phí mà lại Ngon and Bổ được, hehe.

(Bọn đầu tư Chấng Khoán, Vàng và cả Gambling nó có hẳn bộ môn nghiên cứu và ứng dụng Fibonacci & Golden ratio đó, xin mời xơi mìn nào, hehe)

================================
Bonus tý Multimedia cho trực quan sinh động nhá: