Skip to content

Instantly share code, notes, and snippets.

@johnschrom
Last active August 29, 2015 14:22
Show Gist options
  • Save johnschrom/276a83f244ed8af21f83 to your computer and use it in GitHub Desktop.
Save johnschrom/276a83f244ed8af21f83 to your computer and use it in GitHub Desktop.
Predictive Genes
# Data frame for which genes to include by disease
excl <- data.frame('gene' = c(NA), 'round' = c(NA))
# Remove 30% of genes each round
while(nrow(excl) < nrow(d.qn)) {
cat('Running with', excl.n, 'genes excluded...\n')
# Run SVM
svm.model <- svm(t(as.matrix(d.qn[-excl$gene,])), # features, minus excluded genes
tc, # class of each sample
kernel='linear',
cost=1)
# Calculate weights
w <- t(svm.model$coefs) %*% svm.model$SV
# Pick the genes to remove
excl <- rbind(excl,
data.frame(
'round' = nrow(excl),
'gene' = which(rownames(d.qn) %in%
rownames(d.qn)[order(abs(w[1,]))[1:(0.3*(nrow(d.qn)-nrow(excl)))]])))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment