Description Usage Arguments Value Examples
View source: R/extend_mondrian_forest.R
mondrian_forest
implements a fast (looks at multiple new observations
at once) version of Lakshminarayanan et al's Extend Mondrian Block algorithm
described in [Lakshminarayanan et al. 2014]
(https://arxiv.org/abs/1406.2673) with a modification allowing for more
space-efficient treatment of categorical variables as if they were
dummy-encoded.
1 | extend_mondrian_forest(mforest, newdata)
|
mforest |
A mondrianforest. |
newdata |
Data (matrix or data frame) containing new data to extend the forest. |
A mondrianforest.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | library(mondrianforest); library(dplyr); library(purrr); library(magrittr)
set.seed(1)
test <- data.frame(x1 = rnorm(1000),
x2 = runif(1000),
x3 = rbeta(n = 1000, shape1 = 3, shape2 = 8),
# x3 is noise
x4 = rbinom(n = 1000, size = 4, prob = 0.2)) %>%
map_df(function(x) (x - min(x))/(max(x) - min(x))) %>%
mutate(y = x1*x2^2 + exp(x1) - x4,
x1 = cut_number(sin(x1), n = 10),
label = as.factor(case_when(y < 1 ~ "A",
y >=1 & y < 1.7 ~ "B",
y >= 1.7 ~ "C",
))) %>%
select(-y)
mf <- mondrian_forest(test[1:5, ], y_col_num = 5, lambda = 3)
table(test$label[751:1000], predict(mf, test[751:1000, ], type = "class"))
mf_ext <- extend_mondrian_forest(mf, test[6:750, ])
table(test$label[751:1000], predict(mf_ext, test[751:1000, ], type = "class"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.