I am new to R and the clustering world. I am using a shopping dataset to extract features from it in order to identify something meaningful.
So far I have managed to learn how to merge files, remove na., do the sum of errors squared, workout the mean values, summarise by group, do the K means clustering and plot the results X, Y.
However, I am very confused on how to view these results or identify what would be a useful cluster? Am i repeating something or missing out on something? I get confused with plotting X Y variables aswell.
Below is my code, maybe my code might be wrong. Could you please help. Any help would be great.
# Read file
mydata = read.csv(file.choose(), TRUE)
#view the file
View(mydata)
#create new data set
mydata.features = mydata
mydata.features <- na.omit(mydata.features)
wss <- (nrow(mydata.features)-1)*sum(apply(mydata.features,2,var))
for (i in 2:20) wss[i] <- sum(kmeans(mydata.features, centers=i)$withinss)
plot(1:20, wss, type="b", xlab="Number of Clusters", ylab="Within groups sum of squares")
# K-Means Cluster Analysis
fit <- kmeans(mydata.features, 3)
# get cluster means
aggregate(mydata.features,by=list(fit$cluster),FUN=mean)
# append cluster assignment
mydata.features <- data.frame(mydata.features, fit$cluster)
results <- kmeans(mydata.features, 3)
plot(mydata[c("DAY","WEEK_NO")], col= results$cluster
Sample data Variables, below are all the variables I have within my dataset, its shopping dataset collected over 2 years
PRODUCT_ID - uniquely identifies each product household_key - uniquely identifies each household BASKET_ID - uniquely identifies a purchase occasion DAY - day when transaction occured QUANTITY - number of products purchased during the trip SALES_VALUE - amount of dollar retailers receive from sales STORE_ID - identifies unique stores RETAIL_DISC - disccount applied due to manufacture coupon TRANS_TIME - time of day when the transaction occurred WEEK_NO - week of transaction occurred 1-102 MANUFACTURER - code that links products with same manufacture together DEPARTMENT - groups similar products together BRAND - indicates private or national label band COMMODITY_DESC - groups similar products together at the lower level SUB_COMMODITY_DESC - groups similar products together at the lowest level

clusGapin theclusterpackage. It computes a 'goodness of clustering' statistic for many possible values of k. Your question as it stands is not reproducible because you haven't provided sample data. Also, your question about how to identify a useful cluster is a complex, unanswered question in statistics and machine learning. Not really a programming question. - bdemarest