SPPUML2
SPPUML2
Roll No : 2441059
Batch : D
In [70]: df = pd.read_csv('emails.csv')
In [71]: df.head()
Out[71]:
Email
the to ect and for of a you hou ... connevey jay valued lay infras
No.
Email
0 0 0 1 0 0 0 2 0 0 ... 0 0 0 0
1
Email
1 8 13 24 6 6 2 102 1 27 ... 0 0 0 0
2
Email
2 0 0 1 0 0 0 8 0 0 ... 0 0 0 0
3
Email
3 0 5 22 0 5 1 51 2 10 ... 0 0 0 0
4
Email
4 7 6 17 1 5 2 57 0 9 ... 0 0 0 0
5
localhost:8888/notebooks/ML/ML_2.ipynb 1/7
07/08/2024, 16:34 ML_2 - Jupyter Notebook
In [72]: df.tail()
Out[72]:
Email
the to ect and for of a you hou ... connevey jay valued lay inf
No.
Email
5167 2 2 2 3 0 0 32 0 0 ... 0 0 0 0
5168
Email
5168 35 27 11 2 6 5 151 4 3 ... 0 0 0 0
5169
Email
5169 0 0 1 1 0 0 11 0 0 ... 0 0 0 0
5170
Email
5170 2 7 1 0 2 1 28 2 0 ... 0 0 0 0
5171
Email
5171 22 24 5 1 6 5 148 8 2 ... 0 0 0 0
5172
In [73]: df.describe()
Out[73]:
the to ect and for of
In [74]: df.shape
localhost:8888/notebooks/ML/ML_2.ipynb 2/7
07/08/2024, 16:34 ML_2 - Jupyter Notebook
In [76]: df
Out[76]:
the to ect and for of a you hou in ... connevey jay valued lay infras
0 0 0 1 0 0 0 2 0 0 0 ... 0 0 0 0
1 8 13 24 6 6 2 102 1 27 18 ... 0 0 0 0
2 0 0 1 0 0 0 8 0 0 4 ... 0 0 0 0
3 0 5 22 0 5 1 51 2 10 1 ... 0 0 0 0
4 7 6 17 1 5 2 57 0 9 3 ... 0 0 0 0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
5167 2 2 2 3 0 0 32 0 0 5 ... 0 0 0 0
5169 0 0 1 1 0 0 11 0 0 1 ... 0 0 0 0
5170 2 7 1 0 2 1 28 2 0 8 ... 0 0 0 0
In [77]: df.isna().sum()
Out[77]: the 0
to 0
ect 0
and 0
for 0
..
military 0
allowing 0
ff 0
dry 0
Prediction 0
Length: 3001, dtype: int64
localhost:8888/notebooks/ML/ML_2.ipynb 3/7
07/08/2024, 16:34 ML_2 - Jupyter Notebook
localhost:8888/notebooks/ML/ML_2.ipynb 4/7
07/08/2024, 16:34 ML_2 - Jupyter Notebook
In [79]: X = df.drop(columns='Prediction',axis = 1)
Y = df['Prediction']
In [81]: KN = KNeighborsClassifier
knn = KN(n_neighbors=7)
knn.fit(x_train, y_train)
y_pred = knn.predict(x_test)
/home/comp/anaconda3/lib/python3.9/site-packages/sklearn/neighbor
s/_classification.py:228: FutureWarning: Unlike other reduction fu
nctions (e.g. `skew`, `kurtosis`), the default behavior of `mode`
typically preserves the axis it acts along. In SciPy 1.11.0, this
behavior will change: the default value of `keepdims` will become
False, the `axis` over which the statistic is taken will be elimin
ated, and the value None will no longer be accepted. Set `keepdims
` to True or False to avoid this warning.
mode, _ = stats.mode(_y[neigh_ind, k], axis=1)
Prediction:
[0 1 0 ... 0 0 0]
In [83]: M = metrics.accuracy_score(y_test,y_pred)
print("KNN accuracy: ", M)
In [84]: C = metrics.confusion_matrix(y_test,y_pred)
print("Confusion matrix: ", C)
model.fit(x_train, y_train)
y_pred = model.predict(x_test)
localhost:8888/notebooks/ML/ML_2.ipynb 6/7
07/08/2024, 16:34 ML_2 - Jupyter Notebook
In [87]: sc = metrics.accuracy_score(y_test,y_pred)
print("SVM accuracy: ", sc)
model.fit(x_train, y_train)
y_pred = model.predict(x_test)
/home/comp/anaconda3/lib/python3.9/site-packages/sklearn/linear_mo
del/_logistic.py:814: ConvergenceWarning: lbfgs failed to converge
(status=1):
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
In [ ]:
localhost:8888/notebooks/ML/ML_2.ipynb 7/7