Python ile NLP için Özellik Mühendisliği
Rounak Banik
Data Scientist
| message | label |
|---|---|
| WINNER!! As a valued network customer you have been selected to receive a $900 prize reward! To claim call 09061701461 | spam |
| Ah, work. I vaguely remember that. What does it feel like? | ham |
CountVectorizer argümanları
lowercase: False, Truestrip_accents: 'unciode', 'ascii', Nonestop_words: 'english', list, Nonetoken_pattern: regextokenizer: function# CountVectorizer'ı içe aktarın from sklearn.feature_extraction.text import CountVectorizer# CountVectorizer nesnesi oluşturun vectorizer = CountVectorizer(strip_accents='ascii', stop_words='english', lowercase=False)# train_test_split'i içe aktarın from sklearn.model_selection import train_test_split # Eğitim ve test setlerine ayırın X_train, X_test, y_train, y_test = train_test_split(df['message'], df['label'], test_size=0.25)
... ... # Eğitim BoW vektörlerini üretin X_train_bow = vectorizer.fit_transform(X_train)# Test BoW vektörlerini üretin X_test_bow = vectorizer.transform(X_test)
# MultinomialNB'yi içe aktarın from sklearn.naive_bayes import MultinomialNB# MultinomialNB nesnesi oluşturun clf = MultinomialNB()# clf'yi eğitin clf.fit(X_train_bow, y_train)# Test setinde doğruluğu hesaplayın accuracy = clf.score(X_test_bow, y_test) print(accuracy)
0.760051
Python ile NLP için Özellik Mühendisliği