Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created July 9, 2021 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/531d2e91e66df8b426332cf2f8b806e3 to your computer and use it in GitHub Desktop.
Save amankharwal/531d2e91e66df8b426332cf2f8b806e3 to your computer and use it in GitHub Desktop.
import pandas as pd
import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import MultinomialNB
data = pd.read_csv("news.csv")
x = np.array(data["title"])
y = np.array(data["label"])
cv = CountVectorizer()
x = cv.fit_transform(x)
xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.2, random_state=42)
model = MultinomialNB()
model.fit(xtrain, ytrain)
import streamlit as st
st.title("Fake News Detection System")
def fakenewsdetection():
user = st.text_area("Enter Any News Headline: ")
if len(user) < 1:
st.write(" ")
else:
sample = user
data = cv.transform([sample]).toarray()
a = model.predict(data)
st.title(a)
fakenewsdetection()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment