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.
| Model | Accuracy | AUC |
|---|---|---|
| TF-IDF + Logistic Regression | 99.4% | 0.9998 |
| TF-IDF + Linear SVM | 99.64% | 0.9999 |
| Logistic Regression | SVM |
|---|---|
![]() |
![]() |
| Logistic Regression | SVM |
|---|---|
![]() |
![]() |
Fake and Real News Dataset from Kaggle — 23,481 fake + 21,417 real articles with title, text, subject, date.
# 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.pyTo 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"├── 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
- 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
- scikit-learn, NLTK, pandas, numpy, matplotlib, seaborn




