>RE::VISION CRM

R 데이터 분석

[KDDTprj4] decision tree sample

YONG_X 2018. 8. 4. 14:13

#----- Decision Tree --------



library(party)

t1 <- ctree(isIF ~.,

     controls = ctree_control(maxdepth = 5,  minbucket=10),

     data=dfbasetrain)

plot(t1)


#---- k-means example ------------




#--- RFM 군집화 예제 ---


fit <- kmeans(df_RFM[8:10], 5)

table(fit$cluster)

plot(jitter(df_RFM$gF), jitter(df_RFM$gM), col=fit$cluster)

par(mfrow=c(1,2))

plot(jitter(df_RFM$gR), jitter(df_RFM$gF), col=fit$cluster)

barplot(1:5, col=1:5) # color label

par(mfrow=c(1,1))


clustRFM <- aggregate(df_RFM$gR~fit$cluster,  FUN=mean)

clustRFM$meangF <- aggregate(df_RFM$gF~fit$cluster,  FUN=mean)[,2]

clustRFM$meangM <- aggregate(df_RFM$gM~fit$cluster,  FUN=mean)[,2]


barplot(t(as.matrix(clustRFM[,2:4])), 

    beside=TRUE, 

    names.arg = clustRFM[,1],

    legend = rownames(t(as.matrix(clustRFM[,2:4]))))


plot(clustRFM$"df_RFM$gR", clustRFM$meangF, cex=table(fit$cluster)/20,

   xlim=c(1,5), ylim=c(1,5), pch=19, col="lightblue")

text(clustRFM$"df_RFM$gR", clustRFM$meangF, 1:5)


plot(clustRFM$meangM, clustRFM$meangF, cex=table(fit$cluster)/20,

   xlim=c(1,5), ylim=c(1,5), pch=19, col="lightblue")

text(clustRFM$meangM, clustRFM$meangF, 1:5)


cor(clustRFM[2:4])