Learn R Programming

bmrm (version 4.1)

ordinalRegressionLoss: The loss function for ordinal regression

Description

The loss function for ordinal regression

Usage

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

Arguments

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.

Value

a function taking one argument w and computing the loss value and the gradient at point w

References

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

See Also

nrbm

Examples

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

# -- Train the model
w <- nrbm(ordinalRegressionLoss(x,y),LAMBDA=0.001,EPSILON_TOL=0.0001)
w2 <- nrbm(ordinalRegressionLoss(x,y,impl="quadratic"),LAMBDA=0.001,EPSILON_TOL=0.0001)

# -- plot predictions
f <- x %*% w
f2 <- x %*% w2
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