私は今日、tf
および/またはtfidf
がRで壊れているようだと認識しました。以下の私の例を見てください。マニュアルのデータ、すなわちcrude
を使用しています。私は、結果として得られる頻出用語リストが等しくないことを期待しています。しかし、彼らは平等です。これは決して起こるべきではないでしょうか?R:weightTfとweightTfIdfは同じ頻出語リストを生成しますか?
data("crude")
dtm <- DocumentTermMatrix(crude, control = list(weighting = function(x) weightTf, stopwords = FALSE))
frequentTerms1 <- data.frame(findFreqTerms(dtm)[1:1000])
#View(frequentTerms1)
dtm <- DocumentTermMatrix(crude, control = list(weighting = function(x) weightTfIdf(x, normalize = FALSE), stopwords = FALSE))
frequentTerms2 <- data.frame(findFreqTerms(dtm)[1:1000])
#View(frequentTerms2)
frequentTerms1 == frequentTerms2
サンプルコードに間違いがありますか?私は基礎となるtm
パッケージのマニュアルからそれをコピーし、比較としてtf
のケースを追加しました。
ありがとうございました。
敬具 トルステン
編集#1: さて、答えてくれてありがとうlukeA
。それは大いに役立ちます。したがって、頻繁な用語を取得する「正しい」方法は次のとおりです。
data("crude")
dtm <- DocumentTermMatrix(crude, control = list(weighting = function(x) weightTf, stopwords = FALSE))
frequentTerms1 <- as.data.frame(sort(colSums(as.matrix(dtm)), decreasing = TRUE))
#View(frequentTerms1)
dtm <- DocumentTermMatrix(crude, control = list(weighting = function(x) weightTfIdf(x, normalize = FALSE), stopwords = FALSE))
frequentTerms2 <- as.data.frame(sort(colSums(as.matrix(dtm)), decreasing = TRUE))
#View(frequentTerms2)
frequentTerms1 == frequentTerms2
ここでは、両方のリストが異なっています。