comparison aggregation.R @ 48:cea4a54c52d0 draft

Uploaded
author nicolas
date Wed, 26 Oct 2016 17:31:45 -0400
parents ac0c3826cca4
children
comparison
equal deleted inserted replaced
47:7b9b78352811 48:cea4a54c52d0
10 library("miscTools") 10 library("miscTools")
11 library(rpart) 11 library(rpart)
12 suppressWarnings(suppressMessages(library(randomForest))) 12 suppressWarnings(suppressMessages(library(randomForest)))
13 library(e1071) 13 library(e1071)
14 suppressWarnings(suppressMessages(library(glmnet))) 14 suppressWarnings(suppressMessages(library(glmnet)))
15 options(warn=-1)
15 ############################ helper functions ####################### 16 ############################ helper functions #######################
16 17
17 ##### Genetic algorithm 18 ##### Genetic algorithm
19
20 # compute r2 by computing the classic formula
21 # compare the sum of square difference from target to prediciton
22 # to the sum of square difference from target to the mean of the target
23 r2 <- function(target, prediction) {
24 sst <- sum((target-mean(target))^2)
25 ssr <- sum((target-prediction)^2)
26 return(1-ssr/sst)
27 }
28
18 optimizeOneIndividual <- function(values, trueValue) { 29 optimizeOneIndividual <- function(values, trueValue) {
19 # change the value into a function 30 # change the value into a function
20 f <- function(w) {sum(values * w/sum(w))} 31 f <- function(w) {sum(values * w/sum(w))}
21 fitness <- function(x) {1/abs(trueValue-f(x))} 32 fitness <- function(x) {1/abs(trueValue-f(x))}
22 resp <- ga(type = "real-valued", fitness = fitness, min = rep(0, length(values)), max = rep(1, length(values)), 33 resp <- ga(type = "real-valued", fitness = fitness, min = rep(0, length(values)), max = rep(1, length(values)),
280 dt={ 291 dt={
281 aggregateDT(classifiers = classifPrediction, target = phenotype, 292 aggregateDT(classifiers = classifPrediction, target = phenotype,
282 out = out, prediction = prediction, model=model) 293 out = out, prediction = prediction, model=model)
283 }, 294 },
284 lasso={ 295 lasso={
285 aggregateLASSO(classifiers = classifPrediction, target = phenotype, 296 aggregateLASSO(classifiers = data.matrix(classifPrediction), target = phenotype,
286 out = out, prediction = prediction, model=model) 297 out = out, prediction = prediction, model=model)
287 }, 298 },
288 rf={ 299 rf={
289 aggregateRF(classifiers = classifPrediction, target = phenotype, 300 aggregateRF(classifiers = classifPrediction, target = phenotype,
290 out = out, prediction = prediction, model=model) 301 out = out, prediction = prediction, model=model)