<jupyter_start><jupyter_text>FAKE NEWS DETECTION  To detect whether the given news is TRUE or FAKE.    IMPORTING THE LIBRARIES<jupyter_code># import necessary libraries
import numpy as np
import pandas as pd
import itertools
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import PassiveAggressiveClassifier
from sklearn.metrics import accuracy_score, confusion_matrix<jupyter_output><empty_output><jupyter_text>IMPORTING THE DATA FILE<jupyter_code>#Read the data
df=pd.read_csv('news.csv')

#Get shape and head
df.shape
df.head()
#Get the labels
labels=df.label
labels.head()<jupyter_output><empty_output><jupyter_text>SPLITTING THE DATA INTO TRAIN AND TEST DATA<jupyter_code>#Split the dataset
x_train,x_test,y_train,y_test=train_test_split(df['text'], labels, test_size=0.2, random_state=7)<jupyter_output><empty_output><jupyter_text>APPLYING THE TF-IDF VECTORIZER<jupyter_code>#Initialize a TfidfVectorizer
tfidf_vectorizer=TfidfVectorizer(stop_words='english', max_df=0.7)

#Fit and transform train set, transform test set
tfidf_train=tfidf_vectorizer.fit_transform(x_train) 
tfidf_test=tfidf_vectorizer.transform(x_test)<jupyter_output><empty_output><jupyter_text>PASSIVE AGGRESSIVE CLASSIFER ALGORITHM<jupyter_code>#Initialize a PassiveAggressiveClassifier
pac=PassiveAggressiveClassifier(max_iter=50)
pac.fit(tfidf_train,y_train)<jupyter_output><empty_output><jupyter_text>ACCURACY CALCULATION<jupyter_code>#Predict on the test set and calculate accuracy
y_pred=pac.predict(tfidf_test)
score=accuracy_score(y_test,y_pred)
print(f'Accuracy: {round(score*100,2)}%')<jupyter_output>Accuracy: 92.66%<jupyter_text>CONFUSION MATRIX<jupyter_code>#Build confusion matrix
confusion_matrix(y_test,y_pred, labels=['FAKE','REAL'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09041689225771521, 'fraction_numerical': 0.008121277747698972, 'mean_word_length': 11.744827586206897, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '75060', 'license': 'MIT', 'n_tokens_mistral': 711, 'n_tokens_neox': 684, 'n_words': 118, 'path': 'detect_news.ipynb', 'repo_name': 'NupSha05/Fake-News-Detection', 'size': '1847'}