【发布时间】:2015-01-31 08:54:43
【问题描述】:
我正在尝试同时使用计数和 tfidf 作为多项式 NB 模型的特征。这是我的代码:
text = ["this is spam", "this isn't spam"]
labels = [0,1]
count_vectorizer = CountVectorizer(stop_words="english", min_df=3)
tf_transformer = TfidfTransformer(use_idf=True)
combined_features = FeatureUnion([("counts", self.count_vectorizer), ("tfidf", tf_transformer)]).fit(self.text)
classifier = MultinomialNB()
classifier.fit(combined_features, labels)
但是我遇到了 FeatureUnion 和 tfidf 的错误:
TypeError: no supported conversion for types: (dtype('S18413'),)
知道为什么会发生这种情况吗?不能同时将计数和 tfidf 作为特征吗?
【问题讨论】:
标签: python numpy nlp scikit-learn ml