Python 2.7 使用sklearn.feature\u extraction.text countvectorier时从文件中读取文档

Python 2.7 使用sklearn.feature\u extraction.text countvectorier时从文件中读取文档,python-2.7,scikit-learn,Python 2.7,Scikit Learn,我能够使用文档示例中的代码,其中fit_transform()函数的输入是一个句子列表,即: corpus = [ 'this is the first document', 'this is the second second document', 'and the third one', 'is this the first document?' ] X=矢量器。拟合_变换(语料库) 并获得预期的数据。但当我试图用文件列表或文件对象(如文档所示)替换语料库时: "

我能够使用文档示例中的代码,其中fit_transform()函数的输入是一个句子列表,即:

corpus = [
   'this is the first document',
   'this is the second second document',
   'and the third one',
   'is this the first document?'
]
X=矢量器。拟合_变换(语料库)

并获得预期的数据。但当我试图用文件列表或文件对象(如文档所示)替换语料库时:

" 拟合(原始文档,y=无)

"

。。因此,我认为我对管道的理解中缺少了一些东西。给定一个我想对其进行矢量化计数的文件目录,我该怎么做?
如果我尝试将文件对象列表作为[open(file,'r')输入,我得到的错误消息是文件对象没有较低的功能。

将矢量器的
输入设置为
文件名
文件
。它的默认值是
content
,假设您已经将文件读入内存。

谢谢,这就是我在解释文档时迷失的地方。实际上,我将文件直接输入到构造函数,但是没有收到任何警告,所以我没有看到它。
Learn a vocabulary dictionary of all tokens in the raw documents.
Parameters :    
raw_documents : iterable
    An iterable which yields either str, unicode or file objects.
Returns :   
self :