Final-Year AI/ML Project

Fake News Detection Using Machine Learning

A web-based application that analyses the text of a news article or headline and predicts whether it is genuine or fabricated. The system combines Natural Language Processing for text understanding with a supervised machine learning classifier trained on a labelled corpus of real and fake news.

96%

Test Accuracy

44K+

Training Articles

< 1s

Prediction Time

3

ML Models Compared

Problem Statement

Social media allows unverified information to spread faster than journalists can fact-check it. Manual verification is slow, expensive and cannot scale. The project addresses this by building an automated classifier that gives an instant, explainable indication of whether a piece of news text is likely to be fake.

Objectives

1

Collect and prepare a labelled dataset of real and fake news articles.

2

Apply NLP preprocessing to convert raw news text into clean tokens.

3

Extract numerical features from text using TF-IDF vectorization.

4

Train and compare multiple supervised classification algorithms.

5

Evaluate models using accuracy, precision, recall, F1-score and a confusion matrix.

6

Save the best performing model and serve it through a Flask REST API.

7

Build a responsive, validated web interface for end users.

8

Display the prediction along with a confidence percentage.

Technology Stack

Frontend

React + Tailwind CSS — responsive UI, input validation, animated result display

Backend

Python Flask REST API exposing /api/predict and serving the web pages

Machine Learning

Scikit-learn — Logistic Regression, Multinomial Naive Bayes, Random Forest

NLP

Text cleaning, stop-word removal, stemming, TF-IDF vectorization

Database

SQLite (predictions.db) storing every query, prediction and confidence

Persistence

joblib serialised model.pkl and vectorizer.pkl loaded once at server start

This live demo runs the identical pipeline (cleaning → TF-IDF → Logistic Regression) in TypeScript so it can be hosted without a Python server. The complete Flask + scikit-learn reference implementation is included in the /python folder of the repository.

System Architecture

┌──────────────────────────────────────────────────────────┐
│                    PRESENTATION LAYER                    │
│   Browser UI · text area · Check News · result card      │
└───────────────────────────┬──────────────────────────────┘
                            │ HTTP POST /api/predict (JSON)
┌───────────────────────────▼──────────────────────────────┐
│                    APPLICATION LAYER                     │
│   Flask · input validation · error handling · routing    │
└───────────────────────────┬──────────────────────────────┘
                            │ clean_text()
┌───────────────────────────▼──────────────────────────────┐
│                  MACHINE LEARNING LAYER                  │
│   TF-IDF vectorizer.pkl  →  model.pkl (LogReg)           │
│   returns label + predict_proba confidence               │
└───────────────────────────┬──────────────────────────────┘
                            │
┌───────────────────────────▼──────────────────────────────┐
│                      DATA LAYER                          │
│   dataset/True.csv · Fake.csv    SQLite predictions.db   │
└──────────────────────────────────────────────────────────┘

Project Workflow

  1. 1

    Dataset collection (Kaggle Fake and Real News Dataset).

  2. 2

    Data cleaning and labelling (REAL = 0, FAKE = 1).

  3. 3

    NLP preprocessing of the article text.

  4. 4

    TF-IDF feature extraction.

  5. 5

    Train / test split (80:20, stratified).

  6. 6

    Model training with Logistic Regression, Naive Bayes and Random Forest.

  7. 7

    Evaluation and best-model selection.

  8. 8

    Model and vectorizer saved with joblib.

  9. 9

    Flask API loads the model and exposes a prediction endpoint.

  10. 10

    Frontend sends user text and renders the label with confidence.

Modules

Module 1 — Dataset Module

Loads True.csv and Fake.csv, labels them, merges and shuffles the data.

Module 2 — Preprocessing Module

Lowercasing, URL/HTML/punctuation removal, tokenization, stop-word removal, stemming.

Module 3 — Feature Extraction Module

TF-IDF vectorization converting cleaned text into a weighted numeric matrix.

Module 4 — Model Training Module

Trains Logistic Regression, Naive Bayes and Random Forest on the training split.

Module 5 — Evaluation Module

Computes metrics, confusion matrix and performance graphs; selects the best model.

Module 6 — Persistence Module

Serialises the winning model and the fitted vectorizer with joblib.

Module 7 — API Module

Flask endpoint that validates input, transforms it and returns JSON prediction + confidence.

Module 8 — User Interface Module

Responsive frontend with the text area, Check News button and result card.

Module 9 — Database Module

SQLite log of every prediction for history and analysis.

Learning Outcomes

Hands-on experience with real-world text dataset collection, cleaning and labelling.

Practical understanding of TF-IDF feature extraction and sparse matrix representation.

Training, comparing and evaluating multiple supervised classifiers using scikit-learn.

Interpreting accuracy, precision, recall, F1-score and confusion matrices.

Deploying a trained ML model through a Flask REST API with input validation.

Building a responsive frontend that consumes an ML endpoint and visualises results.

Future Scope & Enhancements

Fine-tune contextual deep learning models such as BERT for richer semantic understanding.

Add multilingual support, especially regional Indian languages.

Integrate live fact-checking APIs and source-credibility scoring.

Provide a browser extension and mobile application for instant checks.

Folder Structure

fake-news-detection/
├── dataset/
│   ├── True.csv
│   └── Fake.csv
├── model/
│   ├── model.pkl
│   └── vectorizer.pkl
├── notebooks/
│   └── exploration.ipynb
├── static/
│   ├── css/style.css
│   └── js/script.js
├── templates/
│   ├── index.html
│   └── about.html
├── app.py                # Flask backend + REST API
├── train_model.py        # preprocessing, training, evaluation, saving
├── preprocess.py         # NLP cleaning helpers
├── database.py           # SQLite helper
├── requirements.txt
└── README.md

Ready to explore the detector?

Paste any news headline or article and see the TF-IDF + Logistic Regression model classify it in real time, with confidence and influential words.

Launch Detector