tfidf处理代码_tfidf.txt
function [count,tf,idf,weight]=tfidf(docs,term)
%docs--input documents,cell型
%term-- keywords也就是特征詞提取,cell型
%output:count--存放各個關鍵詞出現的頻率在整個文檔中
% wordnum--存放文檔總的詞匯數
%測試用例
%*****************************************************************
%clear all
%doc1='www washingtonpost com wp-adv mediacenter images wpni skin2 jpg';
%doc2='www washingtonpost com wp-adv mediacenter images about us welcome gif';
%doc3='media washingtonpost com wp-adv mediacenter images wpni mediakit hdr top gif';
%doc4='www washingtonpost com wp-adv mediacenter html research demographics html';
%docs={
doc1,doc2,doc3,doc4
};
%term={
'washingtonpost','mediacenter','images'
};
%%*************************************************************************
Ldocs=length(docs);
Lterm=length(term);
tf=zeros(Ldocs,Lterm);
idf=zeros(1,Lterm);
count=zeros(Ldocs,Lterm);
wordnum=[];
weight=zeros(Ldocs,Lterm);
p=' ';
i=1;
for i=1:Ldocs
doc=cell2mat(docs(i));
tabnum=find(doc==p);
Ltab=length(tabnum);
wordnum(i)=Ltab+1;
k=1;
for j=1:Ltab
word=doc(k:tabnum(j)-1);%會少輸出最后一個詞
Lw=length(word);
fword=doc((tabnum(Ltab)+1):length(doc));%最后一個詞
Lfw=length(fword);
for jj=1:Lterm
aterm=cell2mat(term(jj));
Lat=length(aterm);
if Lat==Lw||Lat==Lfw
if strcmpi(word,aterm);
count(i,jj)=count(i,jj)+1;
if j
...
...
(完整源碼請下載查看)
...
展開> <收縮
總結
以上是生活随笔為你收集整理的tfidf处理代码_tfidf.txt的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shell字段拼接日期_shell 脚本
- 下一篇: js 转化为实体符_js转html实体的