Fake News Detection Using Machine Learning
Complete academic documentation, project report and viva preparation. This page covers the problem statement, methodology, algorithms, results, advantages, future scope, UI design, learning outcomes and commonly asked viva questions with model answers.
1. Abstract
The rapid growth of online media has made it easy to publish and circulate misleading news, which can influence public opinion, damage reputations and even threaten public safety. Manual fact-checking cannot keep pace with the volume of content produced every day. This project presents an automated Fake News Detection System that uses Natural Language Processing and supervised Machine Learning to classify a news article or headline as REAL or FAKE.
News text is cleaned using NLP techniques (lowercasing, punctuation and URL removal, stop-word removal and stemming) and converted into numerical features using TF-IDF vectorization. Classification models — Logistic Regression, Multinomial Naive Bayes and Random Forest — are trained on the Kaggle Fake and Real News Dataset and compared using accuracy, precision, recall and F1-score. The best model achieves over 95% accuracy on the held-out test set. The trained model is serialised with joblib and deployed through a Flask REST API, with a responsive web interface where a user can paste news text and instantly receive the predicted label along with a confidence percentage.
2. Introduction
News is no longer consumed only through newspapers and television. Social networks, messaging apps and content aggregators deliver information instantly and without editorial control. This freedom has a cost: false or deliberately manipulated stories, commonly called fake news, spread faster and wider than verified reporting.
Machine Learning offers a practical solution. Fake and real news differ statistically — in vocabulary, sensationalism, punctuation and writing style. A supervised classifier trained on a large labelled corpus can learn these patterns and generalise to unseen articles. This project implements such a classifier end-to-end and packages it as an easy-to-use web application.
3. Problem Statement
There is no simple, accessible tool for an ordinary reader to check whether a news item is likely to be fabricated. Professional fact-checking is accurate but slow, manual and limited in coverage. The problem is therefore to design and implement an automated system that accepts free-form news text, analyses its linguistic content and returns a reliable REAL/FAKE classification with a measure of confidence, in real time and through a simple interface.
4. Objectives
Study existing approaches for automated misinformation detection.
Collect and prepare a balanced dataset of real and fake news articles.
Apply NLP preprocessing for noise removal and normalisation.
Extract features using the TF-IDF weighting scheme.
Train and compare Logistic Regression, Naive Bayes and Random Forest classifiers.
Evaluate models with accuracy, precision, recall, F1-score and a confusion matrix.
Persist the best model and expose it through a Flask REST API.
Design a responsive, validated web interface that reports the prediction and confidence.
5. Existing System
Current practice relies mainly on manual verification by journalists and fact-checking organisations, and on platform-level moderation such as user reporting and blacklists of known unreliable domains.
- Manual verification is slow and cannot scale to millions of daily posts.
- Source-based blacklists fail when false content is published on new or credible-looking domains.
- Keyword filters are rigid and easily bypassed by rewording.
- Results are not available to the reader at the moment of reading.
- Human judgement can be inconsistent or biased.
6. Proposed System
The proposed system automates detection using content-based machine learning. The user pastes a news article or headline into a web page and clicks Check News. The backend cleans the text, converts it into a TF-IDF feature vector using the vectorizer fitted at training time, and passes it to the trained classifier, which outputs a class label together with a probability. The result and its confidence are displayed immediately, and the query is logged into a database.
- Analyses the content itself, not just the source.
- Instant, real-time prediction through a REST API.
- Gives a confidence score instead of a bare yes/no.
- Retrainable — accuracy improves as more data is added.
- Lightweight, runs on ordinary hardware without a GPU.
7. System Requirements
Hardware
Intel i3 or higher, 4 GB RAM (8 GB recommended), 2 GB free disk space.
Operating System
Windows 10/11, Linux or macOS with a modern browser.
Development Tools
Python 3.9+, pip, VS Code / PyCharm, Git.
Python Libraries
pandas, numpy, scikit-learn, nltk, flask, flask-cors, joblib, matplotlib, seaborn.
Frontend Stack
HTML5, CSS3, JavaScript / React for the interactive demo.
Database
SQLite 3 (bundled with Python) for prediction logging.
8. Methodology
The project follows the standard supervised learning workflow, from raw text to a deployed classifier.
Data Collection
True.csv and Fake.csv from the Kaggle Fake and Real News Dataset, ~44,898 rows in total.
Labelling & Merging
real = 0, fake = 1; the two frames are concatenated and shuffled for unbiased training.
Text Preprocessing
Lowercasing, URL/HTML/punctuation/digit removal, tokenization, stop-word removal and Porter stemming.
Feature Extraction
TfidfVectorizer(stop_words='english', max_df=0.7) builds a sparse weighted term-document matrix.
Train-Test Split
80% training / 20% testing with stratify=y and random_state=42 for reproducibility.
Model Training
Logistic Regression, Multinomial Naive Bayes and Random Forest are fitted on the training matrix.
Evaluation
accuracy_score, classification_report and confusion_matrix; graphs plotted with matplotlib and seaborn.
Deployment
The best model and fitted vectorizer are saved with joblib and loaded once by the Flask application.
9. Algorithms Used
TF-IDF Vectorization
Weights each term by its frequency in a document and rarity across the corpus. Common words are down-weighted while discriminative words dominate, producing a high-dimensional sparse feature matrix ideal for text classification.
Logistic Regression
Models P(fake | x) = sigmoid(w·x + b). It is linear, fast, interpretable and works extremely well on sparse TF-IDF features, making it the primary classifier of this project.
Multinomial Naive Bayes
Applies Bayes' theorem with a conditional independence assumption. Extremely fast to train and a strong baseline for text classification tasks.
Random Forest
An ensemble of decision trees using bagging and random feature selection. It captures non-linear interactions and reduces overfitting while serving as a comparison model.
10. Results
On the full Kaggle dataset with an 80:20 stratified split, Logistic Regression reached approximately 96% accuracy, Multinomial Naive Bayes approximately 93%, and Random Forest approximately 96%. Precision, recall and F1-score for the FAKE class all stayed above 0.93 for the best model, and the confusion matrix showed a small and balanced number of false positives and false negatives.
The Model & Results page of this application recomputes the same metrics live on the bundled demo sample, so the accuracy, precision, recall, F1-score, confusion matrix and feature importances shown there are genuine outputs of the trained model, not static images.
11. Advantages
Fully Automated
Available 24×7 with sub-second response time and no manual intervention.
Content-Based
Analyses the article text itself, so it works even for unknown publishers.
Explainable
Returns a confidence percentage and highlights the words that influenced the decision.
Student Friendly
Simple, interpretable model that a student can explain line by line during a viva.
Lightweight
Runs on ordinary hardware without a GPU or paid cloud service.
Modular
Clean separation of preprocessing, feature extraction, training and deployment.
12. Future Scope & Enhancements
The current system is a strong, interpretable baseline. The following enhancements can extend its reach and accuracy even further:
Fine-tune contextual deep learning models such as LSTM, GRU or BERT for richer semantic understanding.
Add multilingual support, especially regional Indian languages, to broaden usability.
Integrate live fact-checking APIs and source-credibility scoring for layered verification.
Provide a browser extension and a mobile application for instant on-the-go checks.
Automatically fetch and analyse an article from a pasted URL.
Add an admin dashboard with prediction history, analytics and feedback-driven retraining.
13. 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.
14. Screenshots & UI Design
The user interface is designed to be clean, responsive and self-explanatory so that any visitor can use the detector without training. Key screens are described below.
Home / Detector
A clean, centred textarea with sample inputs, validation and a prominent Check News button.
Prediction Result Card
Displays REAL or FAKE label, confidence bar, P(fake) score and the most influential words.
Model & Results Page
Live metrics, algorithm comparison chart, confusion matrix and top TF-IDF feature weights.
About Project Page
Architecture diagram, technology stack, modules and folder structure for academic review.
Project Report Page
Full academic documentation with accordion-style viva questions and answers.
Flask Reference API
Python backend exposing POST /api/predict and GET /api/history with SQLite logging.
15. Conclusion
This project successfully demonstrates that fake news can be detected automatically with high accuracy using classical Natural Language Processing and Machine Learning. TF-IDF vectorization combined with Logistic Regression provides an excellent balance of accuracy, speed and interpretability, achieving around 96% test accuracy. Wrapping the trained model in a Flask REST API and a responsive web interface turns the model into a usable product rather than a notebook experiment.
The system is designed as a first line of defence that helps readers pause before believing and sharing suspicious content. Its modular architecture makes it straightforward to extend the work with deep learning models, multilingual data and live verification services.
16. References
- Shu, K., Sliva, A., Wang, S., Tang, J., & Liu, H. (2017). Fake News Detection on Social Media: A Data Mining Perspective. ACM SIGKDD Explorations Newsletter.
- Ahmed, H., Traore, I., & Saad, S. (2017). Detection of Online Fake News Using N-Gram Analysis and Machine Learning Techniques.
- Kaggle: Clément Bisaillon, Fake and Real News Dataset — kaggle.com/datasets/clmentbisaillon/fake-and-real-news-dataset
- Pedregosa, F. et al. (2011). Scikit-learn: Machine Learning in Python. JMLR 12, 2825–2830.
- Bird, S., Klein, E., & Loper, E. (2009). Natural Language Processing with Python (NLTK). O'Reilly Media.
- Flask Documentation — flask.palletsprojects.com
- Jurafsky, D. & Martin, J. H. Speech and Language Processing, 3rd edition draft.
Viva Questions & Answers
22 commonly asked questions with model answers.