我想从 sklearn 的 Tfidfvectorizer 对象中获取矩阵。这是我的代码:
from sklearn.feature_extraction.text import TfidfVectorizer
text = ["The quick brown fox jumped over the lazy dog.",
"The dog.",
"The fox"]
vectorizer = TfidfVectorizer()
vectorizer.fit_transform(text)
这是我尝试并返回错误的方法:
vectorizer.toarray()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-117-76146e626284> in <module>() ----> 1 vectorizer.toarray() AttributeError: 'TfidfVectorizer' object has no attribute 'toarray'
另一次尝试
vectorizer.todense()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-118-6386ee121184> in <module>() ----> 1 vectorizer.todense() AttributeError: 'TfidfVectorizer' object has no attribute 'todense'