>RE::VISION CRM

R 데이터 분석

R d3netwrok sample using randomForest proximity of mtcars

YONG_X 2015. 8. 5. 13:28




#-----[ unsupervised proximity in rf ] --------

data(mtcars)
crf1 <- randomForest(mpg ~ ., data=mtcars, 
      importance=TRUE,  proximity=TRUE)
m1 <- melt(crf1$proximity)
plot(sort(m1$value))

#--- make a graph using RF proximity --------

# install.packages("d3Network")
require(d3Network)

m2 <- m1[m1$value>quantile(m2$value,0.7) & m1$value<1,]
NetworkData <- data.frame(m2$X1, m2$X2, m2$value)
# create an html file presenting grpah
d3SimpleNetwork(NetworkData, width = 400, height = 400, file = "d3netofRFpox1.html")

#----[ importance and error scatter plot ]---


plot(crf1, log="y")


rfvimpdf<- as.data.frame(crf1$importance)
# error and purity combined
rfvimpdf$epcm<- (rfvimpdf[,1]/max(rfvimpdf[,1]) ) *(rfvimpdf[,2]/max(rfvimpdf[,2]) )
# coldf[colnum==23,] 

plot(rfvimpdf[,1:2],  main="randomForest var Importance", pch=20, cex=2, col= ifelse(rfvimpdf$epcm > quantile(rfvimpdf$epcm,0.7) , rgb( 0, 139, 139, maxColorValue=255), rgb( 139, 125, 107, maxColorValue=255) ))  
text(rfvimpdf[,1:2], labels=row.names(rfvimpdf), pos=3)

lines(c(NA,NA,NA,NA,NA,max(rfvimpdf[,2]) *6/6,  max(rfvimpdf[,2]) *6/7,  max(rfvimpdf[,2]) *6/8, max(rfvimpdf[,2]) *6/9, max(rfvimpdf[,2])*6/10, max(rfvimpdf[,2]) *6/11 ), lst=2)

# insert grid line in the plot
grid(5,5)