Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

ML Fake News Classifier

[!Python](https://python.org) [!Scikit-learn](https://scikit-learn.org) [!NLTK](https://www.nltk.org) [!Pandas](https://pandas.pydata.org)

Overview

Machine learning classifier for detecting fake news articles using Natural Language Processing (NLP). Trained on labeled datasets to distinguish fact-based reporting from misinformation, using feature extraction and text classification techniques.

Key Features

  • Text Classification: Binary classifier (real/fake news)
  • NLP Pipeline: Tokenization, vectorization (TF-IDF), and feature engineering
  • Multiple Algorithms: Logistic Regression, Naive Bayes, Random Forest support
  • Model Evaluation: Precision, recall, F1-score, confusion matrix reporting
  • Serialized Models: Save/load trained classifiers for inference
  • Customizable Features: Adjustable stop words, n-grams, and vocabulary size
  • Web Integration Ready: Easy inference on new articles

Tech Stack

Language: Python 3.8+
ML Framework: Scikit-learn
NLP Tools: NLTK, TextBlob
Data Processing: Pandas, NumPy
Vectorization: TF-IDF (scikit-learn)
Evaluation: Cross-validation, classification metrics

Getting Started

Prerequisites

  • Python 3.8+
  • Scikit-learn, Pandas, NumPy, NLTK

Installation

git clone <repo-url>
cd ML-Fake-news-classifier

pip install -r requirements.txt
# Or manually:
pip install scikit-learn pandas numpy nltk textblob matplotlib

# Download NLTK data
python -m nltk.downloader punkt stopwords wordnet

Dataset

The model expects a CSV with columns:

  • text: Article body
  • label: 0 (real) or 1 (fake)

Example datasets:

  • Kaggle Fake and Real News Dataset
  • MediaEval Veracity Dataset

Training & Evaluation

# Train model on labeled dataset
python train.py --dataset news.csv --model logistic_regression --output model.pkl

# Evaluate on test set
python evaluate.py --model model.pkl --test_data test.csv

# Cross-validation
python train.py --dataset news.csv --cv 5

Usage

from classifier import load_model, predict

model = load_model('fake_news_classifier.pkl')
result = predict(model, "Article text here...")
print(f"Prediction: {'FAKE' if result == 1 else 'REAL'} (confidence: {confidence:.2%})")

Model Details

Preprocessing:

  • Lowercase conversion
  • Punctuation & special character removal
  • Stop word removal
  • Lemmatization

Vectorization: TF-IDF (max 5000 features, bigrams)

Algorithms:

  • Logistic Regression (baseline)
  • Multinomial Naive Bayes
  • Random Forest (ensemble)

Performance (typical):

  • Accuracy: 92–96%
  • Precision: 90–95%
  • Recall: 91–96%

Feature Importance

Top indicators of fake news:

  • Clickbait language patterns
  • Absence of source attribution
  • Emotional manipulation keywords
  • Unusual punctuation/capitalization

Limitations

  • Dataset bias (training data source affects generalization)
  • Context-dependent: satirical content may be misclassified
  • Language-specific: English-only training
  • Evolving tactics: New misinformation patterns require model retraining

License

[Add your license]

About

NLP-based fake news detection classifier using TF-IDF vectorization and ensemble ML models

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages