Skip to contents

Fit classification random forest to klassets_response_xy object

Usage

fit_classification_random_forest(
  df,
  type = "prob",
  ntree = 500L,
  maxdepth = NULL,
  trace = FALSE,
  ...
)

Arguments

df

A object from sim_response_xy.

type

Type of prediction, one of prob, response, node.

ntree

Number of trees to grow for the forest.

maxdepth

Max depth of each trees.

trace

A logical indicating if a progress bar shall be printed while the forest grows.

...

Options for ranger::ranger.

Examples


set.seed(123)

df <- sim_response_xy(n = 1000, relationship = function(x, y) x**2 > sin(y))

plot(df)


dfcrf <- fit_classification_random_forest(df)

dfcrf
#> # A tibble: 1,000 × 4
#>    response       x       y prediction
#>    <fct>      <dbl>   <dbl>      <dbl>
#>  1 FALSE    -0.425  -0.453      0.953 
#>  2 FALSE     0.577   0.188      0.754 
#>  3 FALSE    -0.182  -0.680      0.696 
#>  4 FALSE     0.766   0.707      0.188 
#>  5 TRUE      0.881   0.695      0.646 
#>  6 TRUE     -0.909  -0.0442     0.900 
#>  7 FALSE     0.0562  0.547      0.0358
#>  8 FALSE     0.785  -0.409      0.959 
#>  9 FALSE     0.103  -0.869      0.661 
#> 10 TRUE     -0.0868 -0.119      0.691 
#> # … with 990 more rows

plot(dfcrf)