(文本表示及挖掘)Representing and Mining Text
主要内容:1. Text data 2. Bag of words 3. N-gram sequence 4. Text mining 案例
(一) text data文本数据(Text data )的特点
文本数据的缺陷(Text data’s problem —dirty data ):
Dirty data 需要经过预处理(preprocess)才能作为下一步模型的输入(input) A collection of documents is called 'corpus'
(二)bag of words词汇频率表(term frequency)–记录文档中,每个词汇的出现次数 In mathematics a bag is a multiset,where members are allowed to appear more than once. (discarding word order) Term frequency 有两点需要我们注意:
Term frequency 描述了词汇在单个文档中的频繁程度,我们常常还要关心这个词汇在我们挖掘的文档集中的分布情况。于是我们便引入了逆文档频率(inverse document frequency)—IDF的概念,若某些词汇集中出现在少数几个文档中,那么这些词汇对这几个文档的重要性不言而喻。
IDF 图像效果如下 看以看出,当某个词汇在文档集中出现较为稀缺时,IDF 值是显著的,并且随着数量增加显著性迅速下降,大多数stopword 的IDF 为 1 将 TF (term frequency )和IDF(inverse document frequency)和并到一起,得到TFIDF 值 依据TFIDF 我们便可以将文档转变为特征向量 , 随后我们往往需要进行特征选择(可以使用频率的上下阈值,或者之前提到过的information gain),之后我们便能够将特征向量用于各种模型之中。 IDF 与 熵(Entropy )的联系 定义
于是有
We can express entropy as the expected value of IDF(t) and IDF(not_t) based on the probability of its occurrence in the corpus. 可以看出第三图图与熵的图是一致的
(三)N-gram Sequence看到N-gram Sequence 方法的时候突然想起了之前写过的一段代码 用R语言写的提取英语文章中较为常见的短语的小程序 (当初觉得别人整理的常见词组没有针对性,于是就写了这个,将各种文章导入,一份属于自己的常用短语表就出来了,【初学R语言时现学现用的小代码,太过简单,勿喷】) [Words 是将文档split 后得到的 word list ] n=2
two_word<-character(0)
for (i in 1:(length(words)-n+1))
{
two_word[i]<-paste(words[i],words[i+1])
}
s2w<-sort(table(two_word),d=T)
s2w<-s2w[s2w>2]
n=3
three_word<-character(0)
for (i in 1:(length(words)-n+1))
{
three_word[i]<-paste(words[i],words[i+1],words[i+2])
}
s3w<-sort(table(three_word),d=T)
s3w<-s3w[s3w>1]
N-gram sequence 的例子:
N-gram Sequence 方法 ,简单的讲就是 将邻近的几个词作为一个整体加入变量集合 Topic models 在词汇与文档直接对应的模型中加入 topic 层,可以挖掘出更多的隐含信息(atent information) 【个人觉得 topic layer 有点 neural network 中 hiden layer 的意味】 General methods for creating topic models include matrix factorization methods,such as Latent Semantic Indexing and Probabilistic Topic Models,such as Latent Dirichlet Allocation.
(四)Text mining 案例Mining News Stories to Predict Stock Price Movement (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |