Skip to content

Commit

Permalink
stricter NAMESPACE, ggplot2 now imported too
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Aug 22, 2016
1 parent 1696bec commit 30270a9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
2016-08-22 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (License): Use dual license with GPL (>= 2) for my code,
and BSD 3-clause for existing code

* NAMESPACE: All importing now via importFrom()

* demo/vw_example_4.R: Add library(pROC), add a legend to ROC plot
* demo/00Index: Add vw_example4

* R/plot.R (plotDensity): add utils::globalVariables() for R CMD check

2016-08-21 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Suggests): Added caret (confusion matrix), ggplot2
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Description: A basic R interface to the Vowpal Wabbit fast on-line learner
is provided.
SystemRequirements: The Vowpal Wabbit binary 'vw' has to be in the path.
License: GPL (>= 2) | BSD_3_clause + file LICENSE
Imports: pROC, data.table
Suggests: yaml, caret, ggplot2, earth
Imports: pROC, data.table, ggplot2
Suggests: yaml, caret, earth
RoxygenNote: 5.0.1
9 changes: 5 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

export(dt2vw)
export(vw)
export("vw",
"dt2vw")

import("data.table")
import("pROC")
importFrom("utils", "write.table")
importFrom("data.table", "data.table", "setDT", "setnames", "fread", "set")
importFrom("pROC", "roc", "plot.roc")
importFrom("ggplot2", "ggplot", "aes", "geom_density")
6 changes: 4 additions & 2 deletions R/dt2vw.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ dt2vw <- function(data, fileName, namespaces = NULL, target, weight = NULL, tag
}

##appending the name of the variable to its value for each categorical variable
sapply(Index, FUN = function(x){sapply(names(x), FUN = function(y){if(x[[y]] == F){
set(data, i=NULL, y, paste0(y,"_",data[[y]]))
sapply(Index,
FUN = function(x){sapply(names(x),
FUN = function(y){if(x[[y]] == F){
set(data, i=NULL, y, paste0(y,"_",data[[y]]))
}})})

## FIRST PART OF THE VW DATA FORMAT: target, weight, tag
Expand Down
3 changes: 3 additions & 0 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ plotDensity <- function(x) {
p <- ggplot(data=x) + geom_density(aes(x=predicted,linetype=actual,color=actual))
p
}

## to silence R CMD check --as-cran
utils::globalVariables(c("predicted", "actual"))
17 changes: 10 additions & 7 deletions R/vw.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ vw <- function(training_data, validation_data, model='mdl.vw',
cmd <- sprintf('%s -d %s --loss_function %s -f %s', getVW(), training_data, loss, model)
cmd <- sprintf('%s --learning_rate=%s --passes %s', cmd, learning_rate, passes)
if (use_cache) cmd <- sprintf("%s -c", cmd)

if (!is.null(l1)) cmd <- sprintf('%s --l1 %s', cmd, l1)
if (!is.null(l2)) cmd <- sprintf('%s --l2 %s', cmd, l2)

Expand All @@ -141,7 +141,9 @@ vw <- function(training_data, validation_data, model='mdl.vw',
del_prob <- FALSE

validation_data <- path_data_args[[2]]
predict <- sprintf('%s -t -i %s -p %s %s -d %s', getVW(), model, out_probs, link_function, validation_data)
predict <- sprintf('%s -t -i %s -p %s %s -d %s',
getVW(), model, out_probs,
link_function, validation_data)
system(predict)

if (do_evaluation) {
Expand All @@ -159,13 +161,14 @@ vw <- function(training_data, validation_data, model='mdl.vw',

if (use_perf) {
## compute auc using perf
eval_model <- sprintf("%s -ROC -files %s %s | cut -c8-14", getPerf(), validation_labels, out_probs)
eval_model <- sprintf("%s -ROC -files %s %s | cut -c8-14",
getPerf(), validation_labels, out_probs)
auc <- system(eval_model, intern = TRUE)
} else {
auc <- roc_auc(out_probs, validation_labels, plot_roc, cmd)
}

if (verbose)
if (verbose)
cat('\nModel Parameters\n', cmd, "\n\nAUC: ", auc, "\n")
}

Expand All @@ -176,21 +179,21 @@ vw <- function(training_data, validation_data, model='mdl.vw',
for (i in 1:2) {
if ("data.frame" %in% class(data_args[[i]])) {
file.remove(path_data_args[[i]])
cachefile <- paste0(path_data_args[[i]], ".cache")
cachefile <- paste0(path_data_args[[i]], ".cache")
if (file.exists(cachefile)) unlink(cachefile)
}
}
if (del_prob) file.remove(out_probs)
if (exists("del_val") && del_val) file.remove(validation_labels)
if (file.exists("mdl.vw")) file.remove("mdl.vw")
}

##return(list(auc=auc, preds=probs))
return(list(auc=auc,
data=setDT(data.frame(predicted=probs)), #, actual=as.factor(validation_data[, factor]))),
workingdir=getwd(),
cmd=cmd))

}

# Reads labels file (from the validation dataset)
Expand Down

0 comments on commit 30270a9

Please sign in to comment.