Skip to content

Instantly share code, notes, and snippets.

@dgrapov
Created August 21, 2015 13:42
Show Gist options
  • Save dgrapov/4036496f5672e872a83f to your computer and use it in GitHub Desktop.
Save dgrapov/4036496f5672e872a83f to your computer and use it in GitHub Desktop.
Testing RECA: Relevant Component Analysis for Supervised Distance Metric Learning
#R code, testing RECA with the iris data
library(RECA)
#test data
data(iris)
x<-iris[,-5]
y<-iris$Species
#similar groups (species) in each chunk (n=3)
chunksvec<-as.numeric(y)
xnew <- rca(x, chunksvec)$newX
plot(x[, 1], x[, 2], bg = rainbow(length(unique(y)),alpha=.75)[factor(y)], pch=21)
#different species in each chunk (n=50)
chunksvec<-rep(1:50,3)[1:nrow(x)]
xnew <- rca(x, chunksvec)$newX
plot(xnew[, 1], xnew[, 2], bg = rainbow(length(unique(y)),alpha=.75)[factor(y)], pch=21)
# note the number of chunks does not impact the class resolution
# 2 chunks including every other sample
#gives almost identical results to above
chunksvec<-rep(c(1,2),length.out=nrow(x))
xnew <- rca(x, chunksvec)$newX
plot(xnew[, 1], xnew[, 2], bg = rainbow(length(unique(y)),alpha=.75)[factor(y)], pch=21)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment