Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Expected 2D array, got 1D array instead #2

Open
vizhong opened this issue Jul 21, 2019 · 0 comments
Open

ValueError: Expected 2D array, got 1D array instead #2

vizhong opened this issue Jul 21, 2019 · 0 comments

Comments

@vizhong
Copy link

vizhong commented Jul 21, 2019

I ran the bot in Python 2.7 and got this error:
Traceback (most recent call last):
File "bot.py", line 118, in
main()
File "bot.py", line 100, in main
print get_response(msg)
File "bot.py", line 84, in get_response
val = sim(msg, question)
File "bot.py", line 75, in sim
return alpha*sem_sim(s1, s2) + (1-alpha)*cos_sim(s1, s2)
File "bot.py", line 72, in cos_sim
return cosine_similarity([d[0][p] for p in all_tags], [d[1][p] for p in all_tags])[0][0]
File "C:\Users\AppData\Local\Continuum\anaconda3\envs\Test\lib\site-packages\sklearn\metrics\pairwise.py", line 896, in cosine_similarity
X, Y = check_pairwise_arrays(X, Y)
File "C:\Users\AppData\Local\Continuum\anaconda3\envs\Test\lib\site-packages\sklearn\metrics\pairwise.py", line 111, in check_pairwise_arrays
warn_on_dtype=warn_on_dtype, estimator=estimator)
File "C:\Users\AppData\Local\Continuum\anaconda3\envs\Test\lib\site-packages\sklearn\utils\validation.py", line 552, in check_array
"if it contains a single sample.".format(array))
ValueError: Expected 2D array, got 1D array instead:
array=[0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 1. 0. 1. 0. 0. 1. 0. 0.].
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant