Learn R Programming

roclab (version 0.1.4)

predict.roclearn: Predictions from a fitted linear model

Description

Generate predictions from a fitted linear model.

Usage

# S3 method for roclearn
predict(object, newdata, type = c("class", "response"), ...)

Value

A numeric vector of predictions ({-1, 1}) if type = "class", or raw decision scores if type = "response".

Arguments

object

A fitted model object of class "roclearn" (linear).

newdata

A data frame or matrix of predictors for which predictions are desired. Categorical variables are automatically dummy-encoded and aligned to the training structure.

type

Prediction type: "class" for {-1, 1} labels, or "response" for raw decision scores.

...

Not used.

See Also

roclearn, cv.roclearn

Examples

Run this code
set.seed(123)
n <- 100
n_pos <- round(0.2 * n)
n_neg <- n - n_pos
X <- rbind(
  matrix(rnorm(2 * n_neg, mean = -1), ncol = 2),
  matrix(rnorm(2 * n_pos, mean =  1), ncol = 2)
)
y <- c(rep(-1, n_neg), rep(1, n_pos))

fit <- roclearn(X, y, lambda = 0.1, approx=TRUE)

# Predict classes {-1, 1}
predict(fit, X, type = "class")

# Predict decision scores
predict(fit, X, type = "response")

Run the code above in your browser using DataLab