0% found this document useful (0 votes)
3 views

ML Assignment8

Machine Learning paper

Uploaded by

rp7895798
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

ML Assignment8

Machine Learning paper

Uploaded by

rp7895798
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ml-assignment-2-1

October 31, 2024

[3]: import pandas as pd

df = pd.read_csv('/content/emails.csv')
df

[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

jay valued lay infrastructure military allowing ff dry \


0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 1 0
2 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 1 0
… … … … … … … .. …
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

1
… …
5167 0
5168 0
5169 1
5170 1
5171 0

[5172 rows x 3002 columns]

[4]: df.isnull().sum().sum()

[4]: 0

[5]: # iloc[1:5 , 1:3] it means select 1 to 4 rows and 1 to 2 columns


X = df.iloc[: , 1:3001]
X

[5]: the to ect and for of a you hou in … enhancements \


0 0 0 1 0 0 0 2 0 0 0 … 0
1 8 13 24 6 6 2 102 1 27 18 … 0
2 0 0 1 0 0 0 8 0 0 4 … 0
3 0 5 22 0 5 1 51 2 10 1 … 0
4 7 6 17 1 5 2 57 0 9 3 … 0
… … .. … … … .. … … … .. … …
5167 2 2 2 3 0 0 32 0 0 5 … 0
5168 35 27 11 2 6 5 151 4 3 23 … 0
5169 0 0 1 1 0 0 11 0 0 1 … 0
5170 2 7 1 0 2 1 28 2 0 8 … 0
5171 22 24 5 1 6 5 148 8 2 23 … 0

connevey jay valued lay infrastructure military allowing ff dry


0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 1 0
2 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 1 0
… … … … … … … … .. …
5167 0 0 0 0 0 0 0 0 0
5168 0 0 0 0 0 0 0 1 0
5169 0 0 0 0 0 0 0 0 0
5170 0 0 0 0 0 0 0 1 0
5171 0 0 0 0 0 0 0 0 0

[5172 rows x 3000 columns]

[6]: y = df.iloc[: , -1]


y

2
[6]: 0 0
1 0
2 0
3 0
4 0
..
5167 0
5168 0
5169 1
5170 1
5171 0
Name: Prediction, Length: 5172, dtype: int64

[7]: from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

[8]: from sklearn.svm import SVC

svm_model = SVC()
svm_model.fit(X_train,y_train)

[8]: SVC()

[32]: y_predict = svm_model.predict(X_test)


y_predict

[32]: array([0, 0, 0, …, 1, 1, 0])

[18]: from sklearn import metrics

print("Accuracy : ", metrics.accuracy_score(y_test, y_predict))


# print("Confucion matrics :" , metrics.confusion_matrix(y_test, y_predict))
report = metrics.classification_report(y_test,y_predict,output_dict=True)

print("precision : ", report['1']['precision'])


print("recall : ", report['1']['recall'])
print("F1-Score : ", report['1']['f1-score'])

Accuracy : 0.7963917525773195
precision : 0.8716577540106952
recall : 0.35824175824175825
F1-Score : 0.5077881619937694

[31]: input = X.iloc[5169]

3
input_data = pd.DataFrame([input])

svm_model.predict(input_data)

[31]: array([0])

[36]: from sklearn.neighbors import KNeighborsClassifier

knn_model = KNeighborsClassifier()
knn_model.fit(X_train,y_train)

[36]: KNeighborsClassifier()

[37]: y_predict_knn = knn_model.predict(X_test)


y_predict_knn

[37]: array([0, 0, 0, …, 1, 1, 0])

[40]: from sklearn import metrics

print("Accuracy :" ,metrics.accuracy_score(y_test, y_predict_knn))

report_knn = metrics.classification_report(y_test,␣
↪y_predict_knn,output_dict=True)

print("Precision : ",report['1']['precision'])
print("recall : ",report['1']['recall'])
print("f1-score : ", report['1']['f1-score'])

Accuracy : 0.8646907216494846
Precision : 0.8716577540106952
recall : 0.35824175824175825
f1-score : 0.5077881619937694

You might also like