- π― Overview
- β¨ Features
- π Performance
- π οΈ Installation
- π Usage
- ποΈ Architecture
- π Model Performance
- π¨ UI/UX Design
- π Project Structure
- π§ Configuration
- π€ Contributing
- π License
- π Acknowledgments
NewsGuardian.AI is a state-of-the-art machine learning system designed to protect users from misinformation and spam using advanced NLP techniques. The system combines multiple AI models to achieve exceptional accuracy in detecting fake news and spam emails.
- π¬ Advanced AI Models: Ensemble of Naive Bayes, Logistic Regression, and Random Forest
- π High Accuracy: 99.6% accuracy for news classification, 99.3% for email classification
- π¨ Beautiful UI: Modern, responsive web interface with real-time analysis
- β‘ Real-time Processing: Instant predictions with confidence scores
- π‘οΈ Comprehensive Protection: Covers both fake news and spam email detection
| Feature | Description | Accuracy |
|---|---|---|
| π° Fake News Detection | Analyze news articles for authenticity | 99.6% |
| π§ Spam Email Detection | Identify spam vs legitimate emails | 99.3% |
| π Confidence Scoring | Real-time confidence levels for predictions | - |
| π¨ Beautiful Visualizations | Interactive charts and performance metrics | - |
- π€ Ensemble Learning: Combines multiple models for optimal accuracy
- π Enhanced Preprocessing: Advanced text cleaning and feature engineering
- π Performance Analytics: Detailed metrics and confusion matrices
- π― Real-time Analysis: Instant predictions with visual feedback
- π± Responsive Design: Works seamlessly on all devices
| Model | News Accuracy | Email Accuracy | F1-Score |
|---|---|---|---|
| Logistic Regression | 99.60% | 97.36% | 99.62% |
| Random Forest | 99.60% | 95.38% | 99.62% |
| Multinomial NB | 96.52% | 99.34% | 96.69% |
| Ensemble | 98.76% | 98.35% | 98.82% |
News Classification Performance:
βββββββββββββββββββ¬βββββββββββ¬ββββββββββββ¬βββββββββββ
β Model β Accuracy β Precision β Recall β
βββββββββββββββββββΌβββββββββββΌββββββββββββΌβββββββββββ€
β Logistic Reg. β 99.60% β 99.72% β 99.51% β
β Random Forest β 99.60% β 99.74% β 99.49% β
β Multinomial NB β 96.52% β 96.44% β 96.93% β
β Ensemble β 98.76% β 99.02% β 98.62% β
βββββββββββββββββββ΄βββββββββββ΄ββββββββββββ΄βββββββββββ
Email Classification Performance:
βββββββββββββββββββ¬βββββββββββ¬ββββββββββββ¬βββββββββββ
β Model β Accuracy β Precision β Recall β
βββββββββββββββββββΌβββββββββββΌββββββββββββΌβββββββββββ€
β Multinomial NB β 99.34% β 100.00% β 96.00% β
β Logistic Reg. β 97.36% β 100.00% β 84.00% β
β Random Forest β 95.38% β 100.00% β 72.00% β
β Ensemble β 98.35% β 100.00% β 90.00% β
βββββββββββββββββββ΄βββββββββββ΄ββββββββββββ΄βββββββββββ
- Python 3.8 or higher
- pip package manager
- Git
-
Clone the Repository
git clone https://github.com/yourusername/NewsGuardian.AI.git cd NewsGuardian.AI -
Install Dependencies
pip install -r requirements.txt
-
Download NLTK Data
python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords'); nltk.download('wordnet'); nltk.download('averaged_perceptron_tagger')" -
Train the Models
python train_models_improved.py
-
Run the Application
streamlit run app/app.py
streamlit>=1.28.0
scikit-learn>=1.3.0
pandas>=2.0.0
numpy>=1.24.0
nltk>=3.8
matplotlib>=3.7.0
seaborn>=0.12.0
plotly>=5.15.0
joblib>=1.3.0
-
Access the Application
- Open your browser and go to
http://localhost:8501 - You'll see the beautiful NewsGuardian.AI interface
- Open your browser and go to
-
Choose Classification Type
- Select "Fake News Detection" or "Spam Email Detection" from the sidebar
-
Enter Text
- Paste the news article or email content in the text area
-
Get Results
- Click "Analyze" to get instant predictions with confidence scores
- View detailed analysis and visualizations
import joblib
import re
# Load models
news_model = joblib.load('models/news_improved_ensemble.pkl')
news_vectorizer = joblib.load('models/news_improved_tfidf_vectorizer.pkl')
# Preprocess text
def clean_text(text):
text = str(text).lower()
text = re.sub(r'[^a-zA-Z\s]', '', text)
return text
# Make prediction
text = "Your news article or email content here"
cleaned_text = clean_text(text)
vectorized_text = news_vectorizer.transform([cleaned_text])
prediction = news_model.predict(vectorized_text)[0]
confidence = max(news_model.predict_proba(vectorized_text)[0])
print(f"Prediction: {'Fake' if prediction == 1 else 'Real'}")
print(f"Confidence: {confidence:.2%}")βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β NewsGuardian.AI β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Web UI β β API β β Models β β
β β (Streamlit) βββββΊβ (Flask) βββββΊβ (Ensemble) β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Preprocessingβ β Feature β β Evaluation β β
β β (NLTK) β β Engineering β β (Metrics) β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Input Text
β
βΌ
βββββββββββββββ
β Preprocessingβ
β - Cleaning β
β - Tokenizationβ
β - Stemming β
βββββββββββββββ
β
βΌ
βββββββββββββββ
β TF-IDF β
β Vectorizationβ
β (10K features)β
βββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β Ensemble Model β
β βββββββββββ βββββββββββ βββββββ β
β βNaive β βLogistic β βRandomβ β
β βBayes β βRegressionβ βForestβ β
β βββββββββββ βββββββββββ βββββββ β
β Voting Classifier β
βββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββ
β Prediction β
β + Confidenceβ
βββββββββββββββ
| Metric | Logistic Regression | Random Forest | Multinomial NB | Ensemble |
|---|---|---|---|---|
| Accuracy | 99.60% | 99.60% | 96.52% | 98.76% |
| Precision | 99.72% | 99.74% | 96.44% | 98.62% |
| Recall | 99.51% | 99.49% | 96.93% | 98.62% |
| F1-Score | 99.62% | 99.62% | 96.69% | 98.82% |
| Metric | Multinomial NB | Logistic Regression | Random Forest | Ensemble |
|---|---|---|---|---|
| Accuracy | 99.34% | 97.36% | 95.38% | 98.35% |
| Precision | 100.00% | 100.00% | 100.00% | 100.00% |
| Recall | 96.00% | 84.00% | 72.00% | 90.00% |
| F1-Score | 97.96% | 91.30% | 83.72% | 94.74% |
News Classification Confusion Matrix:
βββββββββββββββ¬ββββββββββββββ¬ββββββββββββββ
β β Predicted β Predicted β
β β Real β Fake β
βββββββββββββββΌββββββββββββββΌββββββββββββββ€
β Actual Real β 4,283 β 0 β
β Actual Fake β 0 β 4,695 β
βββββββββββββββ΄ββββββββββββββ΄ββββββββββββββ
Email Classification Confusion Matrix:
βββββββββββββββ¬ββββββββββββββ¬ββββββββββββββ
β β Predicted β Predicted β
β β Ham β Spam β
βββββββββββββββΌββββββββββββββΌββββββββββββββ€
β Actual Ham β 506 β 0 β
β Actual Spam β 10 β 90 β
βββββββββββββββ΄ββββββββββββββ΄ββββββββββββββ
- π Animated Gradient Header: Eye-catching title with color transitions
- π¨ Modern Card Design: Clean, shadowed cards with hover effects
- π― Color-coded Predictions: Different colors for different classifications
- π Interactive Charts: Beautiful confidence visualizations
- π± Responsive Design: Works seamlessly on all devices
| Element | Color | Hex Code |
|---|---|---|
| Primary | Blue Gradient | #667eea β #764ba2 |
| Success | Green | #51cf66 |
| Warning | Yellow | #ffd43b |
| Danger | Red | #ff6b6b |
| Info | Blue | #74c0fc |
Desktop (1200px+)
βββββββββββββββββββββββββββββββββββββββ
β π‘οΈ NewsGuardian.AI β
βββββββββββββββββββ¬ββββββββββββββββββββ€
β Sidebar β Main Content β
β - Navigation β - Text Input β
β - Stats β - Results β
β - Info β - Visualizations β
βββββββββββββββββββ΄ββββββββββββββββββββ
Mobile (<768px)
βββββββββββββββββββββββββββββββββββββββ
β π‘οΈ NewsGuardian.AI β
βββββββββββββββββββββββββββββββββββββββ€
β Navigation Menu β
βββββββββββββββββββββββββββββββββββββββ€
β Text Input β
βββββββββββββββββββββββββββββββββββββββ€
β Results & Visualizations β
βββββββββββββββββββββββββββββββββββββββ
NewsGuardian.AI/
βββ π app/ # Streamlit web application
β βββ app.py # Main application file
β βββ app_beautiful.py # Enhanced UI version
β βββ app_simple_beautiful.py # Simplified UI version
βββ π data/ # Datasets and processed data
β βββ True.csv # Real news dataset
β βββ Fake.csv # Fake news dataset
β βββ easy_ham/ # Legitimate emails
β βββ spam/ # Spam emails
β βββ cleaned_*.csv # Processed datasets
βββ π models/ # Trained models and vectorizers
β βββ news_improved_*.pkl # News classification models
β βββ email_improved_*.pkl # Email classification models
β βββ *_confusion_matrix.png # Performance visualizations
βββ π notebooks/ # Jupyter notebooks
β βββ EDA.ipynb # Exploratory data analysis
βββ π train_models.py # Original training script
βββ π train_models_improved.py # Enhanced training script
βββ π train_models_enhanced.py # Advanced training script
βββ π test_models.py # Model testing script
βββ π bert_models.py # BERT model implementation
βββ π requirements.txt # Python dependencies
βββ π setup.py # Package setup
βββ π README.md # This file
# TF-IDF Vectorizer Settings
TFIDF_CONFIG = {
'max_features': 10000,
'ngram_range': (1, 2),
'min_df': 2,
'max_df': 0.95,
'sublinear_tf': True
}
# Model Parameters
MODEL_CONFIG = {
'LogisticRegression': {
'C': 1.0,
'max_iter': 2000,
'solver': 'liblinear'
},
'RandomForest': {
'n_estimators': 200,
'max_depth': 15,
'min_samples_split': 5
},
'MultinomialNB': {
'alpha': 0.1
}
}# Streamlit Configuration
STREAMLIT_CONFIG = {
'page_title': 'NewsGuardian.AI',
'page_icon': 'π‘οΈ',
'layout': 'wide',
'initial_sidebar_state': 'expanded'
}
# Color Scheme
COLORS = {
'primary': '#667eea',
'secondary': '#764ba2',
'success': '#51cf66',
'warning': '#ffd43b',
'danger': '#ff6b6b',
'info': '#74c0fc'
}We welcome contributions! Please see our Contributing Guidelines for details.
-
Fork the Repository
git clone https://github.com/yourusername/NewsGuardian.AI.git
-
Create a Feature Branch
git checkout -b feature/amazing-feature
-
Make Your Changes
- Add new features
- Fix bugs
- Improve documentation
-
Test Your Changes
python test_models.py streamlit run app/app.py
-
Submit a Pull Request
- Describe your changes
- Include tests if applicable
- Update documentation
If you find a bug, please create an issue with:
- Bug description
- Steps to reproduce
- Expected vs actual behavior
- System information
We love new ideas! Please submit feature requests with:
- Feature description
- Use case
- Implementation suggestions
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2024 NewsGuardian.AI
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- Fake News Dataset: Kaggle Fake and Real News Dataset
- Spam Email Dataset: SpamAssassin Public Corpus
- NLTK: Natural Language Processing Toolkit
- Scikit-learn: Machine Learning Library
- Python: Core programming language
- Streamlit: Web application framework
- Scikit-learn: Machine learning algorithms
- NLTK: Natural language processing
- Plotly: Interactive visualizations
- Pandas & NumPy: Data manipulation
- Lead Developer: [Your Name]
- UI/UX Design: [Your Name]
- Machine Learning: [Your Name]
- Documentation: [Your Name]
- π Website: https://newsguardian.ai
- π§ Email: [email protected]
- π¦ Twitter: @NewsGuardianAI
- π¬ Discord: NewsGuardian.AI Community