Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fake News Detection Using NLP

Built a classifier to detect whether a news article is fake or real using NLP. Trained on the Kaggle Fake and Real News dataset (~44k articles). Used TF-IDF features with two classifiers — Logistic Regression as a baseline and Linear SVM which gave better results.

Results

Model Accuracy AUC
TF-IDF + Logistic Regression 99.4% 0.9998
TF-IDF + Linear SVM 99.64% 0.9999

Model Comparison

Confusion Matrices

Logistic Regression SVM

ROC Curves

Logistic Regression SVM

Dataset

Fake and Real News Dataset from Kaggle — 23,481 fake + 21,417 real articles with title, text, subject, date.

How to run

# install deps
pip install -r requirements.txt

# download dataset (needs kaggle API key at ~/.kaggle/kaggle.json)
python setup_data.py

# run full pipeline
python main.py

To predict on your own text:

python src/predict.py --model tfidf --text "your article text here"
python src/predict.py --model svm --text "your article text here"

Project structure

├── data/           # raw CSVs (not in git, download separately)
├── models/         # saved model files
├── notebooks/      # EDA notebook
├── outputs/        # plots
├── src/
│   ├── preprocess.py
│   ├── train_tfidf.py
│   ├── train_lstm.py   # SVM model
│   └── predict.py
└── main.py

What I did

  • Combined title + text fields, lowercased, removed URLs/punctuation, stopwords, lemmatized
  • TF-IDF vectorization with unigrams and bigrams
  • Tried Logistic Regression first (fast, interpretable), then SVM which got slightly better accuracy
  • Evaluated with confusion matrix, classification report, and ROC curves

Libraries used

  • scikit-learn, NLTK, pandas, numpy, matplotlib, seaborn

About

End to end NLP pipeline for fake news detection using TF-IDF, Logistic Regression, and Linear SVM with comprehensive evaluation and visualization.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages