SAP HANA PAL - K-Means Algorithm or How To Do Cust... - SAP Community-O
SAP HANA PAL - K-Means Algorithm or How To Do Cust... - SAP Community-O
- SAP Community
Each cluster is associated with a centroid and each point is assigned to the cluster with the closest centroid. The centroid is
the mean of the points in the cluster. The closeness can be measured using:
Manhattan Distance
Euclidean Distance (most commonly used)
Minkowski Distance
Every time a point is assigned to a cluster the centroid is recalculated. This is repeated in multiple iterations until centroids
don’t change anymore (meaning all points have been assigned to a corresponding cluster) or until relatively few points
change clusters. Usually most of the centroid movement happens in the first iterations.
One of the main drawbacks of the K-Means Algorithm is that you need to specify the number of Ks (or clusters) upfront as
an input parameter. Knowing this value is usually very hard, that is why it is important to run quality measurement
functions to check the quality of your clustering. Later in this post we will talk about this.
I came across a very interesting paper that talks about segmentation in the telecommunication industry, so I thought it
would be a very nice use case to demo the K-Means algorithm in HANA (if you are interested in this topic, I very much
recommend reading this paper). These are the steps I followed:
The first step is creating a table that will contain information on customers mobile phone usage habits with the following
structure:
"DAY_TIME_CALLS" DOUBLE, --> Percentage of Calls made during day time hours (9 a.m. - 6 p.m.)
"WEEK_DAY_CALLS" DOUBLE, --> Percentage of Calls made during week days (Monday thru Friday)
"ID" INT,
"AVG_CALL_DURATION" DOUBLE,
"AVG_NUMBER_CALLS_RCV_DAY" DOUBLE,
"AVG_NUMBER_CALLS_ORI_DAY" DOUBLE,
"DAY_TIME_CALLS" DOUBLE,
"WEEK_DAY_CALLS" DOUBLE,
"CALLS_TO_MOBILE" DOUBLE,
"SMS_RCV_DAY" DOUBLE,
"SMS_ORI_DAY" DOUBLE,