Search code examples
pythonpython-3.xscikit-learnpycharmchatbot

Using Sklearn to create Similarity Component in Chatbot - Imports not Working


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.sstatic.net/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.sstatic.net/1waNh.jpg


Solution

  • 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 !