Fake News Detection Using Machine Learning: Project & Approach
Here is the pitch most fake news detection tutorials make: train a model, hit 95 percent accuracy, declare victory, and move on. Here is what actually happens when you present that project to an examiner or an interviewer: one question about why your model works, and the whole thing falls apart. Not because the code is wrong, but because the story around it is incomplete.
This guide builds the full pipeline the way it should be built. You will get the easy 95 percent with thirty lines of code using TF-IDF and Logistic Regression. Then you will learn exactly why that number flatters you, what it actually measures, and how to present it honestly. That is the difference between a project that gets a passing grade and one that gets you a job offer.
Fake news detection using machine learning is a text classification problem at its core. You take article text, extract features from it, and train a classifier to label it as real or fake. The techniques are the same ones used in sentiment analysis, spam filtering, and topic categorization. If you can build this, you can build any of those.
The Problem and the Approach (What ML Can and Can't Do Here)
Let us be clear about what we are building and what we are not. A machine learning model for fake news detection learns patterns in text that correlate with the labels in your training data. It learns that certain topics, writing styles, source patterns, and linguistic cues appear more often in articles labeled "fake" versus "real." It does not learn truth. It does not learn facts. It learns statistical correlations.
That distinction matters enormously for two reasons.
First, it tells you what the model is actually good at: flagging articles that share characteristics with previously seen fake news. An article with sensationalist language, unnamed sources, and a topic distribution matching known misinformation sources will get flagged. That is useful.
Second, it tells you where the model breaks: when fake news changes its style or covers new topics. A model trained on 2016 election misinformation will struggle with 2024 health misinformation because the vocabulary, topics, and writing patterns shifted. This is called temporal drift, and it is the reason no production fact-checking system relies solely on ML classification.
The approach we will follow is the standard NLP text classification pipeline, which you can explore in depth in the guide on text classification using scikit-learn:
- Clean and preprocess the text
- Convert text to numerical features (vectorization)
- Train baseline models
- Evaluate honestly
- Upgrade to deep learning if the baseline justifies it
- Deploy as a usable tool
Stop learning AI in fragments—master a structured AI Engineering Course with hands-on GenAI systems with IIT Roorkee CEC Certification
:::
Datasets: What to Train On
Your model is only as good as the data it learns from. Here are the three datasets most commonly used for this project, along with what each one is good for and where it falls short.
| Dataset | Size | Labels | Strengths | Known Biases |
|---|---|---|---|---|
| ISOT Fake News | ~44,000 articles (21,417 real, 23,481 fake) | Binary (real/fake) | Large, balanced, full article text | Topic-heavy (politics focus), source leakage risk |
| Kaggle Fake News | ~45,000 articles across train/test | Binary (real/fake) | Clean split, widely used, easy to benchmark | Similar political topic concentration |
| LIAR | ~12,800 short statements | 6-way (pants-fire to true) | Granular labels, diverse topics | Short statements only, not full articles |
Download guidance: The ISOT dataset is available through the University of Victoria. The Kaggle Fake News dataset is on Kaggle and includes the commonly used WELFake variant. LIAR is hosted by the UCSB NLP group.
The bias you must mention in your report: All three datasets have political topic concentration. If your model learns that articles about certain political topics are "fake" and others are "real," it is doing topic classification, not truth detection. This is the single most important caveat for your viva, and we will come back to it in the evaluation section.
Viva question: "Why might your model's high accuracy be misleading?" The answer starts with topic bias and source leakage, not with the accuracy number.
Steps 1–3: Preprocess and Vectorize (TF-IDF)
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Step 1: Text Cleaning
Raw news articles contain noise that does not help classification. Here is the standard preprocessing pipeline:
Important note for BERT: If you plan to upgrade to BERT later, use lighter preprocessing. BERT's tokenizer handles casing and punctuation, and heavy lemmatization can actually hurt its performance. Keep a raw and a cleaned version of your text column.
Step 2: Train-Test Split (Done Right)
This is where most tutorials introduce a bug. A random train-test split can leak information if the same news source appears in both sets. The model learns source-specific patterns rather than general fake-news indicators.
from sklearn.model_selection import train_test_split
For a more robust split, group by source if your dataset includes source information, and ensure no source appears in both train and test. This is the split an examiner will respect.
Step 3: TF-IDF Vectorization
TF-IDF (Term Frequency-Inverse Document Frequency) converts text into numerical features by scoring each word based on how often it appears in a document relative to how often it appears across all documents. Words that are common across all articles get low scores. Words that are distinctive get high scores.
from sklearn.feature_extraction.text import TfidfVectorizer
The ngram_range=(1, 2) captures phrases like "breaking news" and "sources say" which are more informative than individual words. The max_df=0.7 drops words that appear in more than 70 percent of documents (usually stopwords that slipped through).
Step 4: Baseline Models (Logistic Regression, Naive Bayes, PassiveAggressive)
This is the thirty-line win. Three classical models, all fast to train, all interpretable, and all strong baselines for text classification.
Logistic Regression
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, confusion_matrix
Typical result on ISOT: 93–95 percent accuracy. Logistic Regression is your best baseline because it is fast, interpretable (you can inspect the coefficients to see which TF-IDF features matter most), and hard to beat by a wide margin on clean text data.
Multinomial Naive Bayes
from sklearn.naive_bayes import MultinomialNB
Naive Bayes is the classic text classification algorithm. It assumes feature independence (the "naive" part) which is wrong for language but works surprisingly well in practice. The full Naive Bayes guide explains the math behind this. Expect 89–92 percent on ISOT, slightly below Logistic Regression.
PassiveAggressiveClassifier
from sklearn.linear_model import PassiveAggressiveClassifier
The PassiveAggressiveClassifier is designed for online learning and large text streams. It often matches or slightly exceeds Logistic Regression on fake news datasets, hitting 94–96 percent. It is less commonly used in tutorials, which makes it a good differentiator in your project.
Build classifier fundamentals in a structured way: Scaler's free Supervised Learning course walks through these models with hands-on exercises and mentor support.
Step 5: Evaluate Honestly
This is the section most tutorials skip, and it is the section that determines whether your project impresses or merely passes.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
The Metrics That Matter
from sklearn.metrics import confusion_matrix, classification_report
import matplotlib.pyplot as plt
import seaborn as sns
For fake news detection, precision and recall tell a more complete story than accuracy alone. The question you need to answer is: which error is worse?
- False positive (flagging real news as fake): Dangerous for press freedom, creates distrust in legitimate journalism
- False negative (letting fake news pass): Allows misinformation to spread unchecked
In most real-world deployments, false positives are considered worse because the cost of suppressing legitimate speech is higher than the cost of missing one piece of misinformation. This means you want high precision even at the cost of some recall. A model with 95 percent accuracy but 80 percent precision on the fake class is worse than a model with 92 percent accuracy and 95 percent precision.
For a deeper dive into choosing the right metrics, the evaluation metrics guide covers precision-recall tradeoffs across different problem types.
Why the 95 Percent Flatters You
Now the honesty part. Your Logistic Regression model hits 94 percent accuracy on the ISOT dataset. Impressive? Maybe. Here is why you should be skeptical.
Topic bias. The ISOT dataset contains a high concentration of political articles. Your model may have learned that articles about certain political figures or events are labeled "fake" and articles about others are labeled "real." Test this: filter your test set to only non-political articles. Watch the accuracy drop.
Source leakage. If the same news website appears in both your training and test sets, your model is partly memorizing source-level patterns (formatting, headline style, typical vocabulary) rather than learning generalizable fake-news indicators. A source-aware split (described in Step 2) usually drops accuracy by 5–10 percentage points.
Temporal drift. Train on articles from 2016–2018 and test on articles from 2023. The model's performance collapses because misinformation changes its style, topics, and distribution channels over time. Your model learned a snapshot, not a durable pattern.
Cross-dataset testing. The credibility move: train on ISOT, test on the Kaggle Fake News dataset. If your model still performs well, you have learned something generalizable. If it drops to 65–70 percent, you have learned dataset-specific patterns. Report both numbers.
Viva question: "Your model has 94 percent accuracy. What would happen if I tested it on news articles published after your training data?" The answer is about temporal drift, topic shift, and why production misinformation detection requires continuous retraining.
Upgrades: LSTM and BERT (With Real Deltas)
Once your baseline is solid and honestly evaluated, deep learning upgrades make sense. The key is to report what actually improves and what does not.
LSTM (Long Short-Term Memory)
An LSTM captures word order and sequential dependencies that TF-IDF ignores. The phrase "not true" and "true" have the same TF-IDF features (mostly) but opposite meanings. An LSTM handles this.
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding, LSTM, Dense, Dropout
Typical result: 94–96 percent on ISOT. The gain over Logistic Regression is often 1–2 percentage points, not the leap many tutorials claim. The LSTM's real advantage is interpretability of sequential patterns, not raw accuracy on these datasets.
For understanding how word representations feed into LSTMs, the word embeddings guide covers Word2Vec, GloVe, and learned embeddings.
BERT Fine-Tuning
BERT (Bidirectional Encoder Representations from Transformers) is the current state-of-the-art approach. It uses attention mechanisms to understand context bidirectionally, meaning "bank" in "river bank" versus "bank account" gets different representations.
from transformers import BertTokenizer, BertForSequenceClassification
from transformers import Trainer, TrainingArguments
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
# Tokenize in batches
train_encodings = tokenizer(
list(X_train[:5000]), truncation=True, padding=True, max_length=256
)
test_encodings = tokenizer(
list(X_test[:1000]), truncation=True, padding=True, max_length=256
)
model = BertForSequenceClassification.from_pretrained(
'bert-base-uncased', num_labels=2
)
BERT models are available through Hugging Face and can be fine-tuned in Google Colab with a free GPU. Use distilbert-base-uncased if memory is tight.
Typical result: 97–99 percent on ISOT and Kaggle datasets. BERT genuinely outperforms classical models on these benchmarks. But remember: the same topic bias and source leakage issues apply. BERT learns the same dataset shortcuts, just more effectively.
| Model | Accuracy (ISOT) | Accuracy (Cross-dataset) | Training Time | Interpretability |
|---|---|---|---|---|
| Logistic Regression + TF-IDF | 93–95% | 65–75% | Seconds | High (feature weights) |
| Naive Bayes + TF-IDF | 89–92% | 60–70% | Seconds | High |
| PassiveAggressive + TF-IDF | 94–96% | 65–75% | Seconds | Medium |
| LSTM | 94–96% | 68–78% | Minutes | Low |
| BERT (fine-tuned) | 97–99% | 70–80% | Hours | Very Low |
The cross-dataset column is the one that matters. Every model drops significantly when tested outside its training distribution. BERT drops less, but it still drops.
Viva question: "BERT gives 98 percent accuracy. Why not just use that?" The answer covers computational cost, interpretability tradeoffs, and the fact that the 2–3 percent gain over Logistic Regression may not justify a model that is 1000x more expensive to run and impossible to explain.
Turn Learning into Career Growth
Deploy It: Flask Interface
A model in a notebook is a homework assignment. A model behind a web interface is a project. Here is a minimal Flask app that takes article text and returns a prediction.
from flask import Flask, request, render_template
The index.html template is a simple form with a textarea for pasting article text. The result.html template shows the prediction and confidence score. Deploy to Heroku or Render for a public URL you can include in your portfolio.
This deployment is also a natural extension point. Add a confidence threshold (flag low-confidence predictions for human review), add batch processing for multiple articles, or integrate with a news API for real-time screening.
Viva and Interview Defense
If you are presenting this as a final-year project, these are the questions examiners ask and the answers that demonstrate real understanding.
"Why did you choose TF-IDF over word embeddings for the baseline?" TF-IDF is simpler, faster, interpretable, and performs within a few percentage points of deep learning on standard fake news datasets. It establishes a strong baseline that justifies the added complexity of LSTM or BERT.
"What are the limitations of your model?" The model learns dataset-specific patterns including topic bias and source-level features rather than generalizable truth indicators. It will degrade on new topics, new sources, and over time as misinformation evolves. Production deployment requires continuous retraining and human-in-the-loop verification.
"How would you improve this for a real deployment?" Cross-dataset training for generalization, source-aware data splitting to prevent leakage, a confidence threshold that routes uncertain predictions to human reviewers, and a retraining pipeline triggered by performance monitoring on fresh data.
"Is fake news detection an ethical problem?" Yes. Any automated classifier can be weaponized to suppress legitimate speech, and the definition of "fake" is itself politically contested. A responsible system flags content for human review rather than making final suppression decisions, and its training data and error rates must be transparent.
Where to Go Next
This project shares its core pipeline with other NLP classification tasks. Once you have this working, you can adapt it for:
- Sentiment analysis — same pipeline, different labels and datasets. The sentiment analysis guide covers the domain-specific differences.
- Fraud detection in text — detecting fraudulent reviews, phishing emails, or scam messages uses identical techniques. The fraud detection tutorial covers the class-imbalance challenges that make fraud detection distinct.
- Production NLP systems — if the deployment step interested you, explore MLOps practices for monitoring model drift in production text classifiers.
From class projects to production NLP: Scaler's AI and ML Program takes you beyond textbook implementations with mentor-led guidance on building ML systems that work in real-world conditions.
FAQs
Which algorithm is best for fake news detection in a project?
Logistic Regression or PassiveAggressiveClassifier with TF-IDF features is the best starting point, delivering 93–96 percent accuracy on standard datasets with minimal code and fast training times. BERT fine-tuning reaches 97–99 percent on benchmarks but costs significantly more in compute and training time. The right choice depends on your goal: a baseline for a college project favors the classical approach, while a portfolio piece showcasing modern NLP favors BERT.
Which dataset should I use for a fake news detection project?
The ISOT Fake News dataset (44,000 articles) and the Kaggle Fake News dataset are the standard choices for binary classification with full article text. LIAR is useful if you want multi-class labels and short-statement classification, but it is a fundamentally different problem. Whichever dataset you choose, document its known biases in your report, especially topic concentration and the risk of source leakage between train and test splits.
Why does my model accuracy drop when I test on a different dataset?
This is the expected behavior, not a bug in your code. Models trained on a specific fake news dataset learn patterns tied to that dataset's topics, time period, and sources. When tested on data from a different source or era, those patterns do not transfer. Cross-dataset evaluation is the honest way to measure generalization, and the drop from 95 percent to 65–75 percent tells you more about your model's real capability than the in-dataset number ever will.
Can I build a fake news detector without deep learning?
Yes, and you should start that way. TF-IDF with Logistic Regression or Naive Bayes gives you a strong baseline in under fifty lines of code, trains in seconds, and produces results within a few percentage points of deep learning models on standard benchmarks. Deep learning (LSTM, BERT) should be the upgrade layer that you compare against the baseline, not the starting point. Examiners and interviewers both respect candidates who establish baselines before reaching for complexity.
How do I make my fake news detection project stand out from others?
Three things separate an impressive project from a copied tutorial: honest evaluation that includes cross-dataset testing and a discussion of why high accuracy can be misleading, a deployed web interface that lets anyone test the model with new articles, and a clear comparison between classical and deep learning approaches with real numbers and honest tradeoffs. Most submissions have none of these three elements, so including even one puts you ahead of the majority.
What is the biggest mistake students make with this project?
The biggest mistake is presenting 95 percent accuracy as the conclusion rather than the starting point of the analysis. An examiner who asks "why is it 95 percent?" or "what would happen on new data?" will expose a student who has not interrogated their own results. The students who impress are the ones who can explain topic bias, temporal drift, and source leakage before the examiner even asks, because that self-critique demonstrates the analytical maturity that the project is actually designed to test.





