simulated_annealing: Feature selector that performs simmulated annealing to select...

Description Usage Arguments Value Examples

View source: R/simulated_annealing.R

Description

Algorithm randomly chooses a set of features, trains on them, scores the model. Then the algorithm slightly modifies the chosen features randomly and tests to see if the model improves. If there is improvement, the newer model is kept, if not the algorithm tests to see if the worse model is still kept based on a acceptance probability that decreases as iterations continue and if the model performs worse.

Usage

1
2
3
4
5
6
7
8
9
simulated_annealing(
  scorer,
  X,
  y,
  c = 1,
  iterations = 100,
  bools = FALSE,
  random_state = NULL
)

Arguments

scorer

A custom user-supplied function that accepts X and y (as defined below) as input and returns the error of the datasets.

X

data frame of training features

y

data frame of training targets

c

control rate of feature perturbation

iterations

number of iterations

bools

If true function returns array of boolean values instead of column indicies

random_state

Seed for random number generators

Value

array of selected features

Examples

1
2
3
4
5
6
7
8
9
custom_scorer_fn <- function(data) {
 model <- lm(Y ~ ., data)
 return(mean(model$residuals^2))
}
df <- tgp::friedman.1.data()
data <- dplyr::select(df, -Ytrue)
X <- data[1:(length(data)-1)]
y <- data[length(data)]
features <- featureselection::simulated_annealing(custom_scorer_fn, X, y)

UBC-MDS/feature-selection-r documentation built on April 27, 2020, 7:21 p.m.