I am currently trying to build a naive Bayes classifier as mentioned in this link. Referring to the line
X_new_tfidf = tfidf_transformer.transform(X_new_counts)
under the Training the Classifier
subheading, I had a similar line, X_new_counts = count_vect.transform(input.plot_movie)
in my code which should take an iterable as an input to the transform function. The input
is a record from a DataFrame and is of type pd.Series
and contains the following entries, out of which I send input.plot_movie
as the input to the transform function:
However, I get the following error: Iterable over raw text documents expected, string object received
How do I fix this error? I also referred to this answer where the person says that s
is an iterable because it was assigned a string. I also came across this link where a TypeError: 'String' object is not iterable
is encountered. Am I missing something here? The links seem to contradict each other.
EDIT:
I just realized that input.plot_movie
is of type unicode and decided to convert it to a string. I encounter the same error again.
The cause of this problem is that input is just a string, but what is needed is a list (or an iterable) containing a single element.
The error can be removed by adding the following line:
input=[input]
before
X_new_counts = count_vect.transform(input.plot_movie)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With