2
$\begingroup$

I have an issue understanding the numbers of each node. The dataset is from Kaggle - human resources analytics and the dataset can be downloaded directly from here.

The image knitted looks like this: enter image description here

The figure indicates 8571 out of 11249 stayed. Double checking it in the R console, this seems correct:

table( training_set$left == 0 )

FALSE  TRUE 
 2678  8571 

However, in the image the node to the left ("satisfaction_level >= 0.46 == YES") shows 7345/8116 have stayed. But double checking in R, these are the numbers.

 table(training_set$satisfaction_level >= 0.46  & training_set$left == 0 )

FALSE  TRUE 
 3882  7367

Am I missing something or reading something wrong? Thanks for your help. :)

P.S.: This is my code:

{r echo=FALSE, fig.width=13}
    # Plotting
    # Importing the dataset
    dataset = read.csv('HR_comma_sep.csv')
    #dataset = subset(dataset, ,-c(sales, salary))

    # Encoding categorical data
    dataset$sales = as.numeric(factor(dataset$sales,
                                      levels = c('accounting', 'hr','IT','management','marketing',
                                                 'product_mng', 'RandD','sales', 'support', 'technical'),
                                      labels = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)))

    dataset$salary = as.numeric(factor(dataset$salary,
                                       levels = c('high', 'medium','low'),
                                       labels = c(3, 2, 1)))
    # Encoding the target feature as factor
    dataset$left = as.factor(dataset$left)

    # quick check if all vars are numbers for future computation
    str(dataset)

    # Splitting the dataset into the Training set and Test set
    # install.packages('caTools')
    library(caTools)
    set.seed(127)
    split = sample.split(dataset$left, SplitRatio = 0.75)
    training_set = subset(dataset, split == TRUE)
    test_set = subset(dataset, split == FALSE)

    library("rpart")
    library("rpart.plot")

    pred_simple_tree = rpart(left ~ ., data = training_set)
    rpart.plot(pred_simple_tree, type = 1, fallen.leaves = F, cex = 1, extra = 102, under = T)
$\endgroup$

closed as off-topic by mkt, Michael Chernick, Peter Flom Aug 4 at 11:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – mkt, Michael Chernick, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ @AlexR. additional parenthesis prints the same resuts. table(training_set$satisfaction_level >= 0.46) prints FALSE TRUE 8349 2900. Now I'm more confused than before :/ $\endgroup$ – Amir Rahbaran May 20 '17 at 10:11
  • $\begingroup$ Have you got any missing data? Rpart uses surrogate values when the split variable is missing. $\endgroup$ – Peter Flom Aug 4 at 11:07