Work / Fake News Detection
NLPDetecting Fake News with Machine Learning
A step-by-step NLP project that tells genuine news from fabricated stories using only the article itself: its headline and body text.
images/fake-news.svg01Question
Can a model reliably tell a genuine news article from a fabricated one using only what the article says? No source reputation, no social signals, just the text. It's a classic binary text-classification problem, and a good test of how far a well-built simple pipeline can go.
02Data
The ISOT Fake News dataset (Kaggle) arrives as two files: 23,481 fake articles (label 0) and 21,417 real articles (label 1), each with a title, body text, subject and date. The two classes are close to balanced.
- Removed rows with empty or whitespace-only text, plus texts that were just URLs or page-builder shortcodes. That left 44,170 articles.
- Merged eight inconsistent subject labels into six categories, for example “politicsNews” and “politics” become “politics”.


03Method
- Combined text: joined the title and body into one field, because headlines carry a lot of the signal.
- TF-IDF: turned each article into a weighted bag of words, giving 122,413 features across 44,170 articles. One-hot subject columns were appended.
- Linear SVC: a linear support-vector classifier, fast and well suited to sparse, high-dimensional text.
- Evaluation: held out a 33% test set and measured accuracy, precision, recall, F1 and the confusion matrix.
news_df["title_text"] = news_df["title"] + ". " + news_df["text"]
news_tfidf = TfidfVectorizer().fit_transform(news_df["title_text"])
X = hstack([news_tfidf, subject_dummies.values])
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=24)
clf = LinearSVC().fit(X_train, y_train)
04Results
| Predicted fake | Predicted real | |
|---|---|---|
| Actually fake | 7,454 | 50 |
| Actually real | 27 | 7,046 |
The model reached 99.47% accuracy, with precision, recall and F1 of 0.99–1.00 for both classes. It made only 77 mistakes across 14,577 unseen articles, and missed slightly more fake stories (50) than it wrongly flagged real ones (27).
05Reflection
The main lesson: a simple linear model on good features is a strong baseline that is hard to beat. A near-perfect score on a benchmark should also make you sceptical. In this dataset, some subject categories appear only in fake articles, and the real articles come from a single newswire with a recognisable house style. Both can act as shortcuts. The next step is to drop the subject features, strip source boilerplate, and test on news from a different source and time period to see how well the model really generalises.
Next project
Avocado Prices vs Sales →
Screenshot comingimages/avocado-price.png