Learn R Programming

bmrm (version 1.7)

ordinalRegressionLoss: The loss function for ordinal regression

Description

The loss function for ordinal regression

Usage

ordinalRegressionLoss(w, x, y, C = "0/1", impl = c("loglin", "quadratic"),
  cache = NULL)

Arguments

w
weight vector where the function have to be evaluated
x
matrix of training instances (one instance by row)
y
integer vector of positive values (>=1) representing the training labels for each instance in x
C
the cost matrix to use, C[i,j] being the cost for predicting label i instead of label j.
impl
either the string "loglin" or "quadratic", that define the implementation to use for the computation of the loss.
cache
if NULL (which is the case at the first call) parameters values are checked

Value

  • a 2 element list (value,gradient) where "value" is the value of the function at point w, and "gradient" is the gradient of the loss function at w

References

Teo et al. Bundle Methods for Regularized Risk Minimization JMLR 2010

See Also

bmrm

Examples

Run this code
# -- Load the data
x <- data.matrix(iris[1:4])
y <- as.integer(iris$Species)

# -- Train the model
m <- bmrm(x,y,lossfun=ordinalRegressionLoss,LAMBDA=0.001,EPSILON_TOL=0.0001)
m2 <- bmrm(x,y,impl="quadratic",lossfun=ordinalRegressionLoss,LAMBDA=0.001,EPSILON_TOL=0.0001)

# -- plot predictions
f <- x %*% m$w
f2 <- x %*% m2$w
layout(1:2)
plot(y,f)
plot(f,f2,main="compare predictions of quadratic and loglin implementations")

# -- Compute accuracy
ij <- expand.grid(i=seq(nrow(x)),j=seq(nrow(x)))
n <- tapply(f[ij$i] - f[ij$j]>0,list(y[ij$i],y[ij$j]),sum)
N <- table(y[ij$i],y[ij$j])
print(n/N)

Run the code above in your browser using DataLab