Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📰 NewsLens – Fake News Detector

A full‑stack system that analyzes news articles to estimate whether content is likely real or fake using an NLP pipeline and machine learning.

Home Page

📚 Table of Contents


Overview

Input

  • News title & body text or a source URL to scrape.

Processing

  • Clean & lemmatize text
  • Vectorize with TF‑IDF
  • Classify using a trained ML model

Output

  • label: real | fake
  • confidence: probability score

All predictions are stored in MongoDB for history and analytics.

Output Analytics

Features

  • 🎨 Responsive React UI with a polished dark theme

  • 🔗 URL scraping using Axios + Cheerio

  • ⚡ Real‑time classification (Node → Python subprocess)

  • 🗂 Persistent prediction history (MongoDB)

  • 📊 Analytics dashboard:

    • Total predictions
    • Real/Fake ratio
    • Average confidence
    • Confidence histogram
    • Top source domains
  • 🚀 One‑command setup to install and run everything

  • 🔁 Retraining endpoint to rebuild the model from CSV


Tech Stack

Frontend

  • React
  • Vite
  • Tailwind CSS
  • Framer Motion
  • lucide‑react icons

Backend

  • Node.js
  • Express
  • Axios
  • Cheerio
  • MongoDB (native driver)

Machine Learning

  • Python
  • scikit‑learn
  • NLTK
  • joblib

Architecture & Flow

Architecture Diagram


---

## Project Structure

NewsLens/ ├─ client/ # React frontend │ ├─ pages/ │ │ ├─ Input (/) │ │ ├─ Result (/result) │ │ └─ Analytics (/analytics) │ ├─ server/ # Express backend │ ├─ index.js │ └─ routes/ │ ├─ predict.js │ ├─ history.js │ ├─ analytics.js │ ├─ retrain.js │ └─ health.js │ ├─ model/ # Python ML pipeline │ ├─ src/ │ │ ├─ preprocess.py │ │ ├─ train.py │ │ └─ predict.py │ ├─ saved_models/ │ │ ├─ model.pkl │ │ ├─ vectorizer.pkl │ │ └─ metrics.json │ └─ requirements.txt │ └─ README.md


---

## Requirements

* **Node.js** ≥ 18
* **npm**
* **Python** ≥ 3.9
* **pip**
* **MongoDB** (local or remote)

---

## Setup & Run

From the project root:

```bash
npm start

This command will:

  • Install frontend & backend dependencies

  • Install Python requirements from model/requirements.txt

  • Start:

    • Backend → http://localhost:3001
    • Frontend → http://localhost:5173

Configuration

Environment variables (optional):

MONGO_URI=mongodb://127.0.0.1:27017/NewsLens
MONGO_DB=NewsLens
WELFAKE_CSV=WELFake_Dataset.csv

API Reference

POST /predict

Body

{
  "title": "optional",
  "text": "optional",
  "url": "optional"
}

Response

{
  "status": "ok",
  "label": "real | fake",
  "confidence": 0.93
}

GET /history?limit=50&skip=0

{
  "status": "ok",
  "items": [ { "input": {}, "result": {}, "ts": 0, "domain": "" } ]
}

GET /analytics

{
  "status": "ok",
  "totals": {},
  "time": {},
  "top_domains": [],
  "confidence_hist": []
}

POST /retrain

{
  "status": "ok",
  "best_model": "LogisticRegression",
  "metrics": {}
}

GET /health

{ "status": "ok" }

Data Model

history collection

{
  "input": { "title": "...", "url": "...", "text": "..." },
  "result": { "label": "real|fake", "confidence": 0.93 },
  "ts": 1736450000000,
  "domain": "example.com"
}

analytics document

{
  "_id": "global",
  "total": 120,
  "real": 78,
  "fake": 42,
  "sumConfidence": 98.5,
  "updatedAt": "2026-01-09T16:05:00Z"
}

Model & Preprocessing

  • Label mapping: 0 → real, 1 → fake

  • Text preprocessing:

    • Lowercasing
    • HTML & URL removal
    • Non‑alphabetic filtering
    • Stop‑word removal
    • Lemmatization (WordNet)
  • Vectorization:

    • TF‑IDF (uni‑grams & bi‑grams)
    • max_features = 50000
    • min_df = 2
    • max_df = 0.95
  • Models evaluated:

    • Multinomial Naive Bayes
    • Logistic Regression
  • Model selection: Best F1 score wins

Artifacts are saved in model/saved_models/ and loaded at inference time.


Retraining Workflow

  • Call POST /retrain or run:
python model/src/train.py
  • Ensure WELFAKE_CSV points to the dataset
  • New artifacts overwrite old ones
  • All future predictions use the updated model

Troubleshooting

  • pip install errors:

    python -m pip install -r model/requirements.txt
  • MongoDB connection issues:

    • Verify MongoDB is running
    • Check MONGO_URI
  • NLTK WordNet missing:

    nltk.download('wordnet')
  • CORS issues:

    • CORS is enabled by default in server/index.js

Security & Production Notes

  • Enable HTTPS
  • Add authentication & rate limiting
  • Redact or hash sensitive text before storage
  • Use managed MongoDB (Atlas) in production
  • Store secrets using environment variables

🚀 NewsLens — turning misinformation into insight.

About

Fake News Detection System - A full‑stack system that analyzes news articles to estimate whether content is likely **real** or **fake** using an NLP pipeline and machine learning.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages