classify_model: makes predictions from a train_model() object.

Description Usage Arguments Details Value Author(s) Examples

View source: R/classify_model.R

Description

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

Usage

1
classify_model(container, model, s=0.01, ...)

Arguments

container

Class of type matrix_container-class generated by the create_container 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.

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.

Value

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

Author(s)

Loren Collingwood <loren.collingwood@gmail.com>, Timothy P. Jurka <tpjurka@ucdavis.edu>

Examples

1
2
3
4
5
6
7
8
9
library(RTextTools)
data(NYTimes)
data <- NYTimes[sample(1:3100,size=100,replace=FALSE),]
matrix <- create_matrix(cbind(data["Title"],data["Subject"]), language="english", 
removeNumbers=TRUE, stemWords=FALSE, weighting=tm::weightTfIdf)
container <- create_container(matrix,data$Topic.Code,trainSize=1:75, testSize=76:100, 
virgin=FALSE)
svm_model <- train_model(container,"SVM")
svm_results <- classify_model(container,svm_model)

Example output

Loading required package: SparseM

Attaching package: 'SparseM'

The following object is masked from 'package:base':

    backsolve

RTextTools documentation built on April 26, 2020, 9:05 a.m.