Classifying news articles as Fake or Real with NLP, TF-IDF and Logistic Regression
Misinformation spreads faster than corrections. This project trains a text classifier on 44,000+ labelled news articles to decide whether a new article is FAKE or REAL, and reports how confident it is.
Articles are cleaned with an NLP pipeline, turned into TF-IDF vectors, and classified with Logistic Regression. After training, you can paste any article into the terminal and get an instant prediction.
- 🧹 Text cleaning: lowercase, strip URLs, HTML, punctuation, digits and stopwords (NLTK)
- 🔢 TF-IDF vectorisation of article text
- 🤖 Logistic Regression classifier
- 📊 Accuracy, precision, recall, F1 and a confusion matrix
- 📏 Word-count comparison of fake vs real articles
- ⌨️ Interactive mode: paste your own article and get FAKE / REAL + confidence %
flowchart LR
A[Fake.csv + True.csv] --> B[Label 0 = Fake, 1 = Real]
B --> C[Clean text]
C --> D[Train/test split 75/25]
D --> E[TF-IDF]
E --> F[Logistic Regression]
F --> G[Metrics + confusion matrix]
F --> H[Predict custom article]
FakeNews_Detection/
├── data/
│ ├── Fake.csv # ~23,000 fake articles
│ └── True.csv # ~21,000 real articles
├── outputs/ # Generated charts
├── src/
│ └── main.py # Full pipeline + interactive prediction
├── requirements.txt
└── README.md
git clone https://github.com/Gaganajain/FakeNews_Detection.git
cd FakeNews_Detection
pip install -r requirements.txt
cd src
python main.pyAfter training, the program asks for an article:
Enter News Article:
NASA confirms the next crewed mission to the Moon is scheduled for ...
Prediction: REAL NEWS (97.85% confidence)
| Area | Tools |
|---|---|
| Language | Python |
| NLP | NLTK stopwords, regex cleaning, TF-IDF |
| ML | scikit-learn Logistic Regression |
| Visualisation | Matplotlib, Seaborn |
- Compare with Naive Bayes, PassiveAggressive and a fine-tuned BERT model
- Save the trained model with
jobliband serve it through a Streamlit web app - Use the article title and subject as extra features
Gagana Jain A · GitHub
⭐ If you found this useful, consider giving the repo a star!
