0

I've been tasked with creating a Chatbot that uses the SKlearn library to create a similarity component and I've been having trouble with coding it (and honestly understanding it as a whole). I specifically have to use cosine_similarity and TfidfVectorizer to do this. Please forgive me if I'm unclear from this point on this task is no playing towards my strengths. I'll happily answer any questions.

I'm having trouble initially with my imports.

from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity

I am using PyCharm and have imported the library (scikit-learn 0.23.2 0.23.2) using the software's "Python Interpreter" however the lines are greyed out which is making me think something is wrong?

This is a look at the code in the program. As you can see the known working imports are in colour whilst the sklearn ones are not

Aside from this, I'm not sure what to do with my code but I thought fixing this issue is the first step.

Let me know if I need to add more information or anything at all. I'm sorry I wasn't too sure what to add to this question.

Sorry a comment made me realise I never added the results of running the code to the post https://i.stack.imgur.com/DtWKQ.jpg

I'm not sure if it's of use, but here is a screenshot as well of my Lib folder. It features scikit_learn right at the bottom https://i.stack.imgur.com/1waNh.jpg

Hannah
  • 67
  • 7
  • And have you tried running the code to see whether the imports are working? If it is not working then what is the error? – Matus Dubrava Nov 22 '20 at 15:48
  • Thank you for your reply. Sorry I meant to add this to the post, https://imgur.com/a/IhFj8z5 this is what happens when I run with the two lines, but I'm not sure what is causing the issue. I've not changed how I import compared to the rest of the imports above @MatusDubrava – Hannah Nov 22 '20 at 15:51
  • It would be better to just copy and paste the error here so that the information is not lost when the link goes down. Anyway, it seems like an issue with your python packages. Try updating `numpy` and `sklearn` to their latest version. – Matus Dubrava Nov 22 '20 at 15:55
  • According to this, they are at their latest versions. Unless I've misunderstood something? https://imgur.com/a/LgDELNT @MatusDubrava – Hannah Nov 22 '20 at 16:00
  • https://stackoverflow.com/questions/64654805/how-do-you-fix-runtimeerror-package-fails-to-pass-a-sanity-check-for-numpy-an have you checked this post? – Matus Dubrava Nov 22 '20 at 16:09

1 Answers1

1

Well, the greyed out lines are not really an issue as it simply means that you have not used the packages that you have imported so far.

And as for the error you're getting it seems the version of Numpy package you have doesn't really agree with either the python version or sklearn package version.

refer: How do you fix "runtimeError: package fails to pass a sanity check" for numpy and pandas?

I wish you good luck with the chat-bot !

Gauthum.J
  • 44
  • 4