protoclass: Greedy algorithm for prototype selection

Description Usage Arguments Details Value See Also Examples

View source: R/protoclass.r

Description

Selects prototypes for each class in a greedy manner as described in 'Bien and Tibshirani (2011) Prototype Selection for Interpretable Classification. Annals of Applied Statistics. 5(4). 2403-2424.'

protoclass

Usage

1
  protoclass(x, y, z, dxz, eps, lambda = 1/n)

Arguments

x

n by p matrix of training features (optional, see dxz).

y

n-vector of labels of the training data.

z

set of potential prototypes (optional, see dxz).

dxz

instead of x and z, you can give dxz, the matrix of pairwise dissimilarities between x and z, with ij-th element giving the dissimilarity between training point x_i and prototype-candidate z_j.

eps

size of covering balls.

lambda

cost of adding a prototype.

Details

It's more efficient to compute dxz just once on your own rather than have protoclass repeatedly compute the pairwise distances on each call.

Value

An object of class "protoclass," which has the following elements:

See Also

predict.protoclass

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# generate some data:
set.seed(1)
n <- 200
p <- 2
x <- matrix(rnorm(n * p), n, p)
y <- rep(c("A","B"), each=n/2)
x[y=="A", ] <- x[y=="A", ] + 3
itr <- sample(n, n/2)
xtr <- x[itr, ] # train
ytr <- y[itr]
xte <- x[-itr, ] # test
yte <- y[-itr]

# take prototype candidates identical to training points:
z <- xtr
dxz <- dist2(xtr, z)
# run protoclass:
prot <- protoclass(dxz=dxz, y=ytr, eps=2, lambda=1/n)
## Not run: 
plot(prot,xtr,y=1+(ytr=="A"))

## End(Not run)
# get predictions on test data:
pred1 <- predict(prot, xte, z=xtr)
# get predictions on test data using pairwise distances:
pred2 <- predictwithd.protoclass(prot, dist2(xte, z))

Example output

Loading required package: class

protoclass documentation built on May 2, 2019, 3:42 a.m.