Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 📌 Project Overview
QuickFactChecker is a machine learning–based web app that helps detect whether a news article is **real** or **fake**.
It uses different models (Naive Bayes, LSTM, etc.) trained on the **LIAR dataset** to evaluate credibility and assist users in identifying potentially misleading information.
It uses different models (e.g., Naive Bayes, LSTM) trained on the **LIAR dataset** to evaluate credibility and assist users in identifying potentially misleading information.

---

Expand All @@ -18,7 +18,7 @@ It uses different models (Naive Bayes, LSTM, etc.) trained on the **LIAR dataset
## 📂 Project Structure
```bash
dataset/liar
├── README
├── README.md ##Dataset description
├── train.tsv ##Training data
├── test.tsv ##Testing data
├── valid.tsv ##Validation data
Expand All @@ -28,8 +28,16 @@ module/
├── fake-news-detection-using-lstm.ipynb
├── fake-news-detection-using-nb.ipynb
├── liar-data-analysis.ipynb

templates/
├── index.html

scripts/
└── fake_news_logreg_rf.py ## Train & evaluate Naive Bayes, Logistic Regression, Random Forest
results/
├── model_comparison.md ## Generated baseline comparison table (markdown)
└── comparison.png ## Generated accuracy bar chart

.gitattributes
app.py
hero_img.svg
Expand All @@ -40,23 +48,42 @@ requirements.txt

## ⚙️ Installation & Setup

1. Clone the repository:
1. Clone the repository and navigate into it:
```bash
git clone https://github.com/Deepika14145/QuickFactChecker.git
cd QuickFactChecker
```
2. Create virtual environment (optional but recommended)
```bash
python -m venv venv
3. Activate the virtual environment:
```bash
source venv/bin/activate # for Linux/Mac
venv\Scripts\activate # for Windows
```

3. Install the required dependencies:
4. Install the required dependencies:
```bash
pip install -r requirements.txt
```

## 📊 Baseline Model Comparison

We evaluated three models on the LIAR dataset using TF-IDF features. Example results (accuracy & precision):
example:
| Model | Accuracy | Precision |
|---------------------|----------|-----------|
| Naive Bayes | 0.XXXX | 0.XXXX |
| Logistic Regression | 0.XXXX | 0.XXXX |
| Random Forest | 0.XXXX | 0.XXXX |

Logistic Regression achieved the highest accuracy among the tested baselines.
### 🔧 Run the comparison script
To reproduce these results, run:
```bash
scripts/fake_news_logreg_rf.py
```

## Usage

1. Run the following command to start the application:
Expand All @@ -67,6 +94,7 @@ requirements.txt
2. The app will provide predictions on whether a news article is real or fake based on the input.

## 🛠️ Model Training
To retrain or experiment with the models, run the provided Jupyter notebooks. Ensure your virtual environment is activated and all dependencies are installed.
### Naive Bayes
Run the notebook:
```bash
Expand All @@ -90,7 +118,7 @@ Contributions are welcome! Follow these steps:
1. Fork the repository
2. Create a new branch (git checkout -b feature-name)
3. Make your changes
4. Commit your changes (git commit -m 'Add feature')
4. Commit your changes (git commit -m 'description of your feature/fix')
5. Push to the branch (git push origin feature-name)
6. Create a Pull Request

Expand All @@ -100,7 +128,7 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) and follow our [Code of Conduct](

For queries, feedback, or guidance regarding this project, you can contact the **mentor** assigned to the issue:

- 📩 **GitHub**: [Deepika14145](https://github.com/Deepika14145)
- 📩 **GitHub**: [Deepika14145](https://github.com/Deepika14145)(owner of this repository)
- 💬 **By commit/PR comments**: Please tag the mentor in your commit or pull request discussion for direct feedback.

Original Repository: [QuickFactChecker](https://github.com/Deepika14145/QuickFactChecker.git)
Expand All @@ -112,6 +140,6 @@ This project is licensed under the **MIT License** - see the [LICENSE](LICENSE)

---

If you like this project, please give it a ⭐ star. Your support means a lot to us!
If you find this project useful, please give it a ⭐️! Your support is appreciated.!

Feel free to contribute or suggest new features!🙏
Binary file added results/comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions results/model_comparison.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Model Comparison Results

| Model | Accuracy| Precision |
|---------------------|---------|-----------|
| Naive Bayes | 0.2344 | 0.3558 |
| Logistic Regression | 0.2402 | 0.2328 |
| Random Forest | 0.2310 | 0.2386 |
91 changes: 91 additions & 0 deletions scripts/fake_news_logreg_rf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import MultinomialNB
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, precision_score
import matplotlib.pyplot as plt
import os

# -------------------------
# Load and preprocess dataset
# -------------------------
df = pd.read_csv("QuickFactChecker/dataset/liar/train.tsv", sep="\t", on_bad_lines="warn")

df.columns = [
"id", "label", "statement", "subject", "speaker", "job", "state", "party",
"barely_true_counts", "false_counts", "half_true_counts", "mostly_true_counts",
"pants_on_fire_counts", "context"
]

X = df["statement"] # claim text
y = df["label"] # truth label (categories)

# Convert text into TF-IDF features
vectorizer = TfidfVectorizer(max_features=5000, stop_words="english")
X_vec = vectorizer.fit_transform(X)

# Split dataset
X_train, X_test, y_train, y_test = train_test_split(
X_vec, y, test_size=0.2, random_state=42
)

# -------------------------
# Helper function for training
# -------------------------
def train_and_evaluate(model, name, results):
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
acc = accuracy_score(y_test, y_pred)
prec = precision_score(y_test, y_pred, average="macro", zero_division=0)
results[name] = {"accuracy": acc, "precision": prec}

# -------------------------
# Train models
# -------------------------
results = {}

train_and_evaluate(MultinomialNB(), "Naive Bayes", results)
train_and_evaluate(LogisticRegression(max_iter=1000), "Logistic Regression", results)
train_and_evaluate(RandomForestClassifier(n_estimators=100, random_state=42), "Random Forest", results)

# -------------------------
# Print results in table
# -------------------------
print("\nModel Performance Comparison:\n")
print("{:<20} {:<10} {:<10}".format("Model", "Accuracy", "Precision"))
for model, scores in results.items():
print("{:<20} {:.4f} {:.4f}".format(model, scores["accuracy"], scores["precision"]))

# -------------------------
# Save results to markdown
# -------------------------
os.makedirs("results", exist_ok=True)

with open("results/model_comparison.md", "w") as f:
f.write("# Model Comparison Results\n\n")
f.write("| Model | Accuracy | Precision |\n")
f.write("|--------------------|----------|-----------|\n")
for model, scores in results.items():
f.write(f"| {model} | {scores['accuracy']:.4f} | {scores['precision']:.4f} |\n")

# -------------------------
# Plot comparison
# -------------------------
models = list(results.keys())
accuracies = [results[m]["accuracy"] for m in models]

plt.figure(figsize=(8,5))
plt.bar(models, accuracies, color=['skyblue', 'lightgreen', 'salmon'])
plt.ylim(0,0.5)
plt.xlabel("Models")
plt.ylabel("Accuracy")
plt.title("Model Accuracy Comparison")

# Add accuracy labels
for i, acc in enumerate(accuracies):
plt.text(i, acc + 0.01, f"{acc:.2f}", ha='center', fontsize=12)

plt.savefig("results/comparison.png")
plt.show()