par(mfrow=c(1,1),mar=c(4,4,2,2))
library(randomForest)
Abl<-read.table("abal.csv",sep=",",dec=".",header=TRUE)
# Visualizziamo i primi 5 record
head(Abl,5)
set.seed(19821404)
Abl.rf<-randomForest(Sex~.,data=Abl,importance=TRUE,proximity=TRUE)
Abl.tr<-getTree(Abl.rf, 12, labelVar=TRUE)
plot(Abl.tr)
data(iris)
## Look at the third trees in the forest.
getTree(randomForest(iris[,-5], iris[,5], ntree=10), 3, labelVar=TRUE)
#post(Abl.tr,file="",title="Random Forest: Abalone data",pretty=TRUE)
plot(Abl.tr,uniform=TRUE,margin=0.1,branch=0.5,compress=TRUE)
text(Abl.tr)
plot(Abl.rf,type="l")
print(Abl.rf)
## Look at variable importance:
round(importance(Abl.rf), 2)
## Do MDS on 1 - proximity:
Abl.mds <- cmdscale(1 - Abl.rf$proximity, eig=TRUE)
op <- par(pty="s")
pairs(cbind(Abl[,2:8], Abl.mds$points), cex=0.6, gap=0, 
      col=c("red", "green", "blue")[as.numeric(Abl$Sex)],
      main="Abalone Data: Predictors and MDS of Proximity Based on RandomForest")
par(op)
print(Abl.mds$GOF)
## The `unsupervised' case:
Abl.urf <- randomForest(Abl[, -5])

MDSplot(Abl.urf, Abl$Sex)