An open API service indexing awesome lists of open source software.

https://github.com/ramarav/fake_news_detection

Machine learning approach for fake news detection using Scikitlearn
https://github.com/ramarav/fake_news_detection

itertools jupyter-notebook jupyter-notebooks machine-learning machine-learning-algorithms machinelearning numpy pandas passiveaggressiveclassifier python python-3 python3 scikit-learn scikitlearn-machine-learning tfidfvectorizer

Last synced: about 2 months ago
JSON representation

Machine learning approach for fake news detection using Scikitlearn

Awesome Lists containing this project

README

          

# ๐Ÿš€ Fake News Detection using ML + Generative AI

### ๐Ÿง  Detect fake vs. real news headlines and explain the reasoning using OpenAI GPT-4o-mini.

---

## ๐Ÿ—๏ธ Project Overview
This upgraded version of the classic Fake News Detection project adds an **LLM-powered explainability layer**.
Traditional ML models classify news articles, while **GPT-4o-mini** provides a human-readable justification of why an article is likely fake or real.

---

## โš™๏ธ Tech Stack

| Layer | Technology | Purpose |
|-------|-------------|----------|
| ๐Ÿงฉ Machine Learning | **Scikit-Learn** | Core fake/real classification |
| ๐Ÿง  Generative AI | **OpenAI GPT-4o-mini** | Natural-language explanations |
| ๐Ÿ’ป Frontend | **HTML + CSS** | Simple, responsive web interface |
| ๐ŸŒ Backend | **Flask** | Web app for serving predictions |
| ๐Ÿ’พ Storage | **joblib, pandas** | Model + dataset handling |

---

## ๐Ÿงฉ Features
- ๐Ÿ“ฐ Classifies news as **FAKE** or **REAL** using Passive Aggressive Classifier.
- ๐Ÿ” Generates **explanations** via GPT-4o-mini for every prediction.
- ๐ŸŒ Flask-based web app with an easy-to-use text input box.
- ๐Ÿ“ˆ Confusion matrix & accuracy summary available on `/metrics`.
- ๐Ÿงฑ Modular folder structure for quick extension or retraining.

---

## ๐Ÿ“ Folder Structure
```
Fake_News_Detection/
โ”‚
โ”œโ”€โ”€ app.py # Flask entry point
โ”œโ”€โ”€ requirements.txt # Dependencies
โ”œโ”€โ”€ model/
โ”‚ โ”œโ”€โ”€ fake_news_model.pkl # Trained PAC model
โ”‚ โ””โ”€โ”€ tfidf_vectorizer.pkl # TF-IDF vectorizer
โ”‚
โ”œโ”€โ”€ data/
โ”‚ โ””โ”€โ”€ news.csv # Dataset (Kaggle-style)
โ”‚
โ”œโ”€โ”€ utils/
โ”‚ โ”œโ”€โ”€ gpt_explainer.py # GPT-4o-mini text explanations
โ”‚ โ”œโ”€โ”€ model_loader.py # Load + predict helpers
โ”‚ โ””โ”€โ”€ preprocess.py # Text preprocessing utils
โ”‚
โ”œโ”€โ”€ templates/
โ”‚ โ””โ”€โ”€ index.html # Web interface
โ”‚
โ”œโ”€โ”€ static/
โ”‚ โ””โ”€โ”€ style.css # Styling
โ”‚
โ””โ”€โ”€ README.md
```

---

## ๐Ÿงฐ Setup Instructions

```bash
# 1๏ธโƒฃ Clone the repository
git clone https://github.com/ramarav/Fake_News_Detection.git
cd Fake_News_Detection

# 2๏ธโƒฃ Create a virtual environment
python -m venv venv
source venv/bin/activate # on Windows use venv\Scripts\activate

# 3๏ธโƒฃ Install dependencies
pip install -r requirements.txt

# 4๏ธโƒฃ Add your OpenAI API key (for explanations)
set OPENAI_API_KEY=your_api_key_here # Windows
export OPENAI_API_KEY=your_api_key_here # macOS/Linux

# 5๏ธโƒฃ Run Flask app
python app.py
```

Then open [http://localhost:5000](http://localhost:5000) ๐ŸŽฏ

---

## ๐Ÿงช Sample Output

| Input | Prediction | Explanation |
|--------|-------------|--------------|
| โ€œNASA confirms aliens discovered near Mars base.โ€ | **FAKE** | โ€œThis resembles tabloid-style unverifiable claims.โ€ |
| โ€œUN reports global hunger dropped by 10% in 2024.โ€ | **REAL** | โ€œThe phrasing and reference to official data suggest credibility.โ€ |

---

## ๐Ÿงฎ Model Performance
| Metric | Value |
|---------|--------|
| Accuracy | **93.13%** |
| Classifier | PassiveAggressiveClassifier |
| Vectorizer | TF-IDF (max_df=0.7, stop_words='english') |

---

## ๐Ÿท๏ธ Badges

![Python](https://img.shields.io/badge/Python-3.9%2B-blue.svg)
![Flask](https://img.shields.io/badge/Flask-2.x-green.svg)
![Scikit-Learn](https://img.shields.io/badge/ScikitLearn-1.5-orange.svg)
![OpenAI](https://img.shields.io/badge/OpenAI-GPT--4o--mini-purple.svg)
![License](https://img.shields.io/badge/License-MIT-lightgrey.svg)
![Contributions](https://img.shields.io/badge/Contributions-Welcome-brightgreen.svg)

---

## ๐Ÿ“ฆ API Endpoint Example

**POST** `/predict`
```bash
curl -X POST http://127.0.0.1:5000/predict -H "Content-Type: application/json" -d '{"text": "Breaking: New vaccine approved by WHO"}'
```

**Response:**
```json
{
"prediction": "REAL",
"explanation": "WHO approvals are verified through credible institutional sources."
}
```

---

## ๐Ÿ’ก Future Enhancements
- [ ] Integrate news source credibility scoring
- [ ] Add multilingual detection
- [ ] Deploy using Docker + Render
- [ ] Support voice-based input (Speech-to-Text)

---

## ๐Ÿ‘จโ€๐Ÿ’ป Author
**Mekala Ramarao**
AMD India
Focus: AI/ML applications in NLP, GPU analytics, and intelligent automation.
๐Ÿ“ง [LinkedIn](https://www.linkedin.com/in/mekala-ramarao-a2b5a562/)