[!Python](https://python.org) [!Scikit-learn](https://scikit-learn.org) [!NLTK](https://www.nltk.org) [!Pandas](https://pandas.pydata.org)
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.
- 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
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
- Python 3.8+
- Scikit-learn, Pandas, NumPy, NLTK
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 wordnetThe model expects a CSV with columns:
text: Article bodylabel: 0 (real) or 1 (fake)
Example datasets:
- Kaggle Fake and Real News Dataset
- MediaEval Veracity Dataset
# 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 5from 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%})")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%
Top indicators of fake news:
- Clickbait language patterns
- Absence of source attribution
- Emotional manipulation keywords
- Unusual punctuation/capitalization
- 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
[Add your license]