Q2
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
Response: nativeSpeaker
4)* weights = 24
6)* weights = 22
5) age > 6
8)* weights = 13
9)* weights = 11
10)* weights = 51
12)* weights = 29
14)* weights = 16
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
>
a<-data.frame(age=11,shoeSize=30.63692,score=55.721149)
>a
1 11 30.63692 55.72115
> predict(dtm,a,type="class")
yes
Levels: no yes
>