Элементы функции Sklearn CountVectorizer - PullRequest
0 голосов
/ 10 июля 2020

У меня проблема с CountVectorizer, он смешивает слова вместе. Что мне не хватает?

Вот что я сделал:

raw = open('smsspam').read() 

Набор данных SMS-спама UCI

corpse = raw.replace('\t', '\n').split('\n')
parsed = [i for i in corpse if i]

#Select features
labels = parsed[0::2]
msg = parsed[1::2]

import pandas as pd
pd.set_option('display.max_colwidth', 100)
df = pd.DataFrame({'Label' : labels,'SMS' : msg})

#LEMMATIZING

import string
import re
stopwords = nltk.corpus.stopwords.words('english')
wn = nltk.WordNetLemmatizer()
wn.lemmatize('word')

def lemmatizer(text):
text = "".join([i for i in text if i not in string.punctuation])
text = re.split('\W+', text)
text = [i for i in text if i not in stopwords]
text = [wn.lemmatize(i) for i in text]
return text
df['Stems'] = df['SMS'].apply(lambda x: lemmatizer(x.lower()))
df.head(10)

Снимок экрана

https://ibb.co/fMSxFw8]

#Vectorization
from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer(analyzer=lemmatizer)
x = cv.fit_transform(df['Stems'])

df2 = pd.DataFrame(x.toarray(), columns=cv.get_feature_names())
df2.tail()

снимок экрана

https://ibb.co/DKVSzdN

Что мне здесь не хватает?

...