I am trying to use both counts and tfidf as functions for the multidimensional NB model. Here is my code:
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)
But I get an error with FeatureUnion and tfidf:
TypeError: no supported conversion for types: (dtype('S18413'),)
Any idea why this might happen? Is it impossible to have both counts and tfidf as functions?
source share