tf–idfの例
出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2022/03/28 23:00 UTC 版)
2つの文書からのみ構成されるコーパスの単語カウント表(右に示す)を扱うと仮定する。 文書2語語のカウントthis 1 is 1 another 2 example 3 文書1語語のカウントthis 1 is 1 a 2 sample 1 語"this"のtf-idfは以下のように計算される。 出現頻度をそのままtfとして用いる場合、tfはそれぞれの文書の"this"の頻度と同じになる。標準的な文書長を調整するtfでは、各文書において単語"this"は1度現れるが、文書2はより多くの単語を含むため、相対頻度は小さくなる。 t f ( ″ t h i s ″ , d 1 ) = 1 5 = 0.2 {\displaystyle \mathrm {tf} ({\mathsf {''this''}},d_{1})={\frac {1}{5}}=0.2} t f ( ″ t h i s ″ , d 2 ) = 1 7 ≈ 0.14 {\displaystyle \mathrm {tf} ({\mathsf {''this''}},d_{2})={\frac {1}{7}}\approx 0.14} idfはコーパス毎の定数であり、"this"という単語を含む文書の比率から成り立っている。この事例では、2つの文書からなるコーパスを扱い、それらはすべて"this"という語を含んでいる。 i d f ( ″ t h i s ″ , D ) = log ( 2 2 ) = 0 {\displaystyle \mathrm {idf} ({\mathsf {''this''}},D)=\log \left({\frac {2}{2}}\right)=0} つまり、"this"という語のtf-idfはゼロである。これはこの単語がすべての文書に現れることから、その単語が有益でないでないこと示唆している。 t f i d f ( ″ t h i s ″ , d 1 , D ) = 0.2 × 0 = 0 {\displaystyle \mathrm {tfidf} ({\mathsf {''this''}},d_{1},D)=0.2\times 0=0} t f i d f ( ″ t h i s ″ , d 2 , D ) = 0.14 × 0 = 0 {\displaystyle \mathrm {tfidf} ({\mathsf {''this''}},d_{2},D)=0.14\times 0=0} "example"という語はより興味深く――3度現れるが、文書2にしか現れない。 t f ( ″ e x a m p l e ″ , d 1 ) = 0 5 = 0 {\displaystyle \mathrm {tf} ({\mathsf {''example''}},d_{1})={\frac {0}{5}}=0} t f ( ″ e x a m p l e ″ , d 2 ) = 3 7 ≈ 0.429 {\displaystyle \mathrm {tf} ({\mathsf {''example''}},d_{2})={\frac {3}{7}}\approx 0.429} i d f ( ″ e x a m p l e ″ , D ) = log ( 2 1 ) = 0.301 {\displaystyle \mathrm {idf} ({\mathsf {''example''}},D)=\log \left({\frac {2}{1}}\right)=0.301} 最終的には, t f i d f ( ″ e x a m p l e ″ , d 1 , D ) = t f ( ″ e x a m p l e ″ , d 1 ) × i d f ( ″ e x a m p l e ″ , D ) = 0 × 0.301 = 0 {\displaystyle \mathrm {tfidf} ({\mathsf {''example''}},d_{1},D)=\mathrm {tf} ({\mathsf {''example''}},d_{1})\times \mathrm {idf} ({\mathsf {''example''}},D)=0\times 0.301=0} t f i d f ( ″ e x a m p l e ″ , d 2 , D ) = t f ( ″ e x a m p l e ″ , d 2 ) × i d f ( ″ e x a m p l e ″ , D ) = 0.429 × 0.301 ≈ 0.129 {\displaystyle \mathrm {tfidf} ({\mathsf {''example''}},d_{2},D)=\mathrm {tf} ({\mathsf {''example''}},d_{2})\times \mathrm {idf} ({\mathsf {''example''}},D)=0.429\times 0.301\approx 0.129} (対数は常用対数を用いている。)
※この「tf–idfの例」の解説は、「tf-idf」の解説の一部です。
「tf–idfの例」を含む「tf-idf」の記事については、「tf-idf」の概要を参照ください。
- tf–idfの例のページへのリンク