Siddhesh Asati: #Group: B (ML) #Assignment: 7
Siddhesh Asati: #Group: B (ML) #Assignment: 7
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
[3]: Email No. the to ect and for of a you hou ... connevey \
0 Email 1 0 0 1 0 0 0 2 0 0 ... 0
1 Email 2 8 13 24 6 6 2 102 1 27 ... 0
2 Email 3 0 0 1 0 0 0 8 0 0 ... 0
3 Email 4 0 5 22 0 5 1 51 2 10 ... 0
4 Email 5 7 6 17 1 5 2 57 0 9 ... 0
... ... ... .. ... ... ... .. ... ... ... ... ...
5167 Email 5168 2 2 2 3 0 0 32 0 0 ... 0
5168 Email 5169 35 27 11 2 6 5 151 4 3 ... 0
5169 Email 5170 0 0 1 1 0 0 11 0 0 ... 0
5170 Email 5171 2 7 1 0 2 1 28 2 0 ... 0
5171 Email 5172 22 24 5 1 6 5 148 8 2 ... 0
1
... ... ... ... ... ... ... .. ...
5167 0 0 0 0 0 0 0 0
5168 0 0 0 0 0 0 1 0
5169 0 0 0 0 0 0 0 0
5170 0 0 0 0 0 0 1 0
5171 0 0 0 0 0 0 0 0
Prediction
0 0
1 0
2 0
3 0
4 0
... ...
5167 0
5168 0
5169 1
5170 1
5171 0
[4]: data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5172 entries, 0 to 5171
Columns: 3002 entries, Email No. to Prediction
dtypes: int64(3001), object(1)
memory usage: 118.5+ MB
[5]: data.head()
[5]: Email No. the to ect and for of a you hou ... connevey jay \
0 Email 1 0 0 1 0 0 0 2 0 0 ... 0 0
1 Email 2 8 13 24 6 6 2 102 1 27 ... 0 0
2 Email 3 0 0 1 0 0 0 8 0 0 ... 0 0
3 Email 4 0 5 22 0 5 1 51 2 10 ... 0 0
4 Email 5 7 6 17 1 5 2 57 0 9 ... 0 0
2
[6]: data.tail()
[6]: Email No. the to ect and for of a you hou ... connevey \
5167 Email 5168 2 2 2 3 0 0 32 0 0 ... 0
5168 Email 5169 35 27 11 2 6 5 151 4 3 ... 0
5169 Email 5170 0 0 1 1 0 0 11 0 0 ... 0
5170 Email 5171 2 7 1 0 2 1 28 2 0 ... 0
5171 Email 5172 22 24 5 1 6 5 148 8 2 ... 0
Prediction
5167 0
5168 0
5169 1
5170 1
5171 0
[7]: data.shape
[8]: data.describe()
3
50% 1.000000 28.000000 1.000000 0.000000 5.000000 ...
75% 2.000000 62.250000 3.000000 1.000000 12.000000 ...
max 77.000000 1898.000000 70.000000 167.000000 223.000000 ...
[9]: data.dtypes
[10]: data.isnull().sum()
4
and 0
..
military 0
allowing 0
ff 0
dry 0
Prediction 0
Length: 3002, dtype: int64
[12]: the to ect and for of a you hou in ... enhancements connevey \
0 0 0 1 0 0 0 2 0 0 0 ... 0 0
1 8 13 24 6 6 2 102 1 27 18 ... 0 0
2 0 0 1 0 0 0 8 0 0 4 ... 0 0
3 0 5 22 0 5 1 51 2 10 1 ... 0 0
4 7 6 17 1 5 2 57 0 9 3 ... 0 0
[13]: 0 0
1 0
2 0
3 0
4 0
Name: Prediction, dtype: int64
5
[14]: from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=.2␣
‹→,random_state=12)
x_test
[16]: KNeighborsClassifier()
6
[17]: array([1, 0, 0, ..., 1, 1, 1], dtype=int64)
[20]: 0.8676328502415459
7
[21]: #Support Vector Machine
from sklearn.svm import SVC
svc = SVC(kernel='linear', random_state=0)
svc.fit(x_train, y_train)
8
[25]: #Accuracy score
accuracy_score(y_test, y_pred_svc)
[25]: 0.9439613526570049
[ ]: