web123456

【Feature Selection】1-feature recursive elimination Recursive Feature Elimination

soundfeature selection(feature set selection) can sometimes give themouldRepresentation and Interpretation, Succinctness Bring Benefits. This paper is based on thegradient boosting machine and supportvector Machine is an example of this process.

Applied Machine Learning Using mlr3 in R - 6  Feature Selection

mlr-org - Recursive Feature Elimination on the Sonar Data Set

‘Currently, RFE works with support vector machines (SVM), decision tree algorithms and gradient boosting machines (GBM). Supported learners are tagged with the "importance" property.' (RFEs are ranked based on importance)

RFE-CVbeRFEA variant of。‘RFE-CV estimates the optimal number of features with cross-validation first. Then one more RFE is carried out on the complete dataset with the optimal number of features as the final feature set size.’

Typical RFE:

  1. Creating an optimizer and storing the relevant parameter settings
  2. Creating Machine Learning Tasks
  3. Creating a Machine Learner
  4. define the feature selection problem
  5. commander-in-chief (military)feature selection problempass on tooptimizer
  6. Train the final model with the best feature set on the full dataset and the test set to evaluate its performance
  1. library(mlr3verse)
  2. #1,retrieve the RFE optimizer with the fs() function.
  3. optimizer = fs("rfe",
  4. n_features = 1,
  5. feature_number = 1,
  6. aggregation = "rank")
  7. #The optimizer stops when the number of features equals n_features.
  8. #The parameters feature_number, feature_fraction and subset_size determine the #number of features that are removed in each iteration.
  9. #2
  10. task = tsk("sonar")
  11. #3
  12. learner = lrn("",
  13. distribution = "bernoulli",
  14. predict_type = "prob")
  15. #4
  16. instance = fsi(
  17. task = task,
  18. learner = learner,
  19. resampling = rsmp("cv", folds = 6),#ResamplingStrategy 60% off cv
  20. measures = msr(""),#Model performance metrics for auc
  21. terminator = trm("none"))#Endpoint: none, because we previously set the final feature count as the endpoint.
  22. #5
  23. optimizer$optimize(instance)
  24. instance$result

 

Visualization of the feature selection process

  1. library(viridisLite)
  2. library(mlr3misc)
  3. data = as.data.table(instance$archive)
  4. data[, n:= map_int(importance, length)]
  5. ggplot(data, aes(x = n, y = )) +
  6. geom_line(
  7. color = viridis(1, begin = 0.5),
  8. linewidth = 1) +
  9. geom_point(
  10. fill = viridis(1, begin = 0.5),
  11. shape = 21,
  12. size = 3,
  13. stroke = 0.5,
  14. alpha = 0.8) +
  15. xlab("Number of Features") +
  16. scale_x_reverse() +
  17. theme_minimal()

Optimization path of the feature selection. We observe that the performance increases first as the number of features decreases. As soon as informative features are removed, the performance drops.

RFE-CV:

Principle: RFE-CV determines the optimal number of features by CV before filtering them.

RFE-CV estimates the optimal number of features before selecting a feature set. For this, an RFE is run in each resampling iteration and the number of features with the best mean performance is selected. Then one more RFE is carried out on the complete dataset with the optimal number of features as the final feature set size.

 

 

  1. optimizer = fs("rfecv",
  2. n_features = 1,
  3. feature_number = 1) #no aggregation needed
  4. learner = lrn("",
  5. type = "C-classification",
  6. kernel = "linear",
  7. predict_type = "prob")
  8. instance = fsi(
  9. task = task,
  10. learner = learner,
  11. resampling = rsmp("cv", folds = 6),#6 fold cv to determine feature set size
  12. measures = msr(""),
  13. terminator = trm("none"),
  14. callback = clbk("mlr3fselect.svm_rfe"))
  15. optimizer$optimize(instance)
  16. library(ggplot2)
  17. library(viridisLite)
  18. library(mlr3misc)
  19. data = (instance$archive)[!(iteration), ]
  20. aggr = data[, list("y" = mean(unlist(.SD))), by = "batch_nr", .SDcols = ""]
  21. aggr[, batch_nr := 61 - batch_nr]
  22. data[, n:= map_int(importance, length)]
  23. ggplot(aggr, aes(x = batch_nr, y = y)) +
  24. geom_line(
  25. color = viridis(1, begin = 0.5),
  26. linewidth = 1) +
  27. geom_point(
  28. fill = viridis(1, begin = 0.5),
  29. shape = 21,
  30. size = 3,
  31. stroke = 0.5,
  32. alpha = 0.8) +
  33. geom_vline(
  34. xintercept = aggr[y == max(y)]$batch_nr,
  35. colour = viridis(1, begin = 0.33),
  36. linetype = 3
  37. ) +
  38. xlab("Number of Features") +
  39. ylab("Mean AUC") +
  40. scale_x_reverse() +
  41. theme_minimal()
  42. #We subset the task to the optimal feature set and train the learner.
  43. task$select(instance$result_feature_set)
  44. learner$train(task)
  45. #The trained model can now be used to predict new, external data.

 Estimation of the optimal number of features. The best mean performance is achieved with 19 features (blue line).