0

I have a decision tree stored as follows(using data.tree)(in R) :

Sex
¦--Male
¦ °--Class
¦ ¦--3rd
¦ ¦ °--Age
¦ ¦ ¦--Child
¦ ¦ ¦ °--No ¦ ¦ °--Adult
¦ ¦ °--No ¦ ¦--1st
¦ ¦ °--Age
¦ ¦ ¦--Adult
¦ ¦ ¦ °--No ¦ ¦ °--Child
¦ ¦ °--Yes ¦ ¦--2nd
¦ ¦ °--Age
¦ ¦ ¦--Adult
¦ ¦ ¦ °--No ¦ ¦ °--Child
¦ ¦ °--Yes ¦ °--Crew
¦ °--Age
¦ °--Adult
¦ °--No °--Female
°--Class
¦--3rd
¦ °--Age
¦ ¦--Child
¦ ¦ °--No ¦ °--Adult
¦ °--No ¦--1st
¦ °--Age
¦ ¦--Adult
¦ ¦ °--Yes ¦ °--Child
¦ °--Yes ¦--2nd
¦ °--Age
¦ ¦--Adult
¦ ¦ °--Yes ¦ °--Child
¦ °--Yes °--Crew
°--Age
°--Adult
°--Yes

This tree is stored in a variable : root
I want to prune the tree(calculate the chi-square values for all nodes with level = 6 and if their chi-square values are less than a threshold(example 6), then delete that node from the tree).

Any help would be much appreciated.

EDIT: I'm using the following dataset :
"","Class","Sex","Age","Survived"
"1","1st","Male","Child","No"
"2","2nd","Male","Child","No"
"3","3rd","Male","Child","No"
.
.
.

Using This, I use ID3 algorithm to create a decision tree. Now, I wanted to prune it.enter image description here

Siddharth Sharma
  • 182
  • 1
  • 1
  • 10
  • Use `Do` to walk the tree and calculate chi-square. Then use `Prune` directly. The representation of the tree is somewhat distorted. Pls use dput for your data. – Christoph Glur Sep 11 '16 at 14:48
  • You'll get a better answer if you provide a reproducible example – Hack-R Sep 11 '16 at 14:58
  • @Hack-R Please see edit. – Siddharth Sharma Sep 11 '16 at 15:05
  • @SiddharthSharma Thanks, that helps. For the R tag the way they generally like you to provide a reproducible example is to `dput()` the data then supply all code and library statements necessary to reproduce the error or problem. For more details check out the R tag description and this link: http://stackoverflow.com/help/mcve – Hack-R Sep 11 '16 at 16:25

0 Answers0