Fake News Detection In Machine Learning


Import Libraries

from keras.models import Sequential
import pandas as pd
import numpy as np
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.models import Sequential
from keras.layers import Dense, Flatten, LSTM, Conv1D, MaxPooling1D, Dropout, Activation
from keras.layers.embeddings import Embedding
from keras.preprocessing.text import text_to_word_sequence


Mount Drive


from google.colab import drive
drive.mount('/content/drive')

Read Data Path

loc = '/content/drive/My Drive/fake/'

Read Dataset

# loading the a train set
tr = pd.read_csv(loc+'train.csv')
tr.dropna(inplace=True)
tr.head()

output:


Loading Test Data


#loading the test set
ts = pd.read_csv(loc+'test.csv')
ts.dropna(inplace=True)
ts.head()

Ouput:


Length of both dataset:

len(tr),len(ts)

(18285, 4575)


# using only 3000 record  to reduce memory usage , increase the numbers below to increase the data.
tr = tr.iloc[:2000,:]
ts = ts.iloc[:1000,:]
tr.label.value_counts()
len(tr)
# cleaning data
tr.replace(r'\b\w{1,3}\b','', regex =True, inplace = True)neuralNetwork.fit(emb, y_tr, epochs=1)
tr.replace(r'\b\w{1,3}\b','', regex =True, inplace = True)
tr.head()

Output:



Get complete solution of this? Send your details at:


realcode4you@gmail.com

#MachineLearningAssignmentHelp #MachineLearningHomeworkHelp #FakeNewsDetection

2 views0 comments