Skip to content

Instantly share code, notes, and snippets.

@dgrapov dgrapov/RECA_test.R
Created Aug 21, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.