Sei sulla pagina 1di 7

University

DATA MINING AND


MACHINE LEARNING
Decision tree using the Wine type
data set

R version 3.1.0 (2014-04-10) -- "Spring Dance"


Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.


You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.


Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or


'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library (tree)


Warning message:
package tree was built under R version 3.1.1
> library (ISLR)
> mywinetype <read.csv(url("http://uopeopleweb.com/winetype.csv"), header=TRUE)

> attach(mywinetype)
> names(mywinetype)
[1] "Class"

"Alcohol"

[4] "Ash"

"Alcalinity_of_ash"

[7] "Total_phenols"

"Malic_acid"
"Magnesium"

"Flavanoids"

[10] "Proanthocyanins"
[13] "diluted_wines"

"Nonflavanoid_phenols"

"Color_intensity"

"Hue"

"Proline"

> dim(mywinetype)
[1] 178 14
> attributes(mywinetype)
$names
[1] "Class"

"Alcohol"

[4] "Ash"

"Alcalinity_of_ash"

[7] "Total_phenols"
[10] "Proanthocyanins"
[13] "diluted_wines"

"Malic_acid"
"Magnesium"

"Flavanoids"
"Color_intensity"

"Nonflavanoid_phenols"
"Hue"

"Proline"

$class
[1] "data.frame"

$row.names
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
36

[37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
54
[55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
72
[73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
90
[91] 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
107 108
[109] 109 110 111 112 113 114 115 116 117 118 119 120 121 122
123 124 125 126
[127] 127 128 129 130 131 132 133 134 135 136 137 138 139 140
141 142 143 144
[145] 145 146 147 148 149 150 151 152 153 154 155 156 157 158
159 160 161 162
[163] 163 164 165 166 167 168 169 170 171 172 173 174 175 176
177 178

> head(mywinetype)
Class Alcohol Malic_acid Ash Alcalinity_of_ash Magnesium
Total_phenols
1

1 14.23

1.71 2.43

15.6

127

2.80

1 13.20

1.78 2.14

11.2

100

2.65

1 13.16

2.36 2.67

18.6

101

2.80

1 14.37

1.95 2.50

16.8

113

3.85

1 13.24

2.59 2.87

21.0

118

2.80

1 14.20

1.76 2.45

15.2

112

3.27

Flavanoids Nonflavanoid_phenols Proanthocyanins Color_intensity


Hue
1

3.06

0.28

2.29

5.64 1.04

2.76

0.26

1.28

4.38 1.05

3.24

0.30

2.81

5.68 1.03

3.49

0.24

2.18

7.80 0.86

2.69

0.39

1.82

4.32 1.04

3.39

0.34

1.97

6.75 1.05

diluted_wines Proline
1

3.92

1065

3.40

1050

3.17

1185

3.45

1480

2.93

735

2.85

1450

> winetype <- tree(Class ~ Malic_acid + Ash + Alcalinity_of_ash +


Magnesium + Total_phenols + Flavanoids + Nonflavanoid_phenols +
Proanthocyanins + Color_intensity + Hue + diluted_wines + Proline,
data=mywinetype)
> summary(winetype)

Regression tree:
tree(formula = Class ~ Malic_acid + Ash + Alcalinity_of_ash +
Magnesium + Total_phenols + Flavanoids + Nonflavanoid_phenols +
Proanthocyanins + Color_intensity + Hue + diluted_wines +

Proline, data = mywinetype)


Variables actually used in tree construction:
[1] "Flavanoids"

"Color_intensity" "Proline"

Number of terminal nodes: 5


Residual mean deviance: 0.01596 = 2.761 / 173
Distribution of residuals:
Min. 1st Qu. Median

Mean 3rd Qu.

Max.

-0.98150 0.00000 0.01852 0.00000 0.02041 0.20000


> plot(winetype)
> text(winetype)
> winetype
node), split, n, deviance, yval
* denotes terminal node

1) root 178 106.3000 1.938


2) Flavanoids < 1.575 62 10.8400 2.774
4) Color_intensity < 3.825 13 0.0000 2.000 *
5) Color_intensity > 3.825 49 0.9796 2.980 *
3) Flavanoids > 1.575 116 28.9900 1.491
6) Proline < 724.5 54 0.9815 1.981 *
7) Proline > 724.5 62 3.7420 1.065
14) Color_intensity < 3.55 5 0.8000 1.800 *
15) Color_intensity > 3.55 57 0.0000 1.000 *

Potrebbero piacerti anche