I have R code for importing text data into R, remove stop words, stem words and then create a matrix. Below is the code for
- Using the create container function to split the matrix into training and test data sets.
- Use train_models function to create a model based on SVM.
- Execute the model on test.
Then I save the model.
library("RTextTools") container = create_container(matrix, as.numeric(as.factor(data[, 2])), trainSize = 1:2800,testSize = 2801:3162, virgin = FALSE) models = train_models(container,"SVM", kernel = "linear",cost =1) results = classify_models(container, models) save(models, file = "my_model1.rda")
I am not able to use the saved model for prediction on new data(matrix_new) using predict function.
p <- predict(models,matrix_new) #Error in predict.svm(X[[1L]], ...) : test data does not match model !
My question is: Is it feasible to use saved models on new data to predict sentiment ? From the error it looks like there is mismatch between the words that were used while creating the model and the new data. Please clarify if my understanding is correct.