Skip to content

Commit 3f8de7e

Browse files
authored
added spam detection
1 parent 39a1790 commit 3f8de7e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

machine_learning/spam_dect.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#This code is made by MRayan Asim
2+
#pip install pandas
3+
#pip install numpy
4+
#pip install scikit-learn
5+
import pandas as pd
6+
import numpy as np
7+
from sklearn.feature_extraction.text import CountVectorizer
8+
from sklearn.model_selection import train_test_split
9+
from sklearn.naive_bayes import MultinomialNB
10+
data = pd.read_csv("https://raw.githubusercontent.com/amankharwal/SMS-Spam-Detection/master/spam.csv", encoding= 'latin-1')
11+
data.head()
12+
data = data[["class", "message"]]
13+
x = np.array(data["message"])
14+
y = np.array(data["class"])
15+
cv = CountVectorizer()
16+
X = cv.fit_transform(x) # Fit the Data
17+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
18+
19+
clf = MultinomialNB()
20+
clf.fit(X_train,y_train)
21+
sample = input('Enter a message:')
22+
data = cv.transform([sample]).toarray()
23+
print(clf.predict(data))

0 commit comments

Comments
 (0)