parttree icon indicating copy to clipboard operation
parttree copied to clipboard

Voronoi tiling as a plotting option for random forests and boosted trees?

Open grantmcdermott opened this issue 3 years ago • 0 comments

set.seed(42)
library(ranger)  ## Random forests
library(ggforce) ## Voronoi tiling
#> Loading required package: ggplot2

dat = na.omit(palmerpenguins::penguins)

train_ids = sample.int(nrow(dat), 100)
rf_mod = ranger(species ~ flipper_length_mm + bill_length_mm, data=dat[train_ids,])

dat = cbind(dat, pred = predict(rf_mod, dat)$predictions)

ggplot(dat, aes(flipper_length_mm, bill_length_mm, group = -1L)) +
  geom_voronoi_tile(aes(fill = pred), alpha = .3) +
  geom_point(aes(col = species)) +
  theme_minimal()
#> Warning: stat_voronoi_tile: dropping duplicated points

Created on 2022-05-31 by the reprex package (v2.0.1)

grantmcdermott avatar May 31 '22 19:05 grantmcdermott