Created
October 25, 2020 19:34
-
-
Save HeenaR17/4ee9547bb7d627ec926a74b8e68b6f9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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