MulaiMulai sekarang secara gratis

Counting words (I)

Once high level information has been recorded you can begin creating features based on the actual content of each text. One way to do this is to approach it in a similar way to how you worked with categorical variables in the earlier lessons.

  • For each unique word in the dataset a column is created.
  • For each entry, the number of times this word occurs is counted and the count value is entered into the respective column.

These "count" columns can then be used to train machine learning models.

Latihan ini adalah bagian dari kursus

Feature Engineering for Machine Learning in Python

Lihat Kursus

Petunjuk latihan

  • Import CountVectorizer from sklearn.feature_extraction.text.
  • Instantiate CountVectorizer and assign it to cv.
  • Fit the vectorizer to the text_clean column.
  • Print the feature names generated by the vectorizer.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Import CountVectorizer
____

# Instantiate CountVectorizer
cv = ____

# Fit the vectorizer
cv.____(speech_df['text_clean'])

# Print feature names
print(cv.____)
Edit dan Jalankan Kode