To write a program to implement the SVM For Spam Mail Detection.
- Hardware โ PCs
- Anaconda โ Python 3.7 Installation / Jupyter notebook
- Import the packages.
- Analyse the data.
- Use modelselection and Countvectorizer to preditct the values.
- Find the accuracy and display the result.
/*
Program to implement the SVM For Spam Mail Detection..
Developed by: Lokesh N
RegisterNumber: 212222100023
*/
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import CountVectorizer
from sklearn import svm
from sklearn.metrics import classification_report, accuracy_score
df = pd.read_csv('/content/spam.csv', encoding='ISO-8859-1')
df.head()
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(df['v2'])
y = df['v1']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)
model = svm.SVC (kernel='linear')
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print("Accuracy: ", accuracy_score (y_test, predictions))
print("Classification Report: ")
print(classification_report (y_test, predictions))
Thus the program to implement the SVM For Spam Mail Detection is written and verified using python programming.