Assignment no 2 _ML_output
Assignment no 2 _ML_output
October 8, 2024
[36]: #ASSIGNMENT NO 2
#Use K-Nearest Neighbors and Support Vector Machine for classification. Analyze␣
↪their performance.
[38]: df=pd.read_csv('/home/pc13/Documents/Email/emails.csv')
[51]: df.head() #it returns the first five rows of the DataFrame df
[51]: 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
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5172 entries, 0 to 5171
Columns: 3002 entries, Email No. to Prediction
1
dtypes: int64(3001), object(1)
memory usage: 118.5+ MB
#X typically represents the feature set (input data) used for training a␣
↪machine learning model.
#y usually represents the target variable (output data) that the model aims to␣
↪predict.
2
[57]: KNeighborsClassifier()
[61]: cm
#The variable cm contains the confusion matrix generated by the␣
↪confusion_matrix function.
3
[69]: svc = SVC(C=1.0,kernel='rbf',gamma='auto')
svc.fit(X_train,y_train)
y_pred2 = svc.predict(X_test)
#you're creating and training a Support Vector Classifier (SVC) using the␣
↪Radial Basis Function (RBF) kernel
cm = confusion_matrix(y_test, y_pred2)
#Creating the Confusion Matrix
[70]: cm
#The variable cm contains the confusion matrix generated from your SVC model's␣
↪predictions
[ ]: