算tfidf矩阵的时候能不能用到多线程矩阵乘法

多线程运算矩阵运算感悟_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
多线程运算矩阵运算感悟
上传于|0|0|暂无简介
阅读已结束,如果下载本文需要使用2下载券
想免费下载本文?
定制HR最喜欢的简历
你可能喜欢利用sklearn进行tfidf计算
时间: 21:07:54
&&&& 阅读:560
&&&& 评论:
&&&& 收藏:0
标签:转自:http://blog.csdn.net/liuxuejiang158blog/article/details/?utm_source=tuicool
  在文本处理中,TF-IDF可以说是一个简单粗暴的东西。它可以用作特征抽取,关键词筛选等。
  以网页搜索&核能的应用&为例,关键字分成&核能&、&的&、&应用&。根据直觉,我们知道,包含这三个词较多的网页比包含它们较少的网页相关性强。但是仅仅这样,就会有漏洞,那就是文本长的比文本短的关键词数量要多,所以相关性会偏向长文本的网页。所以我们需要归一化,即用比例代替数量。用关键词数除以总的词数,得到我们的&单文本词频()&最后的为各个关键词的相加。这样还不够,还是有漏洞。像&的&、&和&等这样的常用字,对衡量相关性没什么作用,但是几乎所有的网页都含有这样的字,所以我们要忽略它们。于是就有了IDF(
  原理非常简单,结合单词的词频和包含该单词的文档数,统计一下,计算TF和IDF的乘积即可。但是自己的写的代码,在运算速度上,一般不尽人意,在自己写了一段代码之后,为了方便检验结果是否正确、效率如何,在网上寻找了一些开源代码。这里用到了sklearn里面的TF-IDF。主要用到了两个函数:CountVectorizer()和TfidfTransformer()。CountVectorizer是通过fit_transform函数将文本中的词语转换为词频矩阵,矩阵元素weight[i][j] 表示j词在第i个文本下的词频,即各个词语出现的次数;通过get_feature_names()可看到所有文本的关键字,通过toarray()可看到词频矩阵的结果。TfidfTransformer也有个fit_transform函数,它的作用是计算tf-idf值。
#!/usr/bin/python
# -*- coding: utf-8 -*-import string
import sys
reload(sys)
sys.setdefaultencoding(‘utf8‘)
from sklearn import feature_extraction
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.feature_extraction.text import CountVectorizer
if __name__ == "__main__":
corpus = []
tfidfdict = {}
f_res = open(‘sk_tfidf.txt‘, ‘w‘)
for line in open(‘seg.txt‘, ‘r‘).readlines():
#读取一行语料作为一个文档
corpus.append(line.strip())
vectorizer=CountVectorizer()#该类会将文本中的词语转换为词频矩阵,矩阵元素a[i][j] 表示j词在i类文本下的词频
transformer=TfidfTransformer()#该类会统计每个词语的tf-idf权值
tfidf=transformer.fit_transform(vectorizer.fit_transform(corpus))#第一个fit_transform是计算tf-idf,第二个fit_transform是将文本转为词频矩阵
word=vectorizer.get_feature_names()#获取词袋模型中的所有词语
weight=tfidf.toarray()#将tf-idf矩阵抽取出来,元素a[i][j]表示j词在i类文本中的tf-idf权重
for i in range(len(weight)):#打印每类文本的tf-idf词语权重,第一个for遍历所有文本,第二个for便利某一类文本下的词语权重
for j in range(len(word)):
getword = word[j]
getvalue = weight[i][j]
if getvalue != 0:
#去掉值为0的项
if tfidfdict.has_key(getword):
#更新全局TFIDF值
tfidfdict[getword] += string.atof(getvalue)
tfidfdict.update({getword:getvalue})
sorted_tfidf = sorted(tfidfdict.iteritems(),
key=lambda d:d[1],
reverse = True )
for i in sorted_tfidf:
f_res.write(i[0] + ‘\t‘ + str(i[1]) + ‘\n‘)
  标签:
&&国之画&&&& &&&&chrome插件
版权所有 京ICP备号-2
迷上了代码!当前位置: >>
NLP 使用TfidfVectorizer构建文本预处理类(8)
作者:& &发布时间: 16:54:24& &浏览次数:5110
类封装:TextPreprocess.py
# -*- coding: utf-8 -*-
import sys&&
import jieba&
#引入Bunch类
from sklearn.datasets.base import Bunch
#引入持久化类
import pickle
from sklearn import feature_extraction&&
from sklearn.feature_extraction.text import TfidfTransformer&&
from sklearn.feature_extraction.text import TfidfVectorizer&
##############################################################
# 分类语料预处理的类
# 语料目录结构:
#& &|-catergory_A
#& &&&|-01.txt
#& &&&|-02.txt& &
#& &|-catergory_B
#& &|-catergory_C
##############################################################
# 配置utf-8输出环境
reload(sys)
sys.setdefaultencoding('utf-8')
#文本预处理类
class TextPreprocess:
& && &&&data_set = Bunch(target_name=[],label=[],filenames=[],contents=[])
& && &&&# 定义词袋对象:data_set
& && &&&# Bunch类提供一种key,value的对象形式
& && &&&# target_name:所有分类集名称列表
& && &&&# label:每个文件的分类标签列表
& && &&&# filenames:文件名称
& && &&&# contents:文件内容
& && &&&wordbag = Bunch(target_name=[],label=[],filenames=[],tdm=[],vocabulary={})
& && &&&def __int__(self):&&#构造方法
& && && && && && && && &self.corpus_path = &&& & #原始语料路径
& && && && && && && && &self.pos_path = &&& && & #预处理后语料路径
& && && && && && && && &self.segment_path = &&& &#分词后语料路径
& && && && && && && && &self.wordbag_path = &&& &#词袋模型路径
& && && && && && && && &self.stopword_path = &&&&#停止词路径
& && && && && && && && &self.trainset_name = &&& && &#训练集文件名
& && && && && && && && &self.wordbag_name = &&& && & #词包文件名
& && && && && && && && &
& && && && && && && && &
& && &&&# 对输入语料进行基本预处理,删除语料的换行符,并持久化。
& && &&&# 处理后在pos_path下建立与corpus_path相同的子目录和文件结构
& && &&&def preprocess(self):
& && && && && & if(self.corpus_path==&& or self.pos_path==&&):
& && && && && && && && &print &corpus_path或pos_path不能为空&
& && && && && && && && &return&
& && && && && & dir_list = os.listdir(self.corpus_path) # 获取每个目录下所有的文件
& && && && && & for mydir in dir_list:
& && && && && && && && &class_path = self.corpus_path+mydir+&/& # 拼出分类子目录的路径
& && && && && && && && &file_list = os.listdir(class_path)&&# 获取class_path下的所有文件
& && && && && && && && &for file_path in file_list:& &# 遍历所有文件
& && && && && && && && && && &&&file_name = class_path + file_path&&# 拼出文件名全路径
& && && && && && && && && && &&&file_read = open(file_name, 'rb')& &# 打开一个文件
& && && && && && && && && && &&&raw_corpus = file_read.read()& && & # 读取未处理的语料
& && && && && && && && && && &&&# 按行切分字符串为一个数组
& && && && && && && && && && &&&corpus_array = raw_corpus.splitlines()
& && && && && && && && && && &&&raw_corpus = &&
& && && && && && && && && && &&&for line in corpus_array:
& && && && && && && && && && && && && & line=line.strip()
& && && && && && && && && && && && && & # raw_corpus = self.simple_pruneLine(line,raw_corpus)
& && && && && && && && && && && && && & raw_corpus = self.custom_pruneLine(line,raw_corpus)
& && && && && && && && && && &&&#拼出分词后语料分类目录
& && && && && && && && && && &&&pos_dir = self.pos_path+mydir+&/&&&
& && && && && && && && && && &&&if not os.path.exists(pos_dir):& & #如果没有创建
& && && && && && && && && && && && && & os.makedirs(pos_dir)&
& && && && && && && && && && &&&file_write = open ( pos_dir + file_path, 'wb' )
& && && && && && && && && && &&&file_write.write(raw_corpus)
& && && && && && && && && && &&&file_write.close()&&#关闭写入的文件
& && && && && && && && && && &&&file_read.close()&
& && && && && & print &中文语料修改处理成功!!!&
& && &&&# 对行的简单修剪& && &&&
& && &&&def simple_pruneLine(self,line,raw_corpus):
& && && && && & if line != &&:&
& && && && && && && && &raw_corpus += line
& && && && && & return raw_corpus
& && &&&# 自定义行处理
& && &&&def custom_pruneLine(self,line,raw_corpus):
& && && && && & if line.find(&【 日&&期 】&)!=-1:
& && && && && && && && &line = &&
& && && && && & elif line.find(&【 版&&号 】&)!=-1:
& && && && && && && && &line = &&
& && && && && & elif line.find(&【 作&&者 】&)!=-1:
& && && && && && && && &line = &&
& && && && && & elif line.find(&【 正&&文 】&)!=-1:
& && && && && && && && &line = &&
& && && && && & elif line.find(&【 标&&题 】&)!=-1:
& && && && && && && && &line = &&
& && && && && & if line != &&:
& && && && && && && && &raw_corpus += line
& && && && && & return raw_corpus
& && && && && && && && &
& && &&&# 对预处理后语料进行分词,并持久化。
& && &&&# 处理后在segment_path下建立与pos_path相同的子目录和文件结构
& && &&&def segment(self):
& && && && && & if(self.segment_path==&& or self.pos_path==&&):
& && && && && && && && &print &segment_path或pos_path不能为空&
& && && && && && && && &return&
& && && && && & dir_list = os.listdir(self.pos_path)
& && && && && & # 获取每个目录下所有的文件
& && && && && & for mydir in dir_list:
& && && && && && && && &class_path = self.pos_path+mydir+&/& # 拼出分类子目录的路径
& && && && && && && && &file_list = os.listdir(class_path)&&# 获取class_path下的所有文件
& && && && && && && && &for file_path in file_list:& &# 遍历所有文件
& && && && && && && && && && &&&file_name = class_path + file_path&&# 拼出文件名全路径
& && && && && && && && && && &&&file_read = open(file_name, 'rb')& &# 打开一个文件
& && && && && && && && && && &&&raw_corpus = file_read.read()& && & # 读取未分词语料
& && && && && && && && && && &&&seg_corpus = jieba.cut(raw_corpus)&&# 结巴分词操作
& && && && && && && && && && &&&#拼出分词后语料分类目录
& && && && && && && && && && &&&seg_dir = self.segment_path+mydir+&/&&&
& && && && && && && && && && &&&if not os.path.exists(seg_dir):& & #如果没有创建
& && && && && && && && && && && && && & os.makedirs(seg_dir)&
& && && && && && && && && && &&&file_write = open ( seg_dir + file_path, 'wb' ) #创建分词后语料文件,文件名与未分词语料相同
& && && && && && && && && && &&&file_write.write(& &.join(seg_corpus))&&#用空格将分词结果分开并写入到分词后语料文件中
& && && && && && && && && && &&&file_read.close()&&#关闭打开的文件
& && && && && && && && && && &&&file_write.close()&&#关闭写入的文件
& && && && && & print &中文语料分词成功完成!!!&
& && && && && &&
&&#打包分词后训练语料
& && &&&def train_bag(self):
& && && && && & if(self.segment_path==&& or self.wordbag_path==&& or self.trainset_name==&&):
& && && && && && && && &print &segment_path或wordbag_path,trainset_name不能为空&
& && && && && && && && &return& && && && && &&&
& && && && && & # 获取corpus_path下的所有子分类
& && && && && & dir_list = os.listdir(self.segment_path)
& && && && && & self.data_set.target_name&&= dir_list
& && && && && & # 获取每个目录下所有的文件&
& && && && && & for mydir in dir_list:
& && && && && && && && &class_path = self.segment_path+mydir+&/& # 拼出分类子目录的路径
& && && && && && && && &file_list = os.listdir(class_path)&&# 获取class_path下的所有文件
& && && && && && && && &for file_path in file_list:& &# 遍历所有文档
& && && && && && && && && && &&&file_name = class_path + file_path&&# 拼出文件名全路径
& && && && && && && && && && &&&self.data_set.filenames.append(file_name) #把文件路径附加到数据集中&
& && && && && && && && && && &&&self.data_set.label.append(self.data_set.target_name.index(mydir)) #把文件分类标签附加到数据集中
& && && && && && && && && && &&&file_read = open(file_name, 'rb')& &# 打开一个文件
& && && && && && && && && && &&&seg_corpus = file_read.read()& && & # 读取语料
& && && && && && && && && && &&&self.data_set.contents.append(seg_corpus) # 构建分词文本内容列表
& && && && && && && && && && &&&file_read.close()
& & #词袋对象持久化& && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && &&
& && && && && & file_obj = open(self.wordbag_path+self.trainset_name, &wb&)
& && && && && & pickle.dump(self.data_set,file_obj)& && && && && && && &&
& && && && && & file_obj.close()
& && && && && & print &分词语料打包成功完成!!!&&
& && && && && &&
&&#计算训练语料的tfidf权值并持久化为词袋
& && &&&def tfidf_bag(self):
& && && && && & if(self.wordbag_path==&& or self.wordbag_name==&& or self.stopword_path==&&):
& && && && && && && && &print &wordbag_path,word_bag或stopword_path不能为空&
& && && && && && && && &return
& && && && && & #读取持久化后的训练集对象
& && && && && & file_obj = open(self.wordbag_path+self.trainset_name, &rb&)
& && && && && & self.data_set = pickle.load(file_obj)&
& && && && && & file_obj.close()
& && && && && & # 定义词袋数据结构: tdm:tf-idf计算后词袋
& && && && && & self.wordbag.target_name = self.data_set.target_name
& && && && && & self.wordbag.label = self.data_set.label
& && && && && & self.wordbag.filenames = self.data_set.filenames
& && && && && & # 构建语料
& && && && && & corpus = self.data_set.contents
& && && && && & stpwrdlst = self.getStopword(self.stopword_path)
& && && && && & # 使用TfidfVectorizer初始化向量空间模型--创建词袋&
& && && && && & vectorizer = TfidfVectorizer(stop_words=stpwrdlst,sublinear_tf = True,max_df = 0.5)
& && && && && & # 该类会统计每个词语的tf-idf权值
& && && && && & transformer=TfidfTransformer()
& && && && && & # 文本转为词频矩阵&
& && && && && & self.wordbag.tdm = vectorizer.fit_transform(corpus)
& && && && && & #保存词袋词典文件
& && && && && & self.wordbag.vocabulary = vectorizer.vocabulary_
& && && && && & # 创建词袋的持久化
& && && && && & file_obj = open(self.wordbag_path + self.wordbag_name, &wb&)
& && && && && & pickle.dump(self.wordbag,file_obj)&
& && && && && & file_obj.close()
& && && && && & print &if-idf词袋创建成功!!!&
& && && && && &&
&&#导入获取停止词列表
& && &&&def getStopword(self,stopword_path):
& && && && && & #从文件导入停用词表&
& && && && && & stpwrd_dic = open(stopword_path, 'rb')
& && && && && & stpwrd_content = stpwrd_dic.read()
& && && && && & #将停用词表转换为list
& && && && && & stpwrdlst = stpwrd_content.splitlines()
& && && && && & stpwrd_dic.close()
& && && && && & return stpwrdlst&
& && && && && &&
&&#验证持久化结果:
& && &&&def verify_trainset(self):
& && && && && & file_obj = open(self.wordbag_path+self.trainset_name,'rb')
& && && && && & #读取持久化后的对象
& && && && && & self.data_set = pickle.load(file_obj)
& && && && && & file_obj.close()
& && && && && & #输出数据集包含的所有类别
& && && && && & print self.data_set.target_name
& && && && && & #输出数据集包含的所有类别标签数
& && && && && & print len(self.data_set.label)
& && && && && & #输出数据集包含的文件内容数
& && && && && & print len(self.data_set.contents)& && &&&
& && &&&def verify_wordbag(self):
& && && && && & file_obj = open(self.wordbag_path+self.wordbag_name,'rb')
& && && && && & #读取持久化后的对象
& && && && && & self.wordbag = pickle.load(file_obj)
& && && && && & file_obj.close()
& && && && && & #输出数据集包含的所有类别
& && && && && & print self.wordbag.target_name
& && && && && & #输出数据集包含的所有类别标签数
& && && && && & print len(self.wordbag.label)
& && && && && & #输出数据集包含的文件内容数
& && && && && & print self.wordbag.tdm.shape& && && && && &&
& && &&&#只进行tfidf权值计算:stpwrdlst:停用词表;myvocabulary:导入的词典
& && &&&def tfidf_value(self,test_data,stpwrdlst,myvocabulary):
& && && && && & vectorizer = TfidfVectorizer(vocabulary=myvocabulary)
& && && && && & transformer=TfidfTransformer()
& && && && && & return vectorizer.fit_transform(test_data)
& && &&&#导出词袋模型:
& && &&&def load_wordbag(self):
& && && && && & file_obj = open(self.wordbag_path+self.wordbag_name,'rb')
& && && && && & self.wordbag = pickle.load(file_obj)
& && && && && & file_obj.close()
& & & & #导出训练语料集
& & & & def load_trainset(self):
& & & & & & & & file_obj = open(self.wordbag_path+self.trainset_name,'rb')
& & & & & & & & self.data_set = pickle.load(file_obj)
& & & & & & & & file_obj.close()& & & & & & & && && && && && && && && && && && && && && && && && && && && && && && &&
.TfidfVectorizer
class&sklearn.feature_extraction.text.TfidfVectorizer(input=u'content',&encoding=u'utf-8',charset=None,decode_error=u'strict',&charset_error=None,&strip_accents=None,&lowercase=True,&preprocessor=None,tokenizer=None,analyzer=u'word',&stop_words=None,&token_pattern=u'(?u)bww+b',&ngram_range=(1,&1),max_df=1.0,&min_df=1,max_features=None,&vocabulary=None,&binary=False,&dtype=&type'numpy.int64'&,&norm=u'l2',use_idf=True,smooth_idf=True,&sublinear_tf=False)
转换源文本集合到TF-IDF特征矩阵.
等价于CountVectorizer 服从TfidfTransformer.
Parameters:
input&: string {&filename&, &file&, &content&}
如果是&filename&,序列作为参数传递给拟合器,预计为文件名列表,这需要读取原始内容进行分析。
如果是&file&,序列项目必须有一个&read&的方法(类似文件的对象),被调用作为获取内存中的字节数。&&
否则,输入预计为序列串,或字节数据项都预计可直接进行分析。
encoding&: string, &utf-8& by default.
如果给出要解析的字节或文件, 此编码将用于解码.
decode_error&: {&strict&, &ignore&, &replace&}
如果一个给出的字节序列包含的字符不是给定的编码,指示应该如何去做。默认情况下,它是'strict',这意味着的UnicodeDecodeError将提高。其他值是&ignore&和&replace&.
strip_accents&: {&ascii&, &unicode&, None}
在预处理步骤中去除编码规则(accents)。 &ASCII码&是一种快速的方法,仅适用于有一个直接的ASCII字符映射。 &unicode&是一个稍慢一些的方法。None(默认)什么都不做。
analyzer&: string, {&word&, &char&} or callable
定义特征为词(word)或n-gram字符。如果传递给它的调用被用于抽取未处理输入源文件的特征序列.
preprocessor&: callable or None (default)
当保留令牌和&n-gram&生成步骤时,覆盖预处理(字符串变换)的阶段。
tokenizer&: callable or None (default)
当保留预处理和n-gram生成步骤时,覆盖字符串令牌步骤。
ngram_range&: tuple (min_n, max_n)
要提取的n-gram的n-values的下限和上限范围。在min_n&=n&=max_n区间的n的全部值。&&
stop_words&: string {&english&}, list, or None (default)
如果为'english',用于英语内建的停用词列表。
如果为list,该列表被假定为包含停用词,列表中的所有词都将从令牌中删除。
如果为None,不使用停用词。 max_df可以被设置为范围为[0.7,1.0)的值,基于内部语料词频来自动检测和过滤停用词。
lowercase&: boolean, default True
在令牌标记前转换所有的字符为小写.
token_pattern&: string
正则表达式显示了&token&的构成, 仅当analyzer ==&word&时才被使用。 两个或多个字母数字字符的正则表达式(标点符号完全被忽略,始终被视为一个标记分隔符)。
max_df&: float in range [0.0, 1.0] or int, optional, 1.0&&by default
当构建词汇表时,严格忽略高于给出阈值的文档频率的词条,(语料指定的停用词)。如果是浮点值,该参数代表文档的比例,整型绝对计数值。如果词汇表不为None,此参数被忽略.
min_df&: float in range [0.0, 1.0] or int, optional, 1&&by default
当构建词汇表时,严格忽略低于给出阈值的文档频率的词条,(语料指定的停用词)。这个值也被称为截止文献值。如果是浮点值,该参数代表文档的比例,整型绝对计数值。如果词汇表不为None,此参数被忽略.&&
max_features&: optional, None by default
如果不为None,构建一个词汇表,仅考虑max_features&按语料词频排序.如果词汇表不为None,这个参数被忽略.
vocabulary&: Mapping or iterable, optional
也是一个映射(Map)(例如,字典),其中键是词条而值是在特征矩阵中索引,或词条中迭代器。如果没有给出,词汇表被确定来自输入文件。在映射中索引不能有重复,并且不能在0到最大索引值之间有间断。
binary&: boolean, False by default.
如果为True,所有非零计数被设置为1,这对于离散概率模型是有用的,建立二元事件模型,而不是整型计数。
dtype&: type, optional
通过fit_transform()或transform()返回矩阵的类型.
norm&: &l1&, &l2& or None, optional
范数用于标准化词条向量。None为不归一化。
use_idf&: boolean, optional
启动 inverse-document-frequency 重新计算权重.
smooth_idf&: boolean, optional
通过加1到文档频率平滑 idf 权重, 为防止除零,加入一个额外的文档.
sublinear_tf&: boolean, optional
应用线性缩放TF, 例如,使用1+log(tf)覆盖 tf.
Attributes:
``idf_``&: array, shape = [n_features], or None
学习 idf 向量 (全局词条权重) 当use_idf被设置为 True,否则为 None.
Tokenize the documents and count theoccurrences of token and return them as a sparse matrix
Apply TermFrequency Inverse Document Frequency normalization to a sparse matrix ofoccurrence counts.
返回一个可调用的预处理和分词句柄
返回一个函数在分词前预处理文本
返回一个函数,分割一个字符串为连续的令牌
解码输入中的Unicode的符号串
(raw_documents[, y])
学习原始文档中的所有令牌词汇表.
(raw_documents[, y])
学习词汇表并且返回文件词条矩阵(term-document matrix).
一个数组映自特征整形索引到特征名称.
获取预测器的参数.
构建和抽取停止词表
返回文档中的词条--X中非零项.
(**params)
设置预测器参数.
(raw_documents[, copy])
转换文档为文档词条矩阵(document-term&&matrix).
__init__(input=u'content',&encoding=u'utf-8',&charset=None,&decode_error=u'strict',charset_error=None,strip_accents=None,&lowercase=True,&preprocessor=None,&tokenizer=None,&analyzer=u'word',stop_words=None,token_pattern=u'(?u)bww+b',&ngram_range=(1,&1),&max_df=1.0,&min_df=1,&max_features=None,vocabulary=None,binary=False,&dtype=&type'numpy.int64'&,&norm=u'l2',&use_idf=True,&smooth_idf=True,sublinear_tf=False)
build_analyzer()
返回一个可调用的预处理和分词句柄
build_preprocessor()
返回一个函数在令牌分词之前预处理文本
build_tokenizer()
返回一个函数,分割一个字符串为连续的令牌
decode(doc)
解码输入中的Unicode的符号串
解码策略取决于向量器参数。
fit(raw_documents, y=None)
学习文档和来自训练集的idf.
Parameters:
raw_documents&: iterable
一个迭代器,产生了 str, unicode 或文件对象
self&: TfidfVectorizer
fit_transform(raw_documents,&y=None)
学习词汇表并且返回文件词条矩阵(term-documentmatrix).
等价于拟合转换, 但更有效.
Parameters:
raw_documents&: iterable
一个迭代器,产生了 str, unicode 或文件对象.
X&: sparse matrix, [n_samples, n_features]
Tf-idf-权重 文档-词条矩阵.
fixed_vocabulary
DEPRECATED: The fixed_vocabulary attribute isdeprecated and will be removed in 0.18. Please usefixed_vocabulary_ instead.
get_feature_names()
一个数组映自特征整形索引到特征名称。
get_params(deep=True)
获取预测器的参数.
Parameters:
deep: boolean,&&optional&:
如果为True, 将返回这个预测器的参数并且包含预测器的子对象..
params&: mapping of string to any
参数名称映射到它的值.
get_stop_words()
构建和抽取停止词表
inverse_transform(X)
返回文档中的词条--X中非零项.
Parameters:
X&: {array, sparse matrix}, shape = [n_samples,&&n_features]
X_inv&: list of arrays, len = n_samples
项目数组列表.
set_params(**params)
设置预测器参数.
该方法适用于简单的估计,以及嵌套对象(如管道)。前者的格式&component&_&parameter&,以便它可以更新嵌套对象的每个组件的参数。
transform(raw_documents, copy=True)
转换文档为文档词条矩阵.
使用学习自fit(或 fit_transform)的词汇表和文本频率(df)。.
Parameters:
raw_documents&: iterable
一个迭代器,产生了包含 str, unicode 或文件对象.
X&: sparse matrix, [n_samples, n_features]
Tf-idf-权重文档-词条矩阵.
上一篇:&&&&下一篇:
交换链接&&
Copyright &2017 &&
All Right Reserved.
Powered by
版权所有 &

我要回帖

更多关于 多线程实现矩阵乘法 的文章

 

随机推荐