-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
spam_dect.py
29 lines (27 loc) · 849 Bytes
/
spam_dect.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
# This code is made by MRayan Asim
# pip install pandas
# pip install numpy
# pip install scikit-learn
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(
"https://raw.githubusercontent.com/amankharwal/SMS-Spam-Detection/master/spam.csv",
encoding="latin-1",
)
data.head()
data = data[["class", "message"]]
x = np.array(data["message"])
y = np.array(data["class"])
cv = CountVectorizer()
X = cv.fit_transform(x) # Fit the Data
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=42
)
clf = MultinomialNB()
clf.fit(X_train, y_train)
sample = input("Enter a message:")
data = cv.transform([sample]).toarray()
print(clf.predict(data))