1
$\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$
  • $\begingroup$ There are a number of strange issues here. You claim that 8571 stayed, but really the split is telling you that 8571 have a satisfaction level of $>=0.46$. So why is the "stayed" part in the data set equal to this? Next, we would expect 8571 people in the "time_spend_company" node, but it shows 8116. Where did the few hundred go? Also, do parenthesis help? : table((training_set$satisfaction_level >= 0.46) & (training_set$left == 0 )) $\endgroup$ – Alex R. May 19 '17 at 17:31
  • $\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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.