<jupyter_start><jupyter_text><jupyter_code># IF YOU ARE USING GOOGLE COLABORATORY AND IF YOUR DATA IS STORED IN GOOGLE DRIVE, THEN RUN THIS CODE OTHERWISE DON'T EXECUTE

from google.colab import drive
drive.mount('/content/gdrive')
import datetime
now = datetime.datetime.now()
print ("Current date and time : ")
print (now.strftime("%Y-%m-%d %H:%M:%S"))
import pickle
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('ggplot')
with open("/content/gdrive/My Drive/Machine Learning Projects/FAKE VS REAL NEWS CATEGORY CLASSIFIER PROJECT/SOURCE CODES AND DATASETS/PACKAGE 1 - SOURCE CODES AND FILES/Pretrained Models/nb_classifier.pkl", "rb") as fin:
  vectorizer, nb_classifier = pickle.load(fin)
 
with open("/content/gdrive/My Drive/Machine Learning Projects/FAKE VS REAL NEWS CATEGORY CLASSIFIER PROJECT/SOURCE CODES AND DATASETS/PACKAGE 1 - SOURCE CODES AND FILES/Pretrained Models/SVC_classifier.pkl", "rb") as fin:
  vectorizer, svc_classifier = pickle.load(fin)

with open("/content/gdrive/My Drive/Machine Learning Projects/FAKE VS REAL NEWS CATEGORY CLASSIFIER PROJECT/SOURCE CODES AND DATASETS/PACKAGE 1 - SOURCE CODES AND FILES/Pretrained Models/SVC_N_classifier.pkl", "rb") as fin:
  vectorizer, SVC_N_classifier = pickle.load(fin)
 
with open("/content/gdrive/My Drive/Machine Learning Projects/FAKE VS REAL NEWS CATEGORY CLASSIFIER PROJECT/SOURCE CODES AND DATASETS/PACKAGE 1 - SOURCE CODES AND FILES/Pretrained Models/pac_classifier.pkl", "rb") as fin:
  vectorizer, pac_classifier = pickle.load(fin)
 
with open("/content/gdrive/My Drive/Machine Learning Projects/FAKE VS REAL NEWS CATEGORY CLASSIFIER PROJECT/SOURCE CODES AND DATASETS/PACKAGE 1 - SOURCE CODES AND FILES/Pretrained Models/calibrator_classifier.pkl", "rb") as fin:
  vectorizer, calibrator_classifier = pickle.load(fin)
  
with open("/content/gdrive/My Drive/Machine Learning Projects/FAKE VS REAL NEWS CATEGORY CLASSIFIER PROJECT/SOURCE CODES AND DATASETS/PACKAGE 1 - SOURCE CODES AND FILES/Pretrained Models/logreg_classifier.pkl", "rb") as fin:
  vectorizer, logreg_classifier = pickle.load(fin)

with open("/content/gdrive/My Drive/Machine Learning Projects/FAKE VS REAL NEWS CATEGORY CLASSIFIER PROJECT/Pretrained - Models/logregcv_classifier.pkl", "rb") as fin:
  vectorizer, logregcv_classifier = pickle.load(fin)


print("SUCCESS ALL MODELS LOADED")
# Required Functions to predict the News
def prediction(text):
  test = vectorizer.transform(text)
  graph,output = ensemble(test)

  if output == 1:
    value = 'REAL'
  else:
    value = 'FAKE'

  class_labels = ['FAKE','REAL']
  j = [graph[0][0],graph[0][1]]
  y_pos = np.arange(len(class_labels))
  plt.barh(y_pos,j)
  plt.yticks(y_pos,class_labels)
  plt.title('PREDICTION FOR BEING FAKE VS REAL')
  plt.ylabel('Percentage')
  plt.xlabel('Labels')
  plt.show()
  print()
  start = "\033[1m"
  end = "\033[0;0m"
  print('THE GIVEN NEWS ARTICLE IS ' + start + str(value) + end)

def ensemble(x):
  pred1 = logreg_classifier.predict_proba(x)
  pred2 = nb_classifier.predict_proba(x)
  pred3 = svc_classifier._predict_proba_lr(x)
  pred4 = pac_classifier._predict_proba_lr(x)
  pred5 = calibrator_classifier.predict_proba(x)
  pred6 = SVC_N_classifier.predict_proba(x)
  pred7 = logregcv_classifier.predict_proba(x)

  test_pred_prob = np.mean([pred1, pred2, pred3, pred4, pred5, pred6, pred7], axis=0)
  pred = np.argmax(test_pred_prob, axis=1)
  return test_pred_prob,pred<jupyter_output><empty_output><jupyter_text>GIVE YOUR INPUT HERE<jupyter_code>#String input
x = input("ENTER THE NEWS ARTCILE HERE : ")
x=[x,]
prediction(x)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10896017699115045, 'fraction_numerical': 0.00995575221238938, 'mean_word_length': 5.323426573426573, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '441464', 'license': 'MIT', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1289, 'n_words': 321, 'path': 'codes (ML)/Part 2 of Fake or Real News Classifier Single Input Testing.ipynb', 'repo_name': 'bala-codes/FAKE-VS-REAL-NEWS-CLASSIFIER-USING-ML-AND-DL-MODELS', 'size': '3616'}