Fake news is one of the biggest problems with online social media and even some news sites. Most of the time, we see a lot of fake news about politics. So using machine learning for fake news detection is a very challenging task. If you want to learn how to detect fake news using machine learning, this article is for you. In this article, I will walk you through the task of Fake News Detection with Machine Learning using Python.
Fake News Detection
Fake news is one of the biggest problems because it leads to a lot of misinformation in a particular region. Most of the time, spreading false news about a community’s political and religious beliefs can lead to riots and violence as you must have seen in the country where you live. So, to detect fake news, we can find relationships between the fake news headlines so that we can train a machine learning model that can tell us whether a particular piece of information is fake or real by simply observing the headline in the news. So in the section below, I’m going to introduce you to a machine learning project on fake news detection using the Python programming language.
Fake News Detection using Python
The dataset I am using here for the fake news detection task has data about the news title, news content, and a column known as label that shows whether the news is fake or real. So we can use this dataset to find relationships between fake and real news headlines to understand what type of headlines are in most fake news. So let’s import the necessary Python libraries and the dataset that we need for this task:
Unnamed: 0 ... label 0 8476 ... FAKE 1 10294 ... FAKE 2 3608 ... REAL 3 10142 ... FAKE 4 875 ... REAL
This dataset is very large and luckily it still has no missing values so without wasting any time let’s use the title column as the feature we need to train a machine learning model and the label column as the values we want to predict:
Now let’s separate the dataset into training and testing sets, and then I’ll use the Multinomial Naive Bayes algorithm to train the fake news detection model:
0.8074191002367798
Now let’s test this model. To test our trained model, I’ll first write down the title of any news item found on google news to see if our model predicts that the news is real or not:
['REAL']
Now I’m going to write a random fake news headline to see if the model predicts the news is fake or not:
['FAKE']
Also, Read – Solving Data Science Case Studies with Python (eBook)
Summary
So this is how we can train a machine learning model for the task of fake news detection by using the Python programming language. Fake news is one of the biggest problems because it leads to a lot of misinformation in a particular region. I hope you liked this article on the task of Fake News detection with machine learning using Python. Feel free to ask your valuable questions in the comments section below.