# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3.9.2 64-bit
#     name: python3
# ---

import os
os.chdir("C:\\Users\\leon7\\Desktop\\PI-new")

import pandas as pd

dataframe = pd.read_csv('news_dataset.csv')
dataframe.head()

df= dataframe.dropna()

content = df['content']
label = df['label']

content

label

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

content_train,content_test,label_train,label_test = train_test_split(content,label,test_size=0.2,random_state=0)
label_train

label_test

tfVectorizer = TfidfVectorizer(stop_words='english',max_df=0.7)
tfid_content_train = tfVectorizer.fit_transform(content_train)
tfid_content_test  = tfVectorizer.transform(content_test)

classifier = PassiveAggressiveClassifier(max_iter=50)
classifier.fit(tfid_content_train,label_train)

label_pred = classifier.predict(tfid_content_test)
skor = accuracy_score(label_test,label_pred)
print(f'Accuracy: {round(skor*100,2)}%')

cf = confusion_matrix(label_test,label_pred, labels=['fake','real'])
print(cf)


def fake_news_det(news):
    input_data = [news]
    vectorized_input_data = tfVectorizer.transform(input_data)
    prediction = classifier.predict(vectorized_input_data)
    print(prediction)


fake_news_det("Print They should pay all the back all the money plus interest. The entire family and everyone who came in with them need to be deported asap. Why did it take two years to bust them? ")

import pickle
pickle.dump(classifier,open('model.pkl','wb'))

loaded_model = pickle.load(open('model.pkl', 'rb'))


def fake_news_det1(news):
    input_data = [news]
    vectorized_input_data = tfVectorizer.transform(input_data)
    prediction = loaded_model.predict(vectorized_input_data)
    print(prediction)


fake_news_det1("<NAME>: Mastry exhibition review â€“ a sumptuous symphony in black")



StarcoderdataJupyterScriptsDedupFiltered