Fake News is one of the major concerns in our society right now. It is a very widespread issue that even the most leading media sometimes gets with the trap of Fake News. If it’s difficult for media channels to detect fake news then it’s next to difficult for a general citizen. As a part of a Machine Learning project, in this article, I will show you Fake News Detection with Machine Learning. I will use all the misinformation that we heard from some previous months about coronavirus. So at the end of this article, you will be able to create a fake news detection model on coronavirus.

Now I will Import all the libraries that we need for Fake News Detection; then I will Import the dataset using the pandas library in Python. Then I will prepare the data using the python pandas:

from nltk.corpus import stopwords    
stop_words = set(stopwords.words('english'))

from nltk.tag import pos_tag
from nltk import word_tokenize
from collections import Counter

import textstat
from lexicalrichness import LexicalRichness

import plotly.express as px
import plotly.figure_factory as ff
import plotly.graph_objects as go

from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix  
from sklearn.metrics import accuracy_score
from sklearn.svm import LinearSVC
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import cross_val_score

pd.set_option('display.max_columns', 500)

df = pd.read_csv('data/corona_fake.csv')
df.loc[df['label'] == 'Fake', ['label']] = 'FAKE'
df.loc[df['label'] == 'fake', ['label']] = 'FAKE'
df.loc[df['source'] == 'facebook', ['source']] = 'Facebook'
df.text.fillna(df.title, inplace=True)

df.loc[5]['label'] = 'FAKE'
df.loc[15]['label'] = 'TRUE'
df.loc[43]['label'] = 'FAKE'
df.loc[131]['label'] = 'TRUE'
df.loc[242]['label'] = 'FAKE'

df = df.sample(frac=1).reset_index(drop=True)
df.title.fillna('missing', inplace=True)
df.source.fillna('missing', inplace=True)

I will create a number of new features based on the titles and body of news articles. Now let’s go through all the features one by one.

#fake news #python #svm #machine learning #data science #programming

Fake News Detection Model | Data Science | Machine Learning | Python
6.30 GEEK