Sunday, May 12, 2013

predicciones con árboles.


árboles de decisión, son muy usados para establecer modelos predictivos,en base a hechos del pasado.

Ejecución de árboles en R.

que algoritmo utiliza R,

library(tree)
library(datasets)
iris.tr = tree(Species ~ ., iris)
iris.tr
> summary(iris.tr)

> plot(iris.tr)
> text(iris.tr)
> misclass.tree(iris.tr)
> misclass.tree(iris.tr, detail=TRUE)

> library(rpart)
> data(spam7)
> attach(spam7)
> spam.tree = rpart(formula = yesno ~ crl.tot + dollar + bang)
> spam.tree = rpart(formula = yesno ~ crl.tot + dollar + bang + money + n000 + make,method="class", data=spam7)
> plot(spam.tree)
> text(spam.tree)
printcp(spam.tree)
> spam.tree = rpart(formula = yesno ~ crl.tot + dollar + bang + money + n000 + make,method="class", data=spam7, cp=0.001)
> plotcp(spam.tree)
> spam7b.tree = prune(spam.tree, cp = spam.tree$cptable[which.min(spam.tree$cptable[,"xerror"]), "CP"])
> plot(spam7b.tree)
> text(spam7b.tree)



Con Weka desde R
> library("RWeka")
tree = make> tree = make_Weka_classifier("weka/classifiers/trees/J48", c("bar", "Weka_tree"))
> print(tree)
> WOW(tree)
> fm = tree(yesno ~ crl.tot + dollar + bang + money + n000 + make, data=spam7, control=Weka_control( S=TRUE, M=150))
> fm
table( observed= spam7$yesno, predicted = fitted(fm))
fm = tree(yesno ~ crl.tot + dollar + bang + money + n000 + make, data=spam7, control=Weka_control( S=TRUE, M=150))
library(party)
plot(fm)