Changing phrases to vectors with while function in Python

后端 未结 2 367
情深已故
情深已故 2021-01-13 00:41

I would like to change the following phrases to vectors with sklearn:

Article 1. It is not good to eat pizza after midnight
Article 2. I wouldn\'t survive a          


        
相关标签:
2条回答
  • 2021-01-13 01:00

    Look at the docs. It says CountVectorizer.fit_transform expects an iterable of strings (e.g. a list of strings). You are passing a single string instead.

    It makes sense, fit_transform in scikit does two things: 1) it learns a model (fit) 2) it applies the model on the data (transform). You want to build a matrix, where columns are all the words in the vocabulary and rows correspond to the documents. For that you need to know the whole vocabulary in your corpus (all the columns).

    0 讨论(0)
  • 2021-01-13 01:03

    This problem occurs when you provide the raw data, means directly giving the string to the extraction function ,instead you can give Y = [X] and pass this Y as the parameter then you will get it correct i faced this problem too

    0 讨论(0)
提交回复
热议问题