Python:list对象没有属性';下';-但语料库已经是小写的了
我的语料库是一系列包含twitter数据的文档,据我所知,已经进行了清理和预处理(甚至包括表情符号)-示例如下:Python:list对象没有属性';下';-但语料库已经是小写的了,python,nlp,tfidfvectorizer,Python,Nlp,Tfidfvectorizer,我的语料库是一系列包含twitter数据的文档,据我所知,已经进行了清理和预处理(甚至包括表情符号)-示例如下: 0 [national, interest, think, worth, holding, ta... 1 [must, accurate, diane, abbott, done, calculat... 然后我实例化TFIDF: # Instantiate vectoriser vect = TfidfVector
0 [national, interest, think, worth, holding, ta...
1 [must, accurate, diane, abbott, done, calculat...
然后我实例化TFIDF:
# Instantiate vectoriser
vect = TfidfVectorizer()
# Fit
vect = TfidfVectorizer(min_df=10, ngram_range = (1,3)).fit(text)
当我尝试适应这一点时,我得到:
AttributeError: 'list' object has no attribute 'lower'
但我已经把所有东西都转换成小写了。这和这是一部连续剧有关吗
将原始文档集合转换为TF-IDF特征矩阵
从这个意义上讲,您在这里复制的数据帧中传递了一系列列表
:
from sklearn.feature_extraction.text import TfidfVectorizer
import pandas as pd
l1 = 'national, interest, think, worth, holding,'.split(',')
l2 = 'must, accurate, diane, abbott, done'.split(',')
df = pd.DataFrame([[l1],[l2]])
text = df[0]
它将文本参数返回为:
0 [national, interest, think, worth, holding, ]
1 [must, accurate, diane, abbott, done]
Name: 0, dtype: object
这显然不起作用,正如所指出的,TfidfVectorizer
接受字符串或文档。在您的情况下,根据示例,尽管您的示例有点违反直觉
您能提供更多关于您正在使用的库和输入的详细信息吗?例外情况表明,您提供的是一个
列表
作为输入,而不是一个具有较低
属性(如字符串)的对象。除了pandas和numpy之外,我还导入了sklearn tfidfvectorier,该对象是pandas.core.series.series,基于快速谷歌搜索,.fit()
正在寻找可生成str
、unicode
或文件的对象。我认为熊猫系列是不合适的。我想您可能需要使用.fit(text.iteritems())
尝试了一下,得到的结果是:“tuple”对象没有属性“lower”
corpus = text.apply(lambda x: ','.join(x)).to_list() # converts your series into a list of strings
vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(corpus)
print(vectorizer.get_feature_names())
['abbott', 'accurate', 'diane', 'done', 'holding', 'interest', 'must', 'national', 'think', 'worth']