Changing phrases to vectors with while function in Python

后端 未结 2 366
情深已故
情深已故 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).

提交回复
热议问题