In a given data, when a function is used a user receives the following error.

336    Asked by AishwaryaJhadav in Data Science , Asked on Nov 5, 2019
Answered by Aishwarya Jhadav

       Siblings Children Gender Survival

1 Y Y F Y

2 N Y M N

3 Y Y M Y

4 N N F N

5 Y N F N

6 N Y F N

7 Y Y M N

8 Y Y M Y

9 Y N F Y

10 Y Y F N

11 Y N M N

The following function and the error is given below

fit <- rpart(Survival ~ Gender + Children + Siblings,

             data = data1, method = "class")

plot(fit)


The error is because the data is not enough for R to display something meaningful.

In such case, the fancyRpartPlot function from the rattle package works better with smaller data sets:

The below code can help fix the problem

library(rattle)

fit <- rpart(Survival ~ Gender + Children + Siblings,

             data = data, method = "class",

             control = rpart.control(minbucket=2))

fancyRpartPlot(fit, sub=NULL)

The code gives the following results

 



Your Answer

Interviews

Parent Categories