Help: Mystery Friend project error

Hi all,

Seek your help to identify and eliminate error in the code.
Any help would be really appreciated. Thanks!

About the project: This code is an input to the Mystery Friend project, part of the Natural Language Processing, Bag of Words project.

There is an error in line 35, referred to other codes in the project as well, they seem to work with the same input.

Code

Code error
Traceback (most recent call last):
File “script.py”, line 35, in
mystery_vector=bow_vectorizer.fit_transform(mystery_postcard)
File “/usr/local/lib/python3.6/dist-packages/sklearn/feature_extraction/text.py”, line 860, in fit_transform
"Iterable over raw text documents expected, "
ValueError: Iterable over raw text documents expected, string object received.

Thanks,
Kabir

Hi, @kabir_jain.

In this line, what type of object should be passed to the fit_transform method?:

mystery_vector=bow_vectorizer.fit_transform(mystery_postcard)

See instruction 4.

Edited on August 9, 2020 to add the following:

Link to project: Learn Natural Language Processing: Mystery Friend

Hi @appylpye,

Thanks for the response.

I understand that it needs to be a vectorized form of the string i.e. mystery_postcard.
I tried this, mystery_vector=bow_vectorizer.transform(mystery_postcard) in the code. It gives an error in line 35.

Am I missing anything in the code? :sweat_smile:

You need to pass a list of one or more strings to the bow_vectorizer.transform() method. Enclose mystery_postcard in square brackets, as follows:

mystery_vector=bow_vectorizer.transform([mystery_postcard])

Thanks so much! The code worked.

1 Like