Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📰 Fake News Detector using Machine Learning

A web-based AI project that detects whether a news article is FAKE or REAL using Machine Learning (Logistic Regression) and TF-IDF Vectorization.
This project is built with Python (Flask) for the backend and a clean HTML + CSS interface for user input and results.


🚀 Features

  • Detects fake or real news using a trained ML model
  • Real-time prediction through Flask web interface
  • Simple and elegant HTML + CSS design
  • Fast and lightweight
  • Easy to train and retrain with your own dataset

🧠 Tech Stack

Component Technology
Programming Language Python
Framework Flask
Machine Learning Scikit-learn
Model Logistic Regression
Frontend HTML, CSS
Data Handling Pandas
Model Saving Joblib

📁 Project Structure

fake_news_app/ │ ├── app.py # Flask web app ├── train_model.py # ML model training script ├── fake_or_real_news.csv # Combined dataset ├── model.pkl # Saved ML model ├── vectorizer.pkl # TF-IDF vectorizer │ ├── templates/ │ └── index.html # Frontend HTML page │ └── static/ └── style.css # CSS file for styling


⚙️ Installation & Setup

1️⃣ Clone or Download the Project

git clone https://github.com/ZohaibAli/fake-news-detector.git cd fake-news-detector

2️⃣ Install Dependencies

Make sure you have Python installed, then run:

pip install flask pandas scikit-learn joblib

3️⃣ Prepare the Dataset

Download dataset from Kaggle: 🔗 Fake and Real News Dataset

Merge both files (True.csv and Fake.csv) into one CSV file:

import pandas as pd

fake = pd.read_csv("Fake.csv") real = pd.read_csv("True.csv")

fake["label"] = "FAKE" real["label"] = "REAL"

data = pd.concat([fake, real]) data.to_csv("fake_or_real_news.csv", index=False)

4️⃣ Train the Model

Run the following command in your terminal:

python train_model.py

✅ This will generate:

model.pkl vectorizer.pkl

5️⃣ Run the Flask Web App

Now start the web app:

python app.py

Then open your browser and go to: 👉 http://127.0.0.1:5000

🧾 Example Prediction

Input News Output "The government announces new education reforms." REAL "Aliens have landed in New York City, scientists confirm." FAKE

📊 Model Performance

Metric Value Algorithm Logistic Regression Accuracy ~93% Feature Extraction TF-IDF Vectorizer Dataset Kaggle Fake and Real News Dataset

About

A web-based AI project that detects whether a news article is FAKE or REAL using Machine Learning (Logistic Regression) and TF-IDF Vectorization.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages