-
Notifications
You must be signed in to change notification settings - Fork 0
/
ejercicio_arbol.R
38 lines (27 loc) · 1007 Bytes
/
ejercicio_arbol.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# install.packages("rattle") # ejecutar los install 1 vez
# install.packages("rpart")
# install.packages("RColorBrewer")
## cargando las librerias
library(rpart)
library(rattle)
## Cargando los datos
d_tennis=read.csv(file="tennis.csv", header = T, stringsAsFactors = F)
## Creando el decision tree default
fit_tree_1=rpart(data = d_tennis,
formula = jugar_tenis ~ clima + temperatura + humedad + ventoso)
## Dibujando el arbolito
fancyRpartPlot(fit_tree_1)
## Creando el decision tree siendo menos restrictivo
fit_tree_2=rpart(data = d_tennis,
formula = jugar_tenis ~ clima + temperatura + humedad + ventoso,
control = rpart.control(
cp = 0.000001,
minbucket=2,
minsplit=2
)
)
fit_tree_2 # <--- este es el modelo predictivo!
## Ahora sí!
fancyRpartPlot(fit_tree_2)
## Imprimiendo las reglas
asRules(fit_tree_2)