I want to build an algorithm that classifies text: ham or spam; I have the train/test data for each category of text. (my train data has for each category 8000 sentences, and for test each category contains 2000 sentences)
X_train looks like this ['please, call me asap!', 'watch out the new sales!', 'hello jim can we talk?', 'only today you can buy this', 'don't miss our offer!']
y_train looks like this [1 0 1 0 0] where 1 = ham, 0 = spam
the same with X_test and y_test.
This is a snippet of my code:
# classifier can be LogisticRegression, MultinomialNB, RandomForest, DecisionTree
text_clf = Pipeline([('vect', CountVectorizer()),
('tfidf', TfidfTransformer()),
('clf', classifier),
])
model = text_clf.fit(X_train, y_train)
y_predict = model.predict(X_test)
And these are the parameters that I measure:
print(accuracy_score(y_test, y_predict))
print(f1_score(y_test, y_predict, average="weighted"))
print(recall_score(y_test, y_predict, pos_label=1, average="binary"))
print(precision_score(y_test, y_predict, average="weighted"))
If I don't use any optimization (remove stop words, remove punctuation, stem words, lemmatize words) I obtain results around 95% each parameter. If I use those optimizations, the accuracy, f1 score and precision decrease drastically to 50-60%. The recall function stays the same at 95%.
Why is this happening? Where am I mistaking? Did I calculate right those parameters? Or this is a normal behavior?
featureswill you try to told me why this behavior? - Mr. Wizard