【问题标题】:Python,sklearn,it-idf how to split by "####",default spacePython,sklearn,it-idf 如何按“####”分割,默认空间
【发布时间】:2017-03-09 07:32:57
【问题描述】:

使用sklean tf-idf,默认使用空间分割

corpus = [  
'This is the first document.',  
'This is the second second document.',  
'And the third one.',  
'Is this the first document?'
]    

vectorizer = CountVectorizer()   
X = vectorizer.fit_transform(corpus)

但是,我想使用这种形式:

enter code herecorpus = [  
'This####is####the####first####document.',  
'This####is####the####second####second####document.'
]
vectorizer = CountVectorizer()   
X = vectorizer.fit_transform(corpus)
tfidf=transformer.fit_transform(vectorizer.fit_transform(documents))
word=vectorizer.get_feature_names()
weight=tfidf.toarray()

怎么办?

【问题讨论】:

标签: python split scikit-learn tf-idf


【解决方案1】:

使用自定义标记器:

def four_pounds_tokenizer(s):
   return s.split('####')

vectorizer = CountVectorizer(tokenizer=four_pounds_tokenizer)
X = vectorizer.fit_transform(corpus)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-17
    • 1970-01-01
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 2018-10-24
    相关资源
    最近更新 更多