【问题标题】:Text file classification in r from KNN to SVMr 中从 KNN 到 SVM 的文本文件分类
【发布时间】:2022-12-17 08:19:40
【问题描述】:

我的问题是我不明白如何使用 SVM,实际上我在 KNN 中有 20% 的错误所以我想改进这个统计,我处理我放入 VCorpus 中的 html 文件,清理,放入 DTM,找出最常用的词,然后我使用大约 1000 个文件来为 1 个文件(我有 7 个类)整理出好的类。下面的代码:

corpusEntrainement <- VCorpus(DirSource("training", recursive=T))

corpusCleanEntrainement <- nettoyage(corpusEntrainement)

motsFrequentsEntrainement <- findFreqTerms(corpusMatrice,lowfreq = 400, highfreq = 1200)

corpusDocReduitEntrainement <- DocumentTermMatrix(corpusCleanEntrainement,list(dictionary=motsFrequentsEntrainement))

dataReduitEntrainement <- as.matrix(corpusDocReduitEntrainement[, motsFrequentsEntrainement])

classesEntrainement<-c(rep(1,150),rep(2,150),rep(3,150),rep(4,150),rep(5,150),rep(6,150),rep(7,150))

matriceFinaleEntrainement <- cbind(dataReduitEntrainement,"classes"=classesEntrainement)

所以这就是我如何清理我的语料库并获得最终的 as.matrix,我如何从 svm 移动?我认为代码的其他部分会很简单,我只想移动 SVM 中的文档。

谢谢 !

【问题讨论】:

    标签: r svm knn text-classification corpus


    【解决方案1】:

    我假设您正在寻找如何训练 SVM 模型(问题中不是很清楚)。

    library(e1071)
    
    svmfit = svm(classes ~ ., data = matriceFinaleEntrainement)
    

    请注意,您可以在之前将类转换为一个因素:

    classesEntrainement<-as.factor(c(rep(1,150),rep(2,150),rep(3,150),rep(4,150),rep(5,150),rep(6,150),rep(7,150)))
    

    有关详细信息,请参见例如this tutorial

    【讨论】:

      猜你喜欢
      • 2013-05-17
      • 2015-07-13
      • 2015-01-09
      • 2011-03-21
      • 2023-04-08
      • 2014-01-31
      • 2020-04-29
      • 2018-02-08
      • 1970-01-01
      相关资源
      最近更新 更多