-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
30 lines (21 loc) · 859 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import streamlit as st
import pickle
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import PassiveAggressiveClassifier
st.title('Fake News Detector')
df = pd.read_csv("news.csv")
labels = df.label
X_train, X_test, y_train, y_test = train_test_split(
df['text'], labels, test_size=0.2, stratify=labels, random_state=42)
tfidf_vectorizer = TfidfVectorizer(stop_words='english', max_df=0.7)
# Fit and Transform train and test set
tfidf_train = tfidf_vectorizer.fit_transform(X_train)
tfidf_test = tfidf_vectorizer.transform(X_test)
# Initialize PassiveAgressiveClassifier
pac = PassiveAggressiveClassifier(max_iter=50)
pac.fit(tfidf_train, y_train)
# y_pred = pac.predict(tfidf_test)
y_pred = pac.predict(tfidf_test[0])
st.write(y_pred)