我陷入一个问题,我必须在scikit Learn的CountVectorizer函数创建的令牌计数列表中添加其他功能(平均字长)。说我有以下代码:
#list of tweets
texts = [(list of tweets)]
#list of average word length of every tweet
average_lengths = word_length(tweets)
#tokenizer
count_vect = CountVectorizer(analyzer = 'word', ngram_range = (1,1))
x_counts = count_vect.fit_transform(texts)
每个实例的格式应为(令牌,平均字长)。我最初的想法是使用zip函数将两个列表简单地串联起来:
x = zip(x_counts, average_lengths)
但是当我尝试拟合模型时出现错误:
ValueError: setting an array element with a sequence.
有人知道如何解决这个问题吗?
你可以写自己喜欢的变压器在这个文章,给你每鸣叫和使用的平均字长FeatureUnion:
vectorizer = FeatureUnion([
('cv', CountVectorizer(analyzer = 'word', ngram_range = (1,1))),
('av_len', AverageLenVectizer(...))
])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句