Hi everybody,
this is my R script for a decision tree:
library(caret)
library(rpart.plot)
library(plyr)
library(dplyr)
library(rpart)
data("iris")
names(iris) = tolower(names(iris))
table(iris$species)
suppressMessages(library(caret))
index = createDataPartition(y=iris$species, p=0.7, list=FALSE)
train = iris[index,]
test = iris[-index,]
trainctrl <- trainControl(method = "cv", number = 5, verboseIter = FALSE)
dt.model <- train(species~., data=train, method = "rpart",
tuneLength = 10,
preProcess = c("center", "scale"),
trControl = trainctrl,
metric="Kappa")
dt.predict <-predict(dt.model, test)
confusionMatrix(dt.predict, test$species)
rpart.plot(dt.model$finalModel)
varImp(dt.model)
my feature importance are:
> varImp(dt.model)
rpart variable importance
Overall
petal.width 100.00
petal.length 96.95
sepal.length 45.08
sepal.width 0.00
Is there a way to consider less petal.width? For example, I want that my tree use more petal.length and sepal.lenght than petal.width. Is it possible?