wrap_ranger: S3 wrapper for ranger

View source: R/wrap_ranger.R

wrap_rangerR Documentation

S3 wrapper for ranger

Description

Fits a 'ranger' random forest with a consistent interface. Supports both classification (factor 'y') and regression (numeric 'y').

Usage

wrap_ranger(x, y, ...)

## S3 method for class 'wrap_ranger'
predict(object, newx, type = c("class", "prob"), ...)

## S3 method for class 'wrap_ranger'
print(x, ...)

Arguments

x

A matrix or data.frame of features.

y

A factor or character vector for classification, numeric for regression.

...

Additional arguments passed to [ranger::ranger()].

object

A fitted 'wrap_ranger' object.

newx

A matrix or data.frame of new observations.

type

'"class"' (default) for class labels, '"prob"' for a probability matrix. Ignored for regression.

Value

An object of class 'wrap_ranger' with fields:

fit

The fitted ranger model.

levels

Class levels (NULL for regression).

task

"classification" or "regression".

Examples


X <- as.matrix(iris[, 1:4])
y <- iris$Species
mod <- wrap_ranger(X, y, num.trees = 100L)
predict(mod, newx = X, type = "class")
predict(mod, newx = X, type = "prob")


X <- as.matrix(iris[, 1:4])
y <- iris$Species
mod <- wrap_ranger(X, y, num.trees = 100L)
predict(mod, newx = X, type = "class")
predict(mod, newx = X, type = "prob")


mlS3 documentation built on April 29, 2026, 1:08 a.m.