Implementation of Decision Tree in R

#1

Dear friends can any one suggest how to implement this in r studio.
Train the Decision Tree on 'Weather' data set and report the Decision Tree and cross-validation results. Convert the Decision Trees into "if-then-else rules".

0 Likes

#2

This sounds a lot like homework questions, so heads up about our homework policy: FAQ: Homework Policy

TL:DR How to Ask a Homework Related Question:

  1. Do not ask verbatim copy-paste questions
  2. Explicitly mention the course you are taking.
  3. Be sure to ask your question as close to a reproducible example (reprex) as you can. Preferably using the reprex-package
1 Like

#3

Hi
I am handling this lab first time.I am trying lot .I have done upto tree generation,but i dont know how to do cross validation and rules

0 Likes

#4

library(rpart)
dat <- read.table(text ="
Outlook Temp Humidity Windy Play
1 Sunny Hot High FALSE No
2 Sunny Hot High TRUE No
3 Overcast Hot High FALSE Yes
4 Rainy Mild High FALSE Yes
5 Rainy Cool Normal FALSE Yes
6 Rainy Cool Normal TRUE No
7 Overcast Cool Normal TRUE Yes
8 Sunny Mild High FALSE No
9 Sunny Cool Normal FALSE Yes
10 Rainy Mild Normal FALSE Yes
11 Sunny Mild Normal TRUE Yes
12 Overcast Mild High TRUE Yes
13 Overcast Hot Normal FALSE Yes
14 Rainy Mild High TRUE No",
stringsAsFactors = FALSE)
datmodel <- rpart(Play ~ Outlook + Temp + Humidity + Windy,data = dat)
printcp(datmodel)
plotcp(datmodel)

0 Likes

#5

when i am trying to plot the tree using plot(datmodel).. i will get this error Error in plot.rpart(datmodel) : fit is not a tree, just a root

0 Likes

closed #6

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

0 Likes