【发布时间】:2019-10-05 22:13:41
【问题描述】:
我要进行方言文本分类,我有这个代码:
from sklearn.naive_bayes import MultinomialNB
from sklearn.feature_extraction.text import CountVectorizer
vectorizerN = CountVectorizer(analyzer='char',ngram_range=(3,4))
XN = vectorizerN.fit_transform(X_train)
vectorizerMX = CountVectorizer(vocabulary=a['vocabs'])
MX = vectorizerMX.fit_transform(X_train)
from sklearn.pipeline import FeatureUnion
combined_features = FeatureUnion([('CountVectorizer', MX),('CountVect', XN)])
combined_features.transform(test_data)
当我运行这段代码时,我得到了这个错误:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
我正在关注这篇文章中的代码: Merging CountVectorizer in Scikit-Learn feature extraction
另外,之后我该如何训练和预测?
【问题讨论】:
标签: python scikit-learn nlp text-classification countvectorizer