Fit a Decision Tree classifier to the data; Error in code

时间:2017-11-08 22:03:13

标签: r decision-tree

This is the code I entered into RStudio to create a decision tree, and park is a data frame I have in my environment

people <- park %>%
  select(Subj, Parkinson, fhi, jitter, rap, shimmer, apq, nhr) %>%
  na.omit()
glimpse(people)
tally(~ Parkinson, data = people, format = "percent")  # simple table


################
set.seed(1688)
#############

# Tree with rpart
whoHasPark <- rpart(Parkinson ~ Subj, fhi, jitter,
                        data = people, control = rpart.control(cp = 0.005, minbucket = 30))
whoHasPark
plot(as.party(whoHasPark))

This is the error I got back:

Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'

Where did I go wrong?

1 个答案:

答案 0 :(得分:0)

不确定,但这可能是因为你在你的rpart调用中给Parkinson ~ Subj, fhi, jitter(用逗号分隔它们会引发错误)。尝试使用“+”可能会有助Parkinson ~ Subj + fhi + jitter