setdiff() showing no data in r

33 Views Asked by At

Trying to use a decision tree to predict drug classes, when I set a seed and then set the sample_frac() for my training data & then use setdiff() for my test data im seeing my data within the training data but when i view my training data its showing no data? even tho its showing my decision tree.[[[enter image description here](https://i.stack.imgur.com/wkzA7.png)](https://i.stack.imgur.com/Ltn4v.png)](https://i.stack.imgur.com/nsTcM.png)

data <- data %>% select(BP, Cholesterol, Drug)
view(data)
str(data)

data <- lapply(data, as.factor)
data <- lapply(data, as.numeric)
view(data)


data <- as.data.frame(data)
view(data)

set.seed(111)
data_training <- data %>% sample_frac(0.80)
data_test <- data %>% setdiff(data_training)

view(data_training)
view(data_test)

data_tree <- rpart(Drug ~ BP + Cholesterol, data=data_training, method = 'class')
plot(data_tree, uniform=TRUE, margin=0.5)
text(data_tree, use.n = TRUE)


data_test['Predicted'] <- predict(data_tree, data_test, type = 'class')
view(data_test)
0

There are 0 best solutions below