Skip to content

Instantly share code, notes, and snippets.

@HeenaR17
Created October 25, 2020 19:34
Show Gist options
  • Save HeenaR17/4ee9547bb7d627ec926a74b8e68b6f9c to your computer and use it in GitHub Desktop.
Save HeenaR17/4ee9547bb7d627ec926a74b8e68b6f9c to your computer and use it in GitHub Desktop.
def fake_news(sample_news):
sample_news = re.sub(pattern='[^a-zA-Z]',repl=' ', string=sample_news)
sample_news = sample_news.lower()
sample_news_words = sample_news.split()
sample_news_words = [word for word in sample_news_words if not word in set(stopwords.words('english'))]
ps = PorterStemmer()
final_news = [ps.stem(word) for word in sample_news_words]
final_news = ' '.join(final_news)
temp = cv.transform([final_news]).toarray()
return classifier.predict(temp)
# For generating random integer
from random import randint
# Predicting values
row = randint(0,news_title.shape[0]-1)
sample_news = news_title[row]
print('News: {}'.format(sample_news))
if fake_news(sample_news):
print('Prediction: This is a FAKE news!')
else:
print('Prediction: This is a REAL news.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment