Description Usage Arguments Details Value Author(s) See Also Examples
The algorithm for searching atrribute subset space.
1 | best.first.search(attributes, eval.fun, max.backtracks = 5)
|
attributes |
a character vector of all attributes to search in |
eval.fun |
a function taking as first parameter a character vector of all attributes and returning a numeric indicating how important a given subset is |
max.backtracks |
an integer indicating a maximum allowed number of backtracks, default is 5 |
The algorithm is similar to forward.search
besides the fact that is chooses the best node from all already evaluated ones and evaluates it. The selection of the best node is repeated approximately max.brackets
times in case no better node found.
A character vector of selected attributes.
Piotr Romanski
forward.search
, backward.search
, hill.climbing.search
, exhaustive.search
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | library(rpart)
data(iris)
evaluator <- function(subset) {
#k-fold cross validation
k <- 5
splits <- runif(nrow(iris))
results = sapply(1:k, function(i) {
test.idx <- (splits >= (i - 1) / k) & (splits < i / k)
train.idx <- !test.idx
test <- iris[test.idx, , drop=FALSE]
train <- iris[train.idx, , drop=FALSE]
tree <- rpart(as.simple.formula(subset, "Species"), train)
error.rate = sum(test$Species != predict(tree, test, type="c")) / nrow(test)
return(1 - error.rate)
})
print(subset)
print(mean(results))
return(mean(results))
}
subset <- best.first.search(names(iris)[-5], evaluator)
f <- as.simple.formula(subset, "Species")
print(f)
|
OpenJDK 64-Bit Server VM warning: Can't detect initial thread stack location - find_vma failed
[1] "Sepal.Length"
[1] 0.7346628
[1] "Sepal.Width"
[1] 0.5220969
[1] "Petal.Length"
[1] 0.9527062
[1] "Petal.Width"
[1] 0.9538031
[1] "Sepal.Length" "Petal.Width"
[1] 0.9567252
[1] "Sepal.Width" "Petal.Width"
[1] 0.9617426
[1] "Petal.Length" "Petal.Width"
[1] 0.9290652
[1] "Sepal.Length" "Sepal.Width" "Petal.Width"
[1] 0.9594957
[1] "Sepal.Width" "Petal.Length" "Petal.Width"
[1] 0.9413296
Species ~ Sepal.Width + Petal.Width
<environment: 0x365a0e0>
Warning message:
system call failed: Cannot allocate memory
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.