Created
July 9, 2012 21:01
-
-
Save ibayer/3078871 to your computer and use it in GitHub Desktop.
Some lines to get timings for the glmnet fortran implementation via the R interface. This should later be used to compare it against the scikit-learn glmnet implementation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rpy2.robjects as robjects | |
from rpy2.robjects import * | |
r_script_path = r"/home/mane/workspace/benchmark" | |
# Set wd in R | |
robjects.r.setwd(r_script_path) | |
# Load the R code | |
r.source(os.path.join(r_script_path, "time_glmnet_fit.R")) | |
leukemia_time = robjects.r.timeLogisticRegression("Leukemia",0.8, 100) | |
#internetAd_time = robjects.r.timeLogisticRegression("InternetAd",0.8, 10) | |
#NewsGroup_time = robjects.r.timeLogisticRegression("NewsGroup",0.8, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(glmnet) | |
require(Matrix) | |
require(lattice) | |
timeLogisticRegression<- function(data_name="Leukemia", alpha=0.5, repetitions=1){ | |
file_name = paste(data_name, "RData", sep=".") | |
load(file.path(getwd(),file_name)) | |
print(paste("Logistic Regression",file_name, " alpha=", alpha)) | |
X = get(data_name)$x | |
y = get(data_name)$y | |
all_timings = NA | |
for (i in 1:repetitions){ | |
my_timer = system.time( {fit = glmnet(x=X,y=y, family="binomial")} ) | |
print(my_timer) | |
all_timings = rbind(all_timings, as.numeric(my_timer)) | |
} | |
#averageTime = colMedians(all_timings, na.rm = TRUE) | |
medianTime = apply(as.array(all_timings), 2, median, na.rm=TRUE) | |
print(medianTime) | |
return(medianTime) | |
} | |
#ergebniss = timeLogisticRegression(data_name="Leukemia", alpha=0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment