Fit regression random forest to klassets_xy
object
Arguments
- df
A object from
sim_xy
.- 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
df <- sim_xy()
df
#> # A tibble: 500 × 2
#> x y
#> <dbl> <dbl>
#> 1 1.87 3.22
#> 2 2.16 4.59
#> 3 2.32 4.50
#> 4 2.34 4.02
#> 5 2.39 4.19
#> 6 2.61 4.55
#> 7 2.68 4.67
#> 8 2.78 3.53
#> 9 2.80 5.13
#> 10 2.94 3.77
#> # … with 490 more rows
dfrrf <- fit_regression_random_forest(df)
dfrrf
#> # A tibble: 500 × 3
#> x y prediction
#> <dbl> <dbl> <dbl>
#> 1 1.87 3.22 3.71
#> 2 2.16 4.59 4.39
#> 3 2.32 4.50 4.38
#> 4 2.34 4.02 4.30
#> 5 2.39 4.19 4.30
#> 6 2.61 4.55 4.49
#> 7 2.68 4.67 4.49
#> 8 2.78 3.53 4.09
#> 9 2.80 5.13 4.61
#> 10 2.94 3.77 3.85
#> # … with 490 more rows
plot(dfrrf)
df <- sim_xy(n = 1000, x_dist = runif)
df <- dplyr::mutate(df, y = y + 2*sin(5 * x))
plot(df)
plot(fit_regression_random_forest(df))
plot(fit_regression_random_forest(df, ntree = 100, maxdepth = 3))