Fake-News-Predictor is a machine learning project that detects whether news articles are real or fake. It uses a dataset of news articles with author, title, and text fields and trains a logistic regression model on text features.
Fake_News.ipynb: Jupyter notebook containing the data loading, preprocessing, model training, evaluation, and prediction workflow.train.csv: Dataset used for training and testing the fake news classifier.
The dataset includes the following fields:
id: unique identifier for the news articletitle: title of the articleauthor: author of the articletext: main text content of the articlelabel: target label where0indicates real news and1indicates fake news
- Load the dataset into a pandas DataFrame.
- Fill missing values and concatenate
authorandtitleinto acontentfield. - Clean text using regular expressions, lowercase conversion, tokenization, stopword removal, and stemming.
- Convert text to numerical features with
TfidfVectorizer. - Split data into training and test sets.
- Train a
LogisticRegressionmodel. - Evaluate accuracy on training and test sets.
- Test the predictive system using a sample input from the test set.
The notebook uses the following Python libraries:
numpypandasnltkscikit-learn
- Install Python and create a virtual environment if desired.
- Install the required packages:
pip install numpy pandas nltk scikit-learn- Download the
train.csvfile into the project folder if it is not already present. - Open
Fake_News.ipynbin Jupyter Notebook or JupyterLab. - Run the notebook cells in order.
- The notebook downloads the NLTK stopwords dataset with
nltk.download('stopwords'). - The final interactive prediction step selects a sample by index from the test split.
- The model is a prototype and can be improved by using more features, deeper preprocessing, or a different classification algorithm.