小编Dr *_*mas的帖子

R tm包用于预测分析.如何对新文档进行分类?

这是关于文本挖掘程序的一般性问题.假设有一个文件语料库被归类为Spam/No_Spam.作为标准程序,可以预先处理数据,删除标点,停止单词等.将其转换为DocumentTermMatrix后,可以构建一些模型来预测垃圾邮件/ No_Spam.这是我的问题.现在我想使用为新文档建立的模型到达.为了检查单个文档,我必须构建DocumentTerm*Vector*?所以它可以用来预测垃圾邮件/ No_Spam.在tm的文档中,我发现使用例如tfidf权重将完整的语料库转换为矩阵.如何使用Corpus中的idf转换单个向量?我是否必须每次更改语料库并构建新的DocumentTermMatrix?我处理了我的语料库,将其转换为矩阵,然后将其拆分为训练和测试集.但是这里测试集与整个文档矩阵建立在同一行.我可以检查精度等,但不知道什么是新文本分类的最佳程序.

Ben,想象一下,我有一个预处理的DocumentTextMatrix,我将它转换为data.frame.

dtm <- DocumentTermMatrix(CorpusProc,control = list(weighting =function(x) weightTfIdf(x, normalize =FALSE),stopwords = TRUE, wordLengths=c(3, Inf), bounds = list(global = c(4,Inf))))

dtmDataFrame <- as.data.frame(inspect(dtm))
Run Code Online (Sandbox Code Playgroud)

添加了因子变量并构建了模型.

Corpus.svm<-svm(Risk_Category~.,data=dtmDataFrame)
Run Code Online (Sandbox Code Playgroud)

现在想象一下,我给你一个新文件d(以前不在你的语料库中),你想知道模型预测垃圾邮件/ No_Spam.你如何做到这一点?

好的,我们根据这里使用的代码创建一个示例.

examp1 <- "When discussing performance with colleagues, teaching, sending a bug report or searching for guidance on mailing lists and here on SO, a reproducible example is often asked and always helpful. What are your tips for creating an excellent example? How do you paste data structures from …
Run Code Online (Sandbox Code Playgroud)

r tm

15
推荐指数
1
解决办法
7286
查看次数

Caret Model 随机森林转化为 PMML 错误

我想使用 pmml 库导出 Caret 随机森林模型,以便我可以将它用于 Java 中的预测。这是我得到的错误的再现。

data(iris)
require(caret)
require(pmml)
rfGrid2 <- expand.grid(.mtry = c(1,2))
fitControl2 <- trainControl(
  method = "repeatedcv",
  number = NUMBER_OF_CV, 
  repeats = REPEATES)

model.Test <- train(Species ~ .,
  data = iris,
  method ="rf",
  trControl = fitControl2,
  ntree = NUMBER_OF_TREES,
  importance = TRUE,  
  tuneGrid = rfGrid2)

print(model.Test)
pmml(model.Test)

Error in UseMethod("pmml") : 
  no applicable method for 'pmml' applied to an object of class "c('train', 'train.formula')"
Run Code Online (Sandbox Code Playgroud)

我在谷歌上搜索了一段时间,发现实际上几乎没有关于导出到 PMML 的信息,通常 pmml 库在以下位置具有随机森林:

methods(pmml)
 [1] pmml.ada          pmml.coxph        pmml.cv.glmnet    pmml.glm          pmml.hclust …
Run Code Online (Sandbox Code Playgroud)

r random-forest pmml r-caret

3
推荐指数
1
解决办法
3516
查看次数

标签 统计

r ×2

pmml ×1

r-caret ×1

random-forest ×1

tm ×1