Trying to get tf-idf weighting working in R

前端 未结 1 1488
终归单人心
终归单人心 2021-01-31 00:07

I am trying to do some very basic text analysis with the tm package and get some tf-idf scores; I\'m running OS X (though I\'ve tried this on Debian Squeeze with the same result

相关标签:
1条回答
  • 2021-01-31 00:54

    If you look at the DocumentTermMatrix help page, an at the example, you will see that the control argument is specified this way :

    data(crude)
    dtm <- DocumentTermMatrix(crude,
               control = list(weighting = function(x) weightTfIdf(x, normalize = FALSE),
                              stopwords = TRUE))
    

    So, the weighting is specified with the list element named weighting, not weight. And you can specify this weighting by passing a function name or a custom function, as in the example. But the following works too :

    data(crude)
    dtm <- DocumentTermMatrix(crude, control = list(weighting = weightTfIdf))
    
    0 讨论(0)
提交回复
热议问题