I'm learning machine learning in R and making a decision tree in R of expired products, where i have the following data:
Product, Category, Temperature, Expire_Day, Rotation_Day, Weight, State
Tapa, Pulpa, 0, 30, 21, 4.21, No
Tapa, Pulpa, 0, 30, 21, 3.82, Expire
Nalga, Pulpa, 0, 30, 25, 6.10, No
Nalga, Pulpa, 0, 30, 25, 5, Expire
Costeleta, Bife, 7, 5, 3, 1.10, No
Costeleta, Bife, 7, 5, 3, 2.25, No
Costeleta, Bife, 7, 5, 3, 0.9, Expire
Brazuelo, Bife, 7, 5, 3, 2.5, No
With this i create the data model by passing the Product and Category series to vector using dummyVars and normalizing the Weight using MinMaxScalar, for Temperature, Expire_Day and Rotation_Day there is a proximity relationship so i didn`t do any conversion and finally convert the State to Factor
The final model is:
Product.Tapa, Product.Nalga, Product.Costeleta, Product.Brazuelo, Category.Pulpa, Category.Bife, Temperature, Expire_Day, Rotation_Day, Weight, State
1, 0, 0, 0, 1, 0, 0, 30, 21, 0.9, No
1, 0, 0, 0, 1, 0, 0, 30, 21, 0.78, Expire
0, 1, 0, 0, 1, 0, 0, 30, 25, 0.99, No
0, 1, 0, 0, 1, 0, 0, 30, 25, 0.72, Expire
0, 0, 1, 0, 0, 1, 7, 5, 3, 0.12, No
0, 0, 1, 0, 0, 1, 7, 5, 3, 0.22, No
0, 0, 1, 0, 0, 1, 7, 5, 3, 0.88, Expire
0, 0, 0, 1, 0, 1, 7, 5, 3, 0.5, No
With this model i create the tree using random forest with the following code:
mtry <- 6
ntree <- 24
rf_model <- randomForest(result ~ .,
data = trainData,
mtry = mtry,
ntree = ntree,
trControl = control,
varimp = TRUE,
importance = TRUE,
weight = data_weights,
oob_score = FALSE)
Up to this point, if i predict i have a precision of 0.90 and works quite well, but i can't make work the decision tree chart where i have 2 conditions to meet:
a- The decision tree must begin with the columns of Expire_Day and Rotation_Day, which are the most important in the series
b- Be able to filter or classify the tree by Category, for example i have to be able to see the tree only of "Pulpa" without showing what corresponds to "Bife" and then change and be able to see only "Bife" or the entire tree if They ask me
i haven't found a way to make it work yet, how should i do it?