Learn R Programming

RTextTools (version 1.3.2)

classify_model: makes predictions from a train_model() object.

Description

Uses a trained model from the train_model function to classify new data.

Usage

classify_model(corpus, model, s=0.01, ...)

Arguments

corpus
Class of type matrix_container-class generated by the create_corpus function.
model
Slot for trained SVM, SLDA, boosting, bagging, RandomForests, glmnet, decision tree, neural network, or maximum entropy model generated by train_model.
s
Penalty parameter lambda for glmnet classification.
...
Additional parameters to be passed into the predict function of any algorithm.

Value

  • Returns a data.frame of predicted codes and probabilities for the specified algorithm.

Details

Only one model may be passed in at a time for classification. See train_models and classify_models to train and classify using multiple algorithms.

Examples

Run this code
library(RTextTools)
data <- read_data(system.file("data/NYTimes.csv.gz",package="RTextTools"),type="csv")
data <- data[sample(1:3100,size=100,replace=FALSE),]
matrix <- create_matrix(cbind(data$Title,data$Subject), language="english", 
removeNumbers=TRUE, stemWords=FALSE, weighting=weightTfIdf)
corpus <- create_corpus(matrix,data$Topic.Code,trainSize=1:75, testSize=76:100, 
virgin=FALSE)
maxent_model <- train_model(corpus,"MAXENT")
svm_model <- train_model(corpus,"SVM")
maxent_results <- classify_model(corpus,maxent_model)
svm_results <- classify_model(corpus,svm_model)

Run the code above in your browser using DataLab