Help: Mystery Friend Error

I am getting an error on the last part of the Mystery Friend project. I am at a loss as to what the problem may be.

My Code

The Error

Traceback (most recent call last):
File “”, line 45, in
predictions = friends_classifier.predict(mystery_vector) #[“None Yet”]
File “/usr/local/lib/python3.6/dist-packages/sklearn/”, line 77, in predict
X = self._check_X(X)
File “/usr/local/lib/python3.6/dist-packages/sklearn/”, line 477, in _check_X
return check_array(X, accept_sparse=‘csr’)
File “/usr/local/lib/python3.6/dist-packages/sklearn/utils/”, line 73, in inner_f
return f(**kwargs)
File “/usr/local/lib/python3.6/dist-packages/sklearn/utils/”, line 617, in check_array
“if it contains a single sample.”.format(array))
ValueError: Expected 2D array, got scalar array instead:
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

Your error code seems to point at the issue. A ValueError that a function/method expected a 2D array and instead got a scalar array. I’d assume the friends_classifier.predict() takes a 2D array. Check the docs and adjust your values as necessary to make sure that it is passed an argument it expects.


I still have no clue. Other users don’t seem to be having this problem, or it is a new issue. I don’t know how to reshape my data. The lessons leading up to this do not address this in any way, shape, or form.

Hi, @tardismonkey,

Link to Project Page: Learn Natural Language Processing: Mystery Friend

Instruction 4 includes this:

Create a new variable mystery_vector . Assign to it the vectorized form of [mystery_postcard] using the vectorizer’s .transform() method.

However, you defined mystery_vector as follows, using the fit method instead of the transform method:

mystery_vector =[mystery_postcard])

Edited on September 1, 2020 to add a link to the project page.