TFIDF Vectorizer giving error

淺唱寂寞╮ 提交于 2019-12-06 06:58:06

the input to the tokenizer paramter is a callable. Try defining a function that will tokenize your data appropriately. If it is comma delimited then:

def tokens(x):
return x.split(',')

should work.

from sklearn.feature_extraction.text import TfidfVectorizer
tfidf_vect= TfidfVectorizer( tokenizer=tokens ,use_idf=True, smooth_idf=True, sublinear_tf=False)

create a random string delimited by ,

 a=['cat on the,angel eyes has,blue red angel,one two blue,blue whales eat,hot tin roof']

tfidf_vect.fit_transform(a)
tfidf_vect.get_feature_names()

returns

Out[73]:

[u'angel eyes has',
 u'blue red angel',
 u'blue whales eat',
 u'cat on the',
 u'hot tin roof',
 u'one two blue']
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!