0% found this document useful (0 votes)
17 views4 pages

Q2

Uploaded by

Arpit Khandelwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Q2

Uploaded by

Arpit Khandelwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Q2

A decision tree is a graphical representation of specific decision situations that are used when
complex branching occurs in a structured decision process. A decision tree is a predictive model
based on a branching series of Boolean tests that use specific facts to make more generalized
conclusions.

The main components of a decision tree involve decision points represented by nodes, actions and
specific choices from a decision point. Each rule within a decision tree is represented by tracing a
series of paths from root to node to the next node and so on until an action is reached.

install.packages("party")

library(party)

> readingSkills

dataset<-readingSkills

> dataset

tree<-ctree(nativeSpeaker~.,data=dataset)

> tree

Conditional inference tree with 8 terminal nodes

Response: nativeSpeaker

Inputs: age, shoeSize, score

Number of observations: 200

1) score <= 43.34602; criterion = 1, statistic = 44.243

2) shoeSize <= 26.92283; criterion = 0.999, statistic = 13.746

3) score <= 31.08626; criterion = 1, statistic = 25.616

4)* weights = 24

3) score > 31.08626


5) age <= 6; criterion = 1, statistic = 17.578

6)* weights = 22

5) age > 6

7) score <= 38.68543; criterion = 1, statistic = 16.809

8)* weights = 13

7) score > 38.68543

9)* weights = 11

2) shoeSize > 26.92283

10)* weights = 51

1) score > 43.34602

11) age <= 9; criterion = 0.997, statistic = 10.843

12)* weights = 29

11) age > 9

13) score <= 50.2831; criterion = 1, statistic = 30.938

14)* weights = 16

13) score > 50.2831

15)* weights = 34

> plot(tree)

Error in drawGTree(x) :

cannot pop the top-level viewport ('grid' and 'graphics' output mixed?)
dev.off()

library(rpart)

> library(rpart.plot)

> dtm<-rpart(nativeSpeaker~.,dataset,method="class")

> dtm

n= 200

node), split, n, loss, yval, (yprob)

* denotes terminal node

1) root 200 100 no (0.50000000 0.50000000)

2) score< 43.36359 121 39 no (0.67768595 0.32231405)

4) age>=7.5 32 0 no (1.00000000 0.00000000) *

5) age< 7.5 89 39 no (0.56179775 0.43820225)

10) score< 34.89582 59 10 no (0.83050847 0.16949153)

20) age>=5.5 34 0 no (1.00000000 0.00000000) *

21) age< 5.5 25 10 no (0.60000000 0.40000000)

42) score< 29.00584 15 0 no (1.00000000 0.00000000) *

43) score>=29.00584 10 0 yes (0.00000000 1.00000000) *


11) score>=34.89582 30 1 yes (0.03333333 0.96666667) *

3) score>=43.36359 79 18 yes (0.22784810 0.77215190)

6) age>=9.5 50 18 yes (0.36000000 0.64000000)

12) score< 50.34113 16 0 no (1.00000000 0.00000000) *

13) score>=50.34113 34 2 yes (0.05882353 0.94117647) *

7) age< 9.5 29 0 yes (0.00000000 1.00000000) *

> rpart.plot(dtm, type=3,fallen.leaves=TRUE)

>

a<-data.frame(age=11,shoeSize=30.63692,score=55.721149)

>a

age shoeSize score

1 11 30.63692 55.72115

> predict(dtm,a,type="class")

yes

Levels: no yes

>

You might also like