Learn R Programming

roclab (version 0.1.4)

predict.kroclearn: Predictions from a fitted kernel model

Description

Generate predictions from a fitted kernel model.

Usage

# S3 method for kroclearn
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 "kroclearn" (kernel).

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

kroclearn, cv.kroclearn

Examples

Run this code
set.seed(123)
n <- 100
r <- sqrt(runif(n, 0.05, 1))
theta <- runif(n, 0, 2*pi)
X <- cbind(r * cos(theta), r * sin(theta))
y <- ifelse(r < 0.5, 1, -1)

fit <- kroclearn(X, y, lambda = 0.1, kernel = "radial", 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