簡體   English   中英

在公告表中查找tf-idf值

[英]Finding tf-idf values in a announcement table

我想對公告進行分析。我必須計算'tf'和'idf'值。 但我認為這些價值觀並不現實。 代碼有問題嗎?

“阻止”線是公告。 第一個公告是'kurskayıttarihprogragirişçıkışsaat'

tf1 = (train['stemming'][0:1]).apply(lambda x: pd.value_counts(x.split(" "))).sum(axis = 0).reset_index()  #Term frequency
tf1.columns = ['words','tf']

for i,word in enumerate(tf1['words']):    #Inverse Document Frequency
  tf1.loc[i, 'idf'] = np.log(train.shape[0]/(len(train[train['stemming'].str.contains(word)])))

tf1['tf-idf'] = tf1['tf'] * tf1['idf'] # 3.4 Term Frequency – Inverse Document Frequency (TF-IDF)

對於第一個單詞(kurs),根據TF(t)=(術語t出現在文檔中的次數)/(文檔中的術語總數 ),tf值必須是1/7 但結果就是這樣

問題在於,當你計算tf時,你只計算每個單詞的出現次數。 您需要將該值除以不同單詞的總數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM