Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +52 -0
- requirements.txt +4 -0
- spam.csv +0 -0
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from sklearn.model_selection import train_test_split
|
3 |
+
from sklearn.feature_extraction.text import CountVectorizer
|
4 |
+
import pandas as pd
|
5 |
+
import numpy as np
|
6 |
+
from sklearn.neighbors import KNeighborsClassifier
|
7 |
+
from sklearn.naive_bayes import MultinomialNB
|
8 |
+
from sklearn.metrics import accuracy_score
|
9 |
+
|
10 |
+
import seaborn as sns
|
11 |
+
import matplotlib.pyplot as plt
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
df = pd.read_csv("spam.csv")
|
16 |
+
st.title(":red[Email Spam or Ham Classification]")
|
17 |
+
|
18 |
+
x = df["Message"]
|
19 |
+
y = df["Category"]
|
20 |
+
ham = df[df["Category"] == "ham"]
|
21 |
+
|
22 |
+
fig, ax = plt.subplots()
|
23 |
+
|
24 |
+
sns.countplot(data = df, x= "Category", ax = ax)
|
25 |
+
st.pyplot(fig)
|
26 |
+
|
27 |
+
bow = CountVectorizer(stop_words = "english")
|
28 |
+
|
29 |
+
final_X = pd.DataFrame(bow.fit_transform(x).toarray(), columns = bow.get_feature_names_out())
|
30 |
+
|
31 |
+
X_train, X_test, y_train, y_test = train_test_split(final_X, y , test_size= 0.25, random_state = 23)
|
32 |
+
|
33 |
+
nav_base = MultinomialNB()
|
34 |
+
|
35 |
+
nav_base.fit(X_train, y_train)
|
36 |
+
|
37 |
+
y_pred = nav_base.predict(X_test)
|
38 |
+
|
39 |
+
res = st.button("predict_score")
|
40 |
+
if res:
|
41 |
+
st.write(accuracy_score(y_test,y_pred))
|
42 |
+
st.snow()
|
43 |
+
|
44 |
+
input = st.text_input("enter email")
|
45 |
+
|
46 |
+
def fun(email):
|
47 |
+
data = bow.transform([email]).toarray()
|
48 |
+
st.write(nav_base.predict(data)[0])
|
49 |
+
|
50 |
+
if st.button("predict"):
|
51 |
+
fun(input)
|
52 |
+
st.balloons()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
numpy
|
4 |
+
scikit-learn
|
spam.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|