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.
git clone https://github.com/Vin-dictive/fake-real-news-detection
cd fake-real-news-detectionNote: The initial clone may take some time as the repository contains dataset files (CSV files in the data/ directory).
- Jupyter - Interactive notebook environment
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.
Option 1: Using Docker (Recommended)
-
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
-
Or build and run directly:
docker build -t fake-news-detection . docker run --rm -p 8000:8000 fake-news-detection -
Access Jupyter Lab at http://127.0.0.1:8000/lab
Option 2: Using conda-lock
-
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
-
Create conda environment:
conda env create -f environment.yml conda activate fake-news-detection
Option 1: Using Makefile (Recommended)
Run the complete analysis pipeline:
make allOr 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 filesOption 2: Using Docker with Makefile
-
Start Docker container:
docker compose up --build
-
In the terminal, look for a URL starting with
http://127.0.0.1:8888/lab?token=and open it in your browser. -
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 renderFunction 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- To shut down the container and clean up the resources,
type
Ctrl+Cin the terminal where you launched the container, and then typedocker compose rm
This project uses a news classification dataset containing:
- True.csv: Contains real news articles
- False.csv: Contains fake news articles
- Source: https://www.kaggle.com/datasets/clmentbisaillon/fake-and-real-news-dataset
- Size: 116.37 MB
Note: Please refer to the original dataset documentation for detailed information about data collection methodology and licensing terms.
- Affiliation: University of British Columbia
- Email: [email protected]
- GitHub: @jessie-liang
- Affiliation: University of British Columbia
- Email: [email protected]
- GitHub: @sgauth01
- Affiliation: University of British Columbia
- Email: [email protected]
- GitHub: @Vin-dictive
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.
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.
