Skip to content

Instantly share code, notes, and snippets.

@alfard
Created November 18, 2013 22:46
Show Gist options
  • Save alfard/7536752 to your computer and use it in GitHub Desktop.
Save alfard/7536752 to your computer and use it in GitHub Desktop.
Mise au format de type LETOR
###############################################################################
####### MISE AU FORMAT LETOR ##################################################
ST4<-NULL
ST2<-NULL
#ec2-79-125-53-143.eu-west-1.compute.amazonaws.com
library(dummies)
library(gtools)
letor <- defmacro(colonne, table, expr={
#table[,colonne]<-paste(grep(colonne, colnames(table)),":",table[,colonne])
table[,colonne]<-paste(match(colonne,names(table)),":",table[,colonne])
table[,colonne] <- gsub(pattern = " ", replacement = "", x = table[,colonne])
table[,colonne] <- gsub(pattern = "\\d\\d.NA$", replacement = "", x = table[,colonne])
table[,colonne] <- gsub(pattern = "\\d.NA$", replacement = "", x = table[,colonne])
})
t<-as.data.frame(dummy(ST3$site_id))
t1<-as.data.frame(dummy(ST3$visitor_location_country_id))
t2<-as.data.frame(dummy(ST3$prop_country_id))
t3<-as.data.frame(dummy(ST3$prop_starrating))
t4<-as.data.frame(dummy(ST3$prop_review_score))
#t5<-as.data.frame(dummy(ST3$srch_destination_id))
ST3$site_id <- NULL
ST3$visitor_location_country_id <- NULL
ST3$prop_country_id <- NULL
ST3$prop_starrating <- NULL
ST3$prop_review_score <- NULL
ST3$srch_destination_id <- NULL
ST3$V4 <- NULL
ST3$prop_id <- NULL
ST4<-cbind(ST3,t,t1,t2,t3,t4)
ST4$srch_id <- paste("qid",":",ST4$srch_id)
ST4$srch_id <- gsub(pattern = " ", replacement = "", x = ST4$srch_id)
ST3 <-NULL
t<-NULL
t1<-NULL
t2<-NULL
t3<-NULL
t4<-NULL
t5<-NULL
for (i in 3:302) {
letor(colnames(ST4)[i],ST4)
print(i)
}
write.table(ST4, "/home/alfard/train.dat", sep="\t",quote=FALSE,col.names=FALSE,row.names=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment