Help with CART fitting

Hey guys, i somehow cant fit my train data. I always get this error. "Error in eval(predvars, data, env) : object 'X1' not found" I dont really know why. Please help me.

This is my code:

# Daten einlesen

# Daten splitten
index <- createDataPartition(diabetes$X1, p = 0.8, list = FALSE)
train_data <- elena[index, ]
test_data  <- elena[-index, ]

# Confusion-Matrix für Test-Data
fit_train <- rpart(X1~., data = train_data, method = "class", control = rpart.control(cp = 0))
rpart.plot(fit_train, extra=4)

When I run the code, X1 is there, but elena is missing.

OMG, yeah i messed up. I got it fixed. I just needed to replace elena with diabetes. Do you also know how to plot this dataset like in this picture shown?

1 Like

Help me out with x and y variables?

The target variable should be X1. The other ones dont really matter. Chose any you want. I just want to know the Code. Later i will chose the best variables. Chose any one you want. And is it possible to highlight each class in a different color?

1 Like

I don't think you want a binary response (target) variable.

p <- ggplot(diabetes, aes(,X1))
p + geom_point(aes(X6))

Created on 2020-04-07 by the reprex package (v0.3.0)

@technocrat Okay sure, do you know how i create such a plot like the one above with this dataset. I want to illustrate the imbalance in the target variable.

An imbalance of X0 in the might be better illustrated as a bar graph of the proportion of 1s by covariates. X \sim X_i is always going to look like the example.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.