Код: Выделить всё
from sklearn.feature_extraction.text import CountVectorizer
import pandas as pd
headers = ['label', 'sms_message']
df = pd.read_csv ('spam.csv', names = headers)
df ['label'] = df['label'].map({'ham': 0, 'spam': 1})
print (df.head(7))
print (df.shape)
count_vector = CountVectorizer()
#count_vector.fit(df)
y = count_vector.fit_transform(df)
count_vector.get_feature_names()
doc_array = y.toarray()
print (doc_array)
frequency_matrix = pd.DataFrame(doc_array, columns = count_vector.get_feature_names())
frequency_matrix
Код: Выделить всё
label sms_message
0 0 Go until jurong point, crazy.. Available only ...
1 0 Ok lar... Joking wif u oni...
2 1 Free entry in 2 a wkly comp to win FA Cup fina...
3 0 U dun say so early hor... U c already then say...
(5573, 2)
[[1 0]
[0 1]]
label sms_message
0 1 0
1 0 1
Мой CSV-файл в основном представляет собой множество строк SMS-сообщений.
Я не могу понять, почему я получаю вывод только для меток столбцов, а не для всех строк текста смс.
Спасибо за любая помощь.
Подробнее здесь: https://stackoverflow.com/questions/594 ... ikit-learn
Мобильная версия