Skip to content

Commit

Permalink
package refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
orionw committed Jan 8, 2019
1 parent 1a48ac7 commit 70aacee
Show file tree
Hide file tree
Showing 31 changed files with 559 additions and 549 deletions.
Binary file removed .RData
Binary file not shown.
984 changes: 492 additions & 492 deletions .Rhistory

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: BestModel
Title: A package to run and compare standard machine learning models with easy visualization.
Title: A package to run and compare standard machine learning models with easy visualization
Version: 0.0.1.0000
Authors@R: person("Orion", "Weller", email = "first.last@example.com", role = c("aut", "cre"))
Description: This package allows for the creation of ModelComparison objects. These objects provide an easy way to visualize the metrics between the different models. You can supply the models yourself, or create them in the function. It also allows for easy Ensembling as well as other helper functionality.
Expand All @@ -8,7 +8,7 @@ License: What license is it under?
Encoding: UTF-8
LazyData: true
Suggests: testthat
depends:
Imports:
caret,
pROC,
ggplot2,
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,3 @@ export(PrepareIris)
export(PrepareNumericTitanic)
export(StripPredictions)
export(prepData)
exportPattern("^[[:alpha:]]+")
importFrom(Rcpp,evalCpp)
useDynLib(BestModel)
17 changes: 10 additions & 7 deletions R/Ensembling.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#'
#' @examples
#' # This function is used by predict.Ensemble. It's usage is as follows:
#' preds[[i]] <- StripPredictions(predict(model, newdata = newdata, type="prob"))
#' # preds[[i]] <- StripPredictions(predict(model, newdata = newdata, type="prob"))
#'
#' @keywords internal
#' @export
Expand All @@ -29,6 +29,8 @@ StripPredictions <- function(pred) {
#' Gives a summary of the models used in the Ensemble object
#'
#' @param object The Ensemble object to be summarized.
#' @param ... Other arguments, if needed

#'
#' @return NULL, only prints out
#'
Expand Down Expand Up @@ -64,6 +66,7 @@ summary.Ensemble <- function(object, ...) {
#' @param voting.type The way that the Ensemble will vote - default is what was given
#' at creation of the object but it can be overriden by passing in "averageVote", "majorityVote"
#' or "majorityWeight."
#' @param ... Other arguments, if needed
#'
#' @return a list of predictions, voted on by all the models into one final prediction.
#'
Expand Down Expand Up @@ -123,7 +126,7 @@ predict.Ensemble <- function(object, newdata, voting.type="default", ...) {
#'
#' @examples
#' # This function is used by predict.Ensemble. It's usage is as follows:
#' MajorityVote(preds)
#' # MajorityVote(preds)
#'
#' @keywords internal
#' @export
Expand Down Expand Up @@ -161,7 +164,7 @@ MajorityVote <- function(list.of.predictions){
#'
#' @examples
#' # This function is used by predict.Ensemble. It's usage is as follows:
#' MajorityWeight(preds, Ensemble$weights)
#' # MajorityWeight(preds, Ensemble$weights)
#'
#' @keywords internal
#' @export
Expand Down Expand Up @@ -206,7 +209,7 @@ MajorityWeight <- function(list.of.predictions, weight.list){
#'
#' @examples
#' # This function is used by predict.Ensemble. It's usage is as follows:
#' AverageVote(preds)
#' # AverageVote(preds)
#'
#' @keywords internal
#' @export
Expand Down Expand Up @@ -249,7 +252,7 @@ AverageVote <- function(list.of.predictions){
#'
#' @examples
#' # This function is used by GetWeightsFromTestSet It's usage is as follows:
#' test.set <- GetFactorEqual(test.set)
#' # test.set <- GetFactorEqual(test.set)
#'
#' @keywords internal
#' @export
Expand Down Expand Up @@ -281,7 +284,7 @@ GetFactorEqual <- function(pred) {
#'
#' @examples
#' # This function is used by Ensemble. It's usage is as follows:
#' return(GetWeightsFromTestingSet(ensemble, weights, test.set, train.type))
#' # return(GetWeightsFromTestingSet(ensemble, weights, test.set, train.type))
#'
#' @keywords internal
#' @export
Expand Down Expand Up @@ -327,7 +330,7 @@ GetWeightsFromTestingSet <- function(ensemble, df.train, test.set, train.type) {
#'
#' @examples
#' # This function is used by Ensemble. It's usage is as follows:
#' ensemble$weight.list = GetModelWeights(ensemble, weights, test.set, train.type)
#' # ensemble$weight.list = GetModelWeights(ensemble, weights, test.set, train.type)
#'
#' @keywords internal
#' @export
Expand Down
20 changes: 11 additions & 9 deletions R/ModelGeneration.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#'
#' @examples
#' # This function is used by GetModelComparison and ModelComparison to create the
#' ModelComparison object. The follow code is what is used by ModelComparison:
#' CreateModelComparison(model.list, multi.class, F, names(model.list))
#' # ModelComparison object. The follow code is what is used by ModelComparison:
#' # CreateModelComparison(model.list, multi.class, F, names(model.list))
#'
#' @keywords internal
#' @export
Expand Down Expand Up @@ -46,7 +46,7 @@ CreateModelComparison <- function(model.list, multi.class, force.prepped, diff.n
#'
#' @examples
#' # see the CreateModelComparison function for it's use as follows:
#' comparison$accuracy.list <- GetAccuracy(comparison)
#' # comparison$accuracy.list <- GetAccuracy(comparison)
#'
#' @keywords internal
#' @export
Expand Down Expand Up @@ -79,6 +79,7 @@ GetAccuracy <- function(object) {
#'
#' @param extra a boolean value on whether accuracy values will be returned, if present.
#' By default this value is TRUE
#' @param ... Other arguments, if needed
#'
#' @return NULL, only prints out
#'
Expand Down Expand Up @@ -121,6 +122,7 @@ summary.ModelComparison <- function(object, extra=TRUE, ...) {
#'
#' @param object The ModelComparison object whose models will be predicted on.
#' @param newdata A dataframe of new data that the models will use to predict.
#' @param ... Other arguments, if needed
#'
#' @return A list of dataframes, where each dataframe is the predictions from the respective
#' model for the two output classes.
Expand Down Expand Up @@ -179,7 +181,7 @@ predict.ModelComparison <- function(object, newdata, ...) {
#'
#' @examples
#' # This function is used by predict.ModelComparison. It's usage is as follows:
#' pred.basic[[i]] = GetPredType(model, newdata)
#' # pred.basic[[i]] = GetPredType(model, newdata)
#'
#' @keywords internal
#' @export
Expand Down Expand Up @@ -213,7 +215,7 @@ GetPredType <- function(model, newdata) {
#'
#' @examples
#' # This function is used by GetModelComparison. It's usage is as follows:
#' training.set = prepData(training.set)
#' # training.set = prepData(training.set)
#'
#' @keywords internal
#' @export
Expand Down Expand Up @@ -250,8 +252,8 @@ prepData <- function(training.set) {
#'
#' @examples
#' # This function is used by GetModelComparison. It's usage is as follows:
#' modelVec = BuildModels(training.data, training.classes, trctrl,
#' tune.length, multi.class, build.flags, force.prepared = forced.prepared)
#' # modelVec = BuildModels(training.data, training.classes, trctrl,
#' # tune.length, multi.class, build.flags, force.prepared = forced.prepared)
#'
#' @keywords internal
#' @export
Expand Down Expand Up @@ -360,7 +362,7 @@ BuildModels <- function(training.data, training.classes, trctrl,
#'
#' @examples
#' # This function is used by GetModelComparison. It's usage is as follows:
#' build.flags <- GetBuildFlags(model.list)
#' # build.flags <- GetBuildFlags(model.list)
#'
#' @keywords internal
#' @export
Expand Down Expand Up @@ -443,7 +445,7 @@ GetBuildFlags <- function(model.list) {
#'
#' @examples
#' # This function is used by GetModelComparison. It's usage is as follows:
#' training.info <- GetTrainingInfo(training.set, training.classes.input, validation, trctrl)
#' # training.info <- GetTrainingInfo(training.set, training.classes.input, validation, trctrl)
#'
#' @keywords internal
#' @export
Expand Down
18 changes: 10 additions & 8 deletions R/Visualization.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#' @param format.data Whether the data should be transformed into one-hot encoding if it needs
#' to be. The default is TRUE. If you would like to predict on unchanged data that is not
#' in the right format, set this to false at your own risk.
#' @param ... Other arguments for plotting

#' @export
#' @examples
#' # prepare the dataset
Expand Down Expand Up @@ -96,7 +98,7 @@ plot.ModelComparison <- function(object, labels, training.data = "none", predict
#'
#' @examples
#' # This function is used by plot.ModelComparison. It's usage is as follows:
#' CreateROCPlot(object, pred.basic, labels)
#' # CreateROCPlot(object, pred.basic, labels)
#' @keywords internal
#' @export
CreateROCPlot <- function(object, pred.basic, labels) {
Expand Down Expand Up @@ -141,9 +143,9 @@ CreateROCPlot <- function(object, pred.basic, labels) {
#'
#' @examples
#' # This function is used by plot.ModelComparison. It's usage is as follows:
#' CreateCombinedPlot(object, pred.basic, labels)
#' # or given specific metrics for Accuracy and AUC:
#' CreateCombinedPlot(object, pred.basic, labels, c("Accuracy", "AUC"))
#' # CreateCombinedPlot(object, pred.basic, labels)
#' # or given specific metrics for Accuracy and AUC:
#' # CreateCombinedPlot(object, pred.basic, labels, c("Accuracy", "AUC"))
#' @keywords internal
#' @export
CreateCombinedPlot <- function(object, pred.basic, labels,
Expand All @@ -166,9 +168,9 @@ CreateCombinedPlot <- function(object, pred.basic, labels,
dataScaled <- predict(preProcValues, ind.pred)
# remove the matrix form
ind.pred <- c(dataScaled)
value.list[[i]] = pROC:::auc(labels, ind.pred)[[1]]
value.list[[i]] = pROC::auc(labels, ind.pred)[[1]]
} else {
value.list[[i]] = pROC:::auc(labels, ind.pred[, 1])[[1]]
value.list[[i]] = pROC::auc(labels, ind.pred[, 1])[[1]]
}
} else {
if (names(pred.basic)[[i]] == "svm.formula") {
Expand Down Expand Up @@ -231,8 +233,8 @@ CreateCombinedPlot <- function(object, pred.basic, labels,
#' @return The predictions, with only two factors.
#'
#' @examples
#' As used in GetCombinedPlot:
#' pred <- GetSVMScale(pred)
#' # As used in GetCombinedPlot:
#' # pred <- GetSVMScale(pred)
#'
#' @keywords internal
#' @export
Expand Down
4 changes: 0 additions & 4 deletions R/forRoxygen2.R

This file was deleted.

2 changes: 1 addition & 1 deletion man/AverageVote.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/BuildModels.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/CreateCombinedPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/CreateModelComparison.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/CreateROCPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/GetAccuracy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/GetBuildFlags.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/GetFactorEqual.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/GetModelWeights.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/GetPredType.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/GetSVMScale.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/GetTrainingInfo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/GetWeightsFromTestingSet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/MajorityVote.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/MajorityWeight.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/StripPredictions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 70aacee

Please sign in to comment.