procureFit: Fits a classifier to a term document matrix

Description Usage Arguments Examples

View source: R/procureFit.R

Description

Wrapper for RTextTools classifier. Also performs sampling of test group if needed.

Usage

1
procureFit(procure, random = TRUE, text.var = "text", classifier = c("svm", "maxent", "glmnet"))

Arguments

procure
random
text.var
classifier

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (procure, random = TRUE, text.var = "text", classifier = c("svm", 
    "maxent", "glmnet")) 
{
    dtm <- formatProcureText(procure, text.var)
    if (random) {
        procure$fit <- 1
        procure$fit[sample(1:nrow(procure), 250)] <- 0
    }
    container <- create_container(dtm, procure$label, trainSize = which(procure$fit == 
        1), testSize = which(procure$fit == 0), virgin = TRUE)
    if (classifier[1] == "svm") {
        SVM <- train_model(container, "SVM")
        predictions <- classify_model(container, SVM)
    }
    if (classifier[1] == "maxent") {
        MAXENT <- train_model(container, "MAXENT")
        predictions <- classify_model(container, MAXENT)
    }
    if (classifier[1] == "glmnet") {
        GLMNET <- train_model(container, "GLMNET")
        predictions <- classify_model(container, GLMNET)
    }
    predictions$true.label <- procure$label[procure$fit == 0]
    predictions$text <- procure[procure$fit == 0, text.var]
    return(predictions)
  }

jon-mellon/procureClassify documentation built on May 19, 2019, 7:26 p.m.