The dataset Online Retail.xlsx and the description of the data is taken from https://archive.ics.uci.edu/ml/
datasets/online+retail.
Online Retail.xlsx contains records of transactions occurring between 01/12/2010 and 09/12/2011
for a UK-based and registered non-store online retail. The company mainly sells unique all-occasion
gifts. Many customers of the company are wholesalers.
The attributes in the dataset are:
z InvoiceN − Invoice number. Nominal, a 6-digit integral number uniquely assigned to each transaction. If this code starts with letter “c”, it indicates a cancellation.
z StockCode − Product (item) code. Nominal, a 5-digit integral number uniquely assigned to each
distinct product.
z Description − Product (item) name. Nominal.
z Quantity − The quantities of each product (item) per transaction. Numeric.
z InvoiceDate − Invoice Date and time. Numeric, the day and time when each transaction was
generated. 

z UnitPrice − Unit price. Numeric, Product price per unit in sterling.
z CustomerID − Customer number. Nominal, a 5-digit integral number uniquely assigned to each
customer.
z Country − Country name. Nominal, the name of the country where each customer resides.
6. Select only the transactions that have occurred in the year 06/01/11 and 11/30/11 and create a new
subset of data. For answering questions from 7 to 10, use this subset of data.
7. Calculate the RFM values for each customer (by customer id). RFM represents
z R (Recency) − Recency should be calculated as the number of months before he or she has made
a purchase from the online store. If he/she made a purchase in the month of November 2011,
then the Recency should be 0. If purchase is made in October 2011 then Recency should be 1
and so on and so forth.
z F (Frequency) − Number of invoices by the customer from 06/01/11 to 11/30/11.
z M (Monetary Value) − Total spend by the customer from 06/01/11 to 11/30/11.
8. Use dendrogram and elbow method to identify how many customer segments exist, using the RFM
values for each customer created in Question 7.
9. Create the customer segments with K-means algorithm by using number of clusters is suggested by
elbow method.
10. Print the cluster centers of each customer segment and explain them intuitively

Solve Q1 to Q10 of Pages 260-261 of the book. For finding the value of k using Elbow Method, compute k mathematically by finding the points of highest change & 2nd  highest change in slope, and then choose one out of the two based on lesser MSE

InvoiceNo,StockCode,Description,Quantity,InvoiceDate,UnitPrice,CustomerID,Country
536365,85123A,WHITE HANGING HEART T-LIGHT HOLDER,6,01-12-2010 8:26,2.55,17850,United Kingdom
536365,71053,WHITE METAL LANTERN,6,01-12-2010 8:26,3.39,17850,United Kingdom
536365,84406B,CREAM CUPID HEARTS COAT HANGER,8,01-12-2010 8:26,2.75,17850,United Kingdom
536365,84029G,KNITTED UNION FLAG HOT WATER BOTTLE,6,01-12-2010 8:26,3.39,17850,United Kingdom
536365,84029E,RED WOOLLY HOTTIE WHITE HEART.,6,01-12-2010 8:26,3.39,17850,United Kingdom
536365,22752,SET 7 BABUSHKA NESTING BOXES,2,01-12-2010 8:26,7.65,17850,United Kingdom
536365,21730,GLASS STAR FROSTED T-LIGHT HOLDER,6,01-12-2010 8:26,4.25,17850,United Kingdom
536366,22633,HAND WARMER UNION JACK,6,01-12-2010 8:28,1.85,17850,United Kingdom
536366,22632,HAND WARMER RED POLKA DOT,6,01-12-2010 8:28,1.85,17850,United Kingdom
536367,84879,ASSORTED COLOUR BIRD ORNAMENT,32,01-12-2010 8:34,1.69,13047,United Kingdom
536367,22745,POPPY'S PLAYHOUSE BEDROOM,6,01-12-2010 8:34,2.1,13047,United Kingdom
536367,22748,POPPY'S PLAYHOUSE KITCHEN,6,01-12-2010 8:34,2.1,13047,United Kingdom
536367,22749,FELTCRAFT PRINCESS CHARLOTTE DOLL,8,01-12-2010 8:34,3.75,13047,United Kingdom
536367,22310,IVORY KNITTED MUG COSY,6,01-12-2010 8:34,1.65,13047,United Kingdom
536367,84969,BOX OF 6 ASSORTED COLOUR TEASPOONS,6,01-12-2010 8:34,4.25,13047,United Kingdom
536367,22623,BOX OF VINTAGE JIGSAW BLOCKS,3,01-12-2010 8:34,4.95,13047,United Kingdom