A machine learning-based NLP project that classifies news articles as Real or Fake using the WELFake dataset. The project covers text preprocessing, TF-IDF feature extraction, multiple classification models, and model evaluation.
The objective is to automatically classify news articles into two categories:
0— Real News1— Fake News
The project combines the title and article text into a single content feature and uses traditional machine learning techniques for text classification.
The project uses the WELFake dataset, containing approximately 72,000 news articles with real/fake labels.
The dataset is relatively balanced:
- Real News: ~48.6%
- Fake News: ~51.4%
Dataset
↓
Data Cleaning & EDA
↓
Combine Title + Text
↓
Text Preprocessing
↓
Train/Test Split
↓
TF-IDF Feature Extraction
↓
Model Training
├── Logistic Regression
├── Multinomial Naive Bayes
└── Random Forest
↓
Model Evaluation & Comparison
The text preprocessing pipeline includes:
- Handling missing values
- Combining title and article text
- Removing non-alphabetic characters using regular expressions
- Converting text to lowercase
- Tokenization using
split() - Stopword removal
- Lemmatization using
WordNetLemmatizer
EDA was performed to understand:
- Class distribution
- Missing values
- Text/title length patterns
- Important textual patterns
The processed text is converted into numerical features using TF-IDF (Term Frequency-Inverse Document Frequency).
Configuration:
TfidfVectorizer(
max_features=5000,
min_df=2,
max_df=0.8,
ngram_range=(1, 2)
)This uses up to 5,000 features, including both unigrams and bigrams.
To avoid data leakage, the vectorizer is fitted only on the training data and then used to transform the test data:
X_train = tfidf.fit_transform(X_train_text)
X_test = tfidf.transform(X_test_text)Used as a strong baseline for high-dimensional TF-IDF text features.
Test Accuracy: 94.68%
Used as a traditional and computationally efficient text-classification baseline.
It performed lower than Logistic Regression on the test set.
Used to evaluate whether an ensemble tree-based model could improve classification performance.
Test Accuracy: 95.42%
Random Forest achieved the best test accuracy among the evaluated models.
| Model | Test Accuracy |
|---|---|
| Logistic Regression | 94.68% |
| Multinomial Naive Bayes | Lower than Logistic Regression |
| Random Forest | 95.42% |
| Class | Precision | Recall | F1-Score |
|---|---|---|---|
| Real | 0.97 | 0.93 | 0.95 |
| Fake | 0.94 | 0.98 | 0.96 |
The Random Forest model achieved 98% recall for fake news, meaning it correctly identified approximately 98% of the fake articles in the test set.
Predicted
Real Fake
Actual Real 9796 713
Fake 278 10854
- TF-IDF provided an effective numerical representation of the news articles.
- Logistic Regression achieved strong performance with a 94.68% test accuracy.
- Multinomial Naive Bayes performed below Logistic Regression.
- Random Forest achieved the best test accuracy at 95.42%.
- Random Forest achieved 98% recall for fake news and a 0.96 F1-score for the fake class.
- The higher Random Forest training accuracy (~99.33%) compared with test accuracy indicates some overfitting.
- Python
- Pandas
- NumPy
- NLTK
- Scikit-learn
- Matplotlib
- Seaborn
- TF-IDF
- Logistic Regression
- Multinomial Naive Bayes
- Random Forest
- Hyperparameter tuning and cross-validation
- Testing Linear SVM and other classifiers
- Experimenting with Word2Vec or other embeddings
- Fine-tuning transformer models such as BERT
- Evaluating performance on completely unseen news sources
- Monitoring concept drift as news topics and writing patterns change
This project demonstrates an end-to-end NLP classification workflow, from data cleaning and exploratory analysis to text preprocessing, TF-IDF feature engineering, model training, and evaluation. Among the evaluated models, Random Forest achieved the strongest test performance with 95.42% accuracy and 98% recall for fake news.