In this project, we developed several machine learning models to classify real and fake news articles. Our project uses Python for data processing and model building on the backend as well as a Flask web interface for users. The application employs various machine learning models to predict and display the legitimacy of news articles based on their text.
The project makes use of multiple datasets sourced from Kaggle, featuring labeled real and fake news articles. These datasets were concatonated, cleaned, and preprocessed to train three main models: Logistic Regression, Random Forest, and XGBoost. The models evaluate text data transformed via TF-IDF vectorization to predict a given news article's legitimacy.
The user interface, accessible via a web browser, allows users to test a news article's authenticity. The classification findings, along with a comparison graph of the probability scores from each model, are displayed on the results page.
- Visual Studio Code installed.
- Python installed (latest version recommended).
- Open Visual Studio Code.
- Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of VS Code or by pressing
Ctrl+Shift+X
(orCmd+Shift+X
on macOS). - Search for and install the following extensions:
-
- Python (by Microsoft)
-
- Jupyter (by Microsoft)
Before you can use this repository, you'll need to have Git and Git LFS installed:
- Install Git (if not already installed): https://git-scm.com/downloads
- Install Git LFS:
- Install Using Homebrew:
- If you do not have Homebrew installed, open Terminal and install Homebrew by running:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install Git LFS with Homebrew by executing:
brew install git-lfs
- If you do not have Homebrew installed, open Terminal and install Homebrew by running:
- Download the Installer:
- Visit the Git LFS Releases Page and download the
git-lfs-windows-vX.X.X.exe
file (whereX.X.X
is the latest version). - Run the installer and follow the prompts to install Git LFS.
- Visit the Git LFS Releases Page and download the
After installing Git LFS, you must run the following command in your terminal to set it up for use:
git lfs install
-
Open Visual Studio Code.
-
To clone the repository into a specific folder, you can drag and drop the folder into VS Code or use the Terminal to navigate:
- Press
Ctrl+
(orCmd+
on macOS) to open the Terminal in VS Code. - Navigate to your desired directory with
cd <directory-path>
.
- Press
-
Run the command in the VS Code terminal
View > Terminal
to clone the repository:git clone https://github.com/lukeflannigan/Fake-News-Detection-Model.git
-
After cloning, you need to change the directory to the project folder. Run:
cd Fake-News-Detection-Model
Within the project directory in VS Code Terminal:
- Run the command to create a virtual environment:
- Windows:
python -m venv venv
- macOS/Linux:
python3 -m venv venv
- Windows:
- Then, run the command to activate the virtual environment:
- Windows:
.\venv\Scripts\activate
- macOS/Linux:
source venv/bin/activate
- Windows:
With the virtual environment activated, install the dependencies by running:
pip install -r requirements.txt
- Ensure the Python interpreter is set to the virtual environment you created. This interpreter will typically have
venv
in its path, indicating it's the virtual environment for this project. - If not set automatically, open Command Palette with
Ctrl+Shift+P
(orCmd+Shift+P
on macOS), typePython: Select Interpreter
, and select the interpreter that includesvenv
and is located within your project directory. - If necessary:
- Install the
ipykernel
package using pip:pip install ipykernel
. - Run the command
python -m ipykernel install --user --name=myenv
to create a new kernel namedmyenv
associated with your virtual environment (venv
). - In VS Code, open a Jupyter Notebook and select the newly created kernel (
myenv
) from the kernel dropdown menu in the top-right corner of the notebook interface.
- Install the
- With the virtual environment activated and dependencies installed, start the Flask server by running the following command in the VS Code Terminal:
python app.py
This command will start running the Flask server.
-
Once running, open a web browser and navigate to
http://127.0.0.1:5000/
. This will take you to the homepage of the user interface. -
To use the application, paste the plaintext of a news article in the input box and submit it for analysis. The application will display the results, showing whether the article is likely real or fake along with the probability scores from the three models.
- If you need to use a Jupyter Notebook:
- Ensure
ipykernel
is installed:
pip install ipykernel
- Register a new kernel associated with the virtual environment:
python -m ipykernel install --user --name=myenv
- Open a Jupyter Notebook in VS Code and select
myenv
from the kernel dropdown menu in the notebook interface.