# Printing the tweets that were incorrectly predicted after applying a machine learning classifier

I applied the random forest classifier to my csv file to classify the tweets as spam or not spam and after an accuracy of 93%, when I printed the confusion matrix I got [[1068 105] [ 65 1262]]. Now I would like to print the 65 false negative tweets and the 105 false positive tweets but I am unable to do that. I tried to print the y_test and y_predict but it is difficult to map the incorrectly identified tweets. Has anyone please got any advice on this?

RandomForest = RandomForestClassifier() RandomForest.fit(x_train, y_train) y_predict = RandomForest.predict(x_test) print(confusion_matrix(y_test,y_predictRF))

Thank you

## 1 Answer

Assuming that you have a column called „target“ and „predicted“:

FN = df[(df[„predicted“]==0) & (df[„target“] == 1)]


and vice versa for FP.

• i don't have one. I tried def predicted(x): x = data.Target for x in (1, 1000): x = y_predict return x then data['predicted'] = data['Target'].apply(lambda x: predicted(x)) but I am getting an error. Feb 1 at 11:41
• I have a column called „target“ but not „predicted“. Feb 1 at 11:42
• I also tried data['pred'] = y_predict but it gave me the error "Length of values (2500) does not match length of index (8000)" Feb 1 at 11:55
• It doesn’t matter how you named your columns, you would just need one binary scaled column with your actual values in it and another binary scaled column with the predictions in it. You have these column because otherwise you wouldn’t be able to print the confusion matrix which you showed to us .. Feb 1 at 12:23
• can you please tell me how to add the predicted results into a csv file. when i do it, all 2500 results get added to 1 row. Feb 1 at 16:23