Skip to content

Instantly share code, notes, and snippets.

@chathurawidanage
Created August 21, 2016 07:47
Show Gist options
  • Save chathurawidanage/2b72de0697e0b17131da6a1f9c9f5236 to your computer and use it in GitHub Desktop.
Save chathurawidanage/2b72de0697e0b17131da6a1f9c9f5236 to your computer and use it in GitHub Desktop.
library(data.table)
print('Reading data')
train <-fread('F:\\engineering\\Semester 7_8\\ML\\keggle\\train.csv',select = c('Cliente_ID', 'Producto_ID', 'Agencia_ID', 'Ruta_SAK', 'Demanda_uni_equil','Canal_ID'))
mean_Can <- train[, .(mean_Can = mean(Demanda_uni_equil)), by = .(Canal_ID)]
train <- merge(train, mean_Can, all.x = TRUE, by = c("Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_Can,method="spearman")," -> Canal_ID"))
train$mean_Can <- NULL
mean_Can <- NULL
gc()
mean_Rut <- train[, .(mean_Rut = mean(Demanda_uni_equil)), by = .(Ruta_SAK)]
train <- merge(train, mean_Rut, all.x = TRUE, by = c("Ruta_SAK"))
print(paste(cor(train$Demanda_uni_equil,train$mean_Rut,method="spearman")," -> Ruta_SAK"))
train$mean_Rut <- NULL
mean_Rut <- NULL
gc()
mean_RutCan <- train[, .(mean_RutCan = mean(Demanda_uni_equil)), by = .(Ruta_SAK,Canal_ID)]
train <- merge(train, mean_RutCan, all.x = TRUE, by = c("Ruta_SAK","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_RutCan,method="spearman")," -> Ruta_SAK,Canal_ID"))
train$mean_RutCan <- NULL
mean_RutCan <- NULL
gc()
mean_Age <- train[, .(mean_Age = mean(Demanda_uni_equil)), by = .(Agencia_ID)]
train <- merge(train, mean_Age, all.x = TRUE, by = c("Agencia_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_Age,method="spearman")," -> Agencia_ID"))
train$mean_Age <- NULL
mean_Age <- NULL
gc()
mean_AgeCan <- train[, .(mean_AgeCan = mean(Demanda_uni_equil)), by = .(Agencia_ID,Canal_ID)]
train <- merge(train, mean_AgeCan, all.x = TRUE, by = c("Agencia_ID","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_AgeCan,method="spearman")," -> Agencia_ID,Canal_ID"))
train$mean_AgeCan <- NULL
mean_AgeCan <- NULL
gc()
mean_AgeRut <- train[, .(mean_AgeRut = mean(Demanda_uni_equil)), by = .(Agencia_ID,Ruta_SAK)]
train <- merge(train, mean_AgeRut, all.x = TRUE, by = c("Agencia_ID","Ruta_SAK"))
print(paste(cor(train$Demanda_uni_equil,train$mean_AgeRut,method="spearman")," -> Agencia_ID,Ruta_SAK"))
train$mean_AgeRut <- NULL
mean_AgeRut <- NULL
gc()
mean_AgeRutCan <- train[, .(mean_AgeRutCan = mean(Demanda_uni_equil)), by = .(Agencia_ID,Ruta_SAK,Canal_ID)]
train <- merge(train, mean_AgeRutCan, all.x = TRUE, by = c("Agencia_ID","Ruta_SAK","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_AgeRutCan,method="spearman")," -> Agencia_ID,Ruta_SAK,Canal_ID"))
train$mean_AgeRutCan <- NULL
mean_AgeRutCan <- NULL
gc()
mean_Pro <- train[, .(mean_Pro = mean(Demanda_uni_equil)), by = .(Producto_ID)]
train <- merge(train, mean_Pro, all.x = TRUE, by = c("Producto_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_Pro,method="spearman")," -> Producto_ID"))
train$mean_Pro <- NULL
mean_Pro <- NULL
gc()
mean_ProCan <- train[, .(mean_ProCan = mean(Demanda_uni_equil)), by = .(Producto_ID,Canal_ID)]
train <- merge(train, mean_ProCan, all.x = TRUE, by = c("Producto_ID","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_ProCan,method="spearman")," -> Producto_ID,Canal_ID"))
train$mean_ProCan <- NULL
mean_ProCan <- NULL
gc()
mean_ProRut <- train[, .(mean_ProRut = mean(Demanda_uni_equil)), by = .(Producto_ID,Ruta_SAK)]
train <- merge(train, mean_ProRut, all.x = TRUE, by = c("Producto_ID","Ruta_SAK"))
print(paste(cor(train$Demanda_uni_equil,train$mean_ProRut,method="spearman")," -> Producto_ID,Ruta_SAK"))
train$mean_ProRut <- NULL
mean_ProRut <- NULL
gc()
mean_ProRutCan <- train[, .(mean_ProRutCan = mean(Demanda_uni_equil)), by = .(Producto_ID,Ruta_SAK,Canal_ID)]
train <- merge(train, mean_ProRutCan, all.x = TRUE, by = c("Producto_ID","Ruta_SAK","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_ProRutCan,method="spearman")," -> Producto_ID,Ruta_SAK,Canal_ID"))
train$mean_ProRutCan <- NULL
mean_ProRutCan <- NULL
gc()
mean_ProAge <- train[, .(mean_ProAge = mean(Demanda_uni_equil)), by = .(Producto_ID,Agencia_ID)]
train <- merge(train, mean_ProAge, all.x = TRUE, by = c("Producto_ID","Agencia_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_ProAge,method="spearman")," -> Producto_ID,Agencia_ID"))
train$mean_ProAge <- NULL
mean_ProAge <- NULL
gc()
mean_ProAgeCan <- train[, .(mean_ProAgeCan = mean(Demanda_uni_equil)), by = .(Producto_ID,Agencia_ID,Canal_ID)]
train <- merge(train, mean_ProAgeCan, all.x = TRUE, by = c("Producto_ID","Agencia_ID","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_ProAgeCan,method="spearman")," -> Producto_ID,Agencia_ID,Canal_ID"))
train$mean_ProAgeCan <- NULL
mean_ProAgeCan <- NULL
gc()
mean_ProAgeRut <- train[, .(mean_ProAgeRut = mean(Demanda_uni_equil)), by = .(Producto_ID,Agencia_ID,Ruta_SAK)]
train <- merge(train, mean_ProAgeRut, all.x = TRUE, by = c("Producto_ID","Agencia_ID","Ruta_SAK"))
print(paste(cor(train$Demanda_uni_equil,train$mean_ProAgeRut,method="spearman")," -> Producto_ID,Agencia_ID,Ruta_SAK"))
train$mean_ProAgeRut <- NULL
mean_ProAgeRut <- NULL
gc()
mean_ProAgeRutCan <- train[, .(mean_ProAgeRutCan = mean(Demanda_uni_equil)), by = .(Producto_ID,Agencia_ID,Ruta_SAK,Canal_ID)]
train <- merge(train, mean_ProAgeRutCan, all.x = TRUE, by = c("Producto_ID","Agencia_ID","Ruta_SAK","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_ProAgeRutCan,method="spearman")," -> Producto_ID,Agencia_ID,Ruta_SAK,Canal_ID"))
train$mean_ProAgeRutCan <- NULL
mean_ProAgeRutCan <- NULL
gc()
mean_Cli <- train[, .(mean_Cli = mean(Demanda_uni_equil)), by = .(Cliente_ID)]
train <- merge(train, mean_Cli, all.x = TRUE, by = c("Cliente_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_Cli,method="spearman")," -> Cliente_ID"))
train$mean_Cli <- NULL
mean_Cli <- NULL
gc()
mean_CliCan <- train[, .(mean_CliCan = mean(Demanda_uni_equil)), by = .(Cliente_ID,Canal_ID)]
train <- merge(train, mean_CliCan, all.x = TRUE, by = c("Cliente_ID","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliCan,method="spearman")," -> Cliente_ID,Canal_ID"))
train$mean_CliCan <- NULL
mean_CliCan <- NULL
gc()
mean_CliRut <- train[, .(mean_CliRut = mean(Demanda_uni_equil)), by = .(Cliente_ID,Ruta_SAK)]
train <- merge(train, mean_CliRut, all.x = TRUE, by = c("Cliente_ID","Ruta_SAK"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliRut,method="spearman")," -> Cliente_ID,Ruta_SAK"))
train$mean_CliRut <- NULL
mean_CliRut <- NULL
gc()
mean_CliRutCan <- train[, .(mean_CliRutCan = mean(Demanda_uni_equil)), by = .(Cliente_ID,Ruta_SAK,Canal_ID)]
train <- merge(train, mean_CliRutCan, all.x = TRUE, by = c("Cliente_ID","Ruta_SAK","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliRutCan,method="spearman")," -> Cliente_ID,Ruta_SAK,Canal_ID"))
train$mean_CliRutCan <- NULL
mean_CliRutCan <- NULL
gc()
mean_CliAge <- train[, .(mean_CliAge = mean(Demanda_uni_equil)), by = .(Cliente_ID,Agencia_ID)]
train <- merge(train, mean_CliAge, all.x = TRUE, by = c("Cliente_ID","Agencia_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliAge,method="spearman")," -> Cliente_ID,Agencia_ID"))
train$mean_CliAge <- NULL
mean_CliAge <- NULL
gc()
mean_CliAgeCan <- train[, .(mean_CliAgeCan = mean(Demanda_uni_equil)), by = .(Cliente_ID,Agencia_ID,Canal_ID)]
train <- merge(train, mean_CliAgeCan, all.x = TRUE, by = c("Cliente_ID","Agencia_ID","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliAgeCan,method="spearman")," -> Cliente_ID,Agencia_ID,Canal_ID"))
train$mean_CliAgeCan <- NULL
mean_CliAgeCan <- NULL
gc()
mean_CliAgeRut <- train[, .(mean_CliAgeRut = mean(Demanda_uni_equil)), by = .(Cliente_ID,Agencia_ID,Ruta_SAK)]
train <- merge(train, mean_CliAgeRut, all.x = TRUE, by = c("Cliente_ID","Agencia_ID","Ruta_SAK"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliAgeRut,method="spearman")," -> Cliente_ID,Agencia_ID,Ruta_SAK"))
train$mean_CliAgeRut <- NULL
mean_CliAgeRut <- NULL
gc()
mean_CliAgeRutCan <- train[, .(mean_CliAgeRutCan = mean(Demanda_uni_equil)), by = .(Cliente_ID,Agencia_ID,Ruta_SAK,Canal_ID)]
train <- merge(train, mean_CliAgeRutCan, all.x = TRUE, by = c("Cliente_ID","Agencia_ID","Ruta_SAK","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliAgeRutCan,method="spearman")," -> Cliente_ID,Agencia_ID,Ruta_SAK,Canal_ID"))
train$mean_CliAgeRutCan <- NULL
mean_CliAgeRutCan <- NULL
gc()
mean_CliPro <- train[, .(mean_CliPro = mean(Demanda_uni_equil)), by = .(Cliente_ID,Producto_ID)]
train <- merge(train, mean_CliPro, all.x = TRUE, by = c("Cliente_ID","Producto_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliPro,method="spearman")," -> Cliente_ID,Producto_ID"))
train$mean_CliPro <- NULL
mean_CliPro <- NULL
gc()
mean_CliProCan <- train[, .(mean_CliProCan = mean(Demanda_uni_equil)), by = .(Cliente_ID,Producto_ID,Canal_ID)]
train <- merge(train, mean_CliProCan, all.x = TRUE, by = c("Cliente_ID","Producto_ID","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliProCan,method="spearman")," -> Cliente_ID,Producto_ID,Canal_ID"))
train$mean_CliProCan <- NULL
mean_CliProCan <- NULL
gc()
mean_CliProRut <- train[, .(mean_CliProRut = mean(Demanda_uni_equil)), by = .(Cliente_ID,Producto_ID,Ruta_SAK)]
train <- merge(train, mean_CliProRut, all.x = TRUE, by = c("Cliente_ID","Producto_ID","Ruta_SAK"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliProRut,method="spearman")," -> Cliente_ID,Producto_ID,Ruta_SAK"))
train$mean_CliProRut <- NULL
mean_CliProRut <- NULL
gc()
mean_CliProRutCan <- train[, .(mean_CliProRutCan = mean(Demanda_uni_equil)), by = .(Cliente_ID,Producto_ID,Ruta_SAK,Canal_ID)]
train <- merge(train, mean_CliProRutCan, all.x = TRUE, by = c("Cliente_ID","Producto_ID","Ruta_SAK","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliProRutCan,method="spearman")," -> Cliente_ID,Producto_ID,Ruta_SAK,Canal_ID"))
train$mean_CliProRutCan <- NULL
mean_CliProRutCan <- NULL
gc()
mean_CliProAge <- train[, .(mean_CliProAge = mean(Demanda_uni_equil)), by = .(Cliente_ID,Producto_ID,Agencia_ID)]
train <- merge(train, mean_CliProAge, all.x = TRUE, by = c("Cliente_ID","Producto_ID","Agencia_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliProAge,method="spearman")," -> Cliente_ID,Producto_ID,Agencia_ID"))
train$mean_CliProAge <- NULL
mean_CliProAge <- NULL
gc()
mean_CliProAgeCan <- train[, .(mean_CliProAgeCan = mean(Demanda_uni_equil)), by = .(Cliente_ID,Producto_ID,Agencia_ID,Canal_ID)]
train <- merge(train, mean_CliProAgeCan, all.x = TRUE, by = c("Cliente_ID","Producto_ID","Agencia_ID","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliProAgeCan,method="spearman")," -> Cliente_ID,Producto_ID,Agencia_ID,Canal_ID"))
train$mean_CliProAgeCan <- NULL
mean_CliProAgeCan <- NULL
gc()
mean_CliProAgeRut <- train[, .(mean_CliProAgeRut = mean(Demanda_uni_equil)), by = .(Cliente_ID,Producto_ID,Agencia_ID,Ruta_SAK)]
train <- merge(train, mean_CliProAgeRut, all.x = TRUE, by = c("Cliente_ID","Producto_ID","Agencia_ID","Ruta_SAK"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliProAgeRut,method="spearman")," -> Cliente_ID,Producto_ID,Agencia_ID,Ruta_SAK"))
train$mean_CliProAgeRut <- NULL
mean_CliProAgeRut <- NULL
gc()
mean_CliProAgeRutCan <- train[, .(mean_CliProAgeRutCan = mean(Demanda_uni_equil)), by = .(Cliente_ID,Producto_ID,Agencia_ID,Ruta_SAK,Canal_ID)]
train <- merge(train, mean_CliProAgeRutCan, all.x = TRUE, by = c("Cliente_ID","Producto_ID","Agencia_ID","Ruta_SAK","Canal_ID"))
print(paste(cor(train$Demanda_uni_equil,train$mean_CliProAgeRutCan,method="spearman")," -> Cliente_ID,Producto_ID,Agencia_ID,Ruta_SAK,Canal_ID"))
train$mean_CliProAgeRutCan <- NULL
mean_CliProAgeRutCan <- NULL
gc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment