Skip to content

Repository files navigation

Fake Real News Detection

About

This project implements a machine learning solution to classify news articles as real or fake using Naive Bayes classification techniques. With the increasing prevalence of misinformation in digital media, this tool aims to help identify potentially false news articles through statistical analysis.

Word Cloud Analysis

Getting Started

Clone the Repository

git clone https://github.com/Vin-dictive/fake-real-news-detection
cd fake-real-news-detection

Note: The initial clone may take some time as the repository contains dataset files (CSV files in the data/ directory).

Development Environment

  • Jupyter - Interactive notebook environment

Dependencies

This project requires the following main dependencies:

  • Python 3.11
  • Docker (for containerized environment)
  • Data Science Libraries:
    • pandas 2.3.3
    • numpy 2.3.5
    • scipy 1.16.3
    • scikit-learn 1.7.2
  • Visualization:
    • matplotlib 3.10.8
    • wordcloud 1.9.4
  • Development Tools:
    • jupyter
    • notebook 7.5.0
    • ipykernel 7.1.0
  • Data Validation:
    • pandera 0.27.0
  • Utilities:
    • click 8.3.1
    • requests 2.32.5
    • tabulate 0.9.0
    • quarto-cli
    • conda-lock

All dependencies are specified in environment.yml for conda or conda-lock.yml for reproducible builds.

Environment Setup

Option 1: Using Docker (Recommended)
  1. Build and run with Docker Compose for running image from docker hub:

    docker compose up --build

    For ARM based chips run with platform as linux/arm64 in docker-compose.yml

  2. Or build and run directly:

    docker build -t fake-news-detection . 
    docker run --rm -p 8000:8000 fake-news-detection
  3. Access Jupyter Lab at http://127.0.0.1:8000/lab

Option 2: Using conda-lock
  1. Install from lock file for your platform:

    conda-lock install --name fake-news-detection conda-lock.yml
    conda activate fake-news-detection
Option 3: Using environment.yml
  1. Create conda environment:

    conda env create -f environment.yml
    conda activate fake-news-detection

Running the analysis

Option 1: Using Makefile (Recommended)

Run the complete analysis pipeline:

make all

Or run individual steps:

make download      # Download raw data
make validate      # Validate processed data
make split         # Split into train/test sets
make preprocess    # Preprocess data
make eda          # Run exploratory data analysis
make model        # Train the model
make evaluate     # Evaluate the model
make report       # Generate final report
make test         # To run tests
make clean        # Remove generated files
Option 2: Using Docker with Makefile
  1. Start Docker container:

    docker compose up --build
  2. In the terminal, look for a URL starting with http://127.0.0.1:8888/lab?token= and open it in your browser.

  3. Run the analysis:

    make all
Option 3: Running Scripts Manually
python scripts/00_download_data.py \
   --url="https://raw.githubusercontent.com/Vin-dictive/fake-real-news-detection/refs/heads/main/data/raw/Fake.csv" \
   --write_to=data/raw

python scripts/00_download_data.py \
   --url="https://raw.githubusercontent.com/Vin-dictive/fake-real-news-detection/refs/heads/main/data/raw/True.csv" \
   --write_to=data/raw

python scripts/01_clean_transform_data.py \
   --raw_true_data=data/raw/True.csv \
   --raw_fake_data=data/raw/Fake.csv

python scripts/02_data_validation_1.py \
   --processed_data_path=data/processed/complete_data.csv

python scripts/03_data_splitting.py \
   --data_path=data/processed/complete_data.csv

python scripts/04_data_validation_2.py \
   --train_data_path=data/processed/train_data.csv

python scripts/05_data_preprocessing.py \
   --train_data_path=data/processed/train_data.csv \
   --test_data_path=data/processed/test_data.csv

python scripts/06_EDA.py \
   --train_data_path=data/processed/train_data.csv

python scripts/07_model_fitting.py \
   --train_data_path=data/processed/train_data.csv \
   --test_data_path=data/processed/test_data.csv

python scripts/08_model_evaluation.py \
   --test_data_path=data/processed/test_data.csv \
   --model_path=models/naive_bayes.pkl

quarto render

Running the function tests

Function tests are written in python scripts. To run these tests to see whether they pass, please run the following command in the root project directory using bash terminal:

python -m pytest tests/ -v

Clean up

  1. To shut down the container and clean up the resources, type Ctrl + C in the terminal where you launched the container, and then type docker compose rm

Dataset Information

This project uses a news classification dataset containing:

  • True.csv: Contains real news articles
  • False.csv: Contains fake news articles

Dataset Details

Note: Please refer to the original dataset documentation for detailed information about data collection methodology and licensing terms.

Contributors

Jessie Liang

Sarah Gauthier

Vinay Valson

Contributing

We welcome contributions to this project! Please see our Contributing Guidelines for details on how to get started.

Please read our Code of Conduct before contributing.

License

This project’s source code is licensed under the MIT License. The documentation, reports, and written materials in this repository are licensed under the Creative Commons Attribution 4.0 International (CC BY 4.0) license. See the LICENSE file for details.

About

This project implements a machine learning solution to classify news articles as real or fake using Naive Bayes classification techniques. With the increasing prevalence of misinformation in digital media, this tool aims to help identify potentially false news articles through statistical analysis.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages