Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
3 views
ML Practical 2
Computer Engineering machine learning practical 2
Uploaded by
shital
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save ml practical 2 For Later
Download
Save
Save ml practical 2 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
3 views
ML Practical 2
Computer Engineering machine learning practical 2
Uploaded by
shital
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save ml practical 2 For Later
Carousel Previous
Carousel Next
Save
Save ml practical 2 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 6
Search
Fullscreen
71287, 10:38 PM In [1]: In [2]: In [3]: out [3]: In [4]: out[4]: In [5]: In [6]: out [6]: In [7]: import pandas as pd Gf = pd.read_csv(“enails.csv") df. shape (5172, 3¢@2) Unites -Jupyter Notebook df.head() Email mall the to ect and for of a you how connevey lay valid lay Instruct 0 Fri yg go 1 0 OO 2 0 0 Enal 1 mal gts 6 68 2 102 1 2 ° Email 2 fl 9 9 1 0 00 8 0 0 3 Fm 9 5 2 0 5 1 2 10 0 aml 7 gt 4 6 2 or ° 0 5 rows x 3002 columns df.drop([ "Email No.*, ‘Prediction'], axis = 1) GF{ 'Prediction'] xoshape (5172, 3008) x.info()
Rangeindex: 5172 entries, © to 5171 Colunns: 3800 entries, the to dry dtypes: intea(3ee@) mmenory usage: 118.4 ¥B localhost 8888inotebooks/Untiledipynb?kemel_name=pythond 1871287, 10:38 PM Uniitles -Jupyter Notebook In [8]: x.dtypes Out(s8}: the inte4 to intea ect ‘intea and ‘intea for intea infrastructure ‘intea military ‘intea allowing ‘intea ff intea dry ‘intea Length: 3000, dtype: object In [9]: set(x.dtypes) out[9]: {dtype('intea" )} In [11]: import seaborn as. sns sns. -countplot(x =y) out{11]:
count Prediction In [12]: y.value_counts() out[12]: @ 1 3672 150 Name: Prediction, dtype: inte localhost 8888inotebooks/Untiledipynb?kemel_name=pythond71287, 10:38 PM In [15]: In [16]: out [16]: In [17]: In [18]: out [18]: In [19]: out[19]: In [21]: out(21]: In [22]: In [23]: In [24]: out [24]: In [25]: localhost 8888inatebooks/Untiledipynb?kemel Unites -Jupyter Notebook from sklearn. preprocessing import MinMaxScaler scaler = MinMaxScaler() x_scaled = scaler.fit_transform(x) x scaled array({[9. 1e 1 De 8. L [0.03809524, '0.09848485, 0.06705539, .. @. 1 (@. : 28. , 8. 1 {e. : » 8. el e. 1 (@.00952381, @.0530303 , @. aoe @. 1 [9.104769 , 0.18181818, @.01166181, .. @. PD) from sklearn.model_selection import train_test_split train_test_split( 25) x train, x_test, y train, y_test x_scaled,y, random_state=0, test_size x scaled. shape (5172, 3000) x_train. shape (3879, 300) x_test.shape (1293, 3000) from sklearn.neighbors import kKNeighborsClassifier knn = KNeighborsClassifier(n_neighbors=5) kan.fit(x_train, y_train) + KNeighbor$Classifier _kveighborsclassifier() y_pred = kan.predict(x test) pame=python’ @. , @.00877193, @ , @ ’ @.00877193, @ , a671287, 10:38 PM Uniitles -Jupyter Notebook In [27]: from sklearn.metrics import ConfusionMatrixDisplay, accuracy_score from sklearn.metrics import classification_report In [3@]: ConfusionMatrixDisplay.from_predictions (y_test, y_pred) Out [30]:
700 600 500 400 True label 300 200 100 Predicted label In [32]: y_test.value_counts() out(32]: @ 929 1 364 Name: Prediction, dtype: intea In [33]: accuracy_score(y_test, y_pred) out[33]: @,871616395978345, In [34]: print(classification_report(y test, y_pred)) precision recall f1-score support @ 0.98 0.84 0.90 929 1 0.78 0.95 0.81 364 accuracy 0.87 1293 macro avg 0.84. 0.89 0.85 1293 weighted avg 2.90 0.87 0.88 1293 localhost 8888inotebooks/Untiledipynb?kemel_name=pythond71287, 10:38 PM In [39]: import numpy as np import matplotlib.pyplot as plt In [41]: error = [] for k in range(1,41): kan knn.fit(x_train, y_train) pred = knn.predict(x_test) error .append(np.mean(pred In [42]: error out(42]: [@.10827532869296211, @.19982211910286156, .12296983758700696, @.11523588553750967, 0.12838360402165508, @.1214230471771075, @.15158546017014696, @.14849187935034802, @.17246713070378963, @.16705336426914152, @.1871616395978345, @.18329466357308585, @.21500386697602475, @.21345767656612528, @.22815158546017014, @.2266047950502707, @.23588553750966745, @.23356535189481825, @.2459396751740139, @.24361948955916474, @.2559938128383604, @.2552204176334107, @.2699149265274555, @.2691415313225058, @.2822892498066512, 0.28306264501160094, 0.2954369682907966, @.2923433874709977, 0. 3039443155452436, 0. 300077339520495, 0. 30549110595514306, @.30549110595514306, @. 31245166279969067, @.31245166279969067, 0. 3194122196442382, @.317092034029389, @.32637277648878577, @.32559938128383603, 0. 33410672853828305, 0. 3325599381283836] localhost 8888inotebooks/Untiledipynb?kemel_name=pythond KNeighborsClassifier(n_neighbor: Unites -Jupyter Notebook y_test)) 5671287, 10:38 PM In [43]: In [44]: out [44]: In [45]: In [47]: out [47]: In [48]: In [49]: In [50]: out (se): In [51]: In [53]: out [53]: In [ ]: localhost 8888inatebooks/Untiledipynb?kemel Unites -Jupyter Notebook knn = KNeighborsClassifier(n_neighbors=1) knn. fit(x_train,y_train) . kNeighbor$Classifier kNeighborsClassifier(n_neighbor: y_pred = knn.predict(x_test) accuracy_score(y_test, y_pred) @.8917246713070379 from sklearn.svm import SVC svm = SVC(kernel= 'linear') sym. Fit(x_train, y_train) + vc Svc(kernelle' Linear") yipred = svm.predict(x test) accuracy_score(y_test, y_pred) @.9767981438515081 pame=python’ 6s
You might also like
CP4252 Machine Learning Lab Manual
PDF
No ratings yet
CP4252 Machine Learning Lab Manual
33 pages
ML2 (1)
PDF
No ratings yet
ML2 (1)
2 pages
ML 2 16
PDF
No ratings yet
ML 2 16
6 pages
02 - Email - Spam - Ipynb - Colab
PDF
No ratings yet
02 - Email - Spam - Ipynb - Colab
11 pages
Assignment no 2 _ML_output
PDF
No ratings yet
Assignment no 2 _ML_output
4 pages
KNN SVM
PDF
No ratings yet
KNN SVM
2 pages
mnbnmnbnnmbbhhuyrgh
PDF
No ratings yet
mnbnmnbnnmbbhhuyrgh
3 pages
ML Lab Programs (1-13)
PDF
No ratings yet
ML Lab Programs (1-13)
44 pages
Case Study - Classifier
PDF
No ratings yet
Case Study - Classifier
5 pages
It - S All About Neighbors - Completed
PDF
No ratings yet
It - S All About Neighbors - Completed
14 pages
Week10 KNN Practical
PDF
No ratings yet
Week10 KNN Practical
4 pages
ML practical Kiranjot 6-10
PDF
No ratings yet
ML practical Kiranjot 6-10
10 pages
Machine Learning With Python - Machine Learning Algorithms - KNN
PDF
No ratings yet
Machine Learning With Python - Machine Learning Algorithms - KNN
15 pages
ML Lab Programs (1-12)
PDF
No ratings yet
ML Lab Programs (1-12)
35 pages
Decision Tree
PDF
No ratings yet
Decision Tree
9 pages
ML 3 & 4 Notes
PDF
No ratings yet
ML 3 & 4 Notes
18 pages
Machine Learning Lab New
PDF
No ratings yet
Machine Learning Lab New
14 pages
Titanic Akshaya
PDF
No ratings yet
Titanic Akshaya
12 pages
KNN Clearly Explained 1696688332
PDF
No ratings yet
KNN Clearly Explained 1696688332
7 pages
Here's An Visualization of The K-Nearest Neighbors Algorithm
PDF
No ratings yet
Here's An Visualization of The K-Nearest Neighbors Algorithm
5 pages
Risss ML Record 6
PDF
No ratings yet
Risss ML Record 6
6 pages
LAB-4 Report
PDF
No ratings yet
LAB-4 Report
21 pages
ML Lab Mannual
PDF
No ratings yet
ML Lab Mannual
29 pages
Assignment 5 - SourceCode - Ipynb - Colab
PDF
No ratings yet
Assignment 5 - SourceCode - Ipynb - Colab
4 pages
ML practical Lovepreet 6-10
PDF
No ratings yet
ML practical Lovepreet 6-10
10 pages
ML LAB Manual
PDF
No ratings yet
ML LAB Manual
28 pages
Name: Mussab Bin Shahid Sap-Id: 2024 Assignment: Machine-Learning
PDF
No ratings yet
Name: Mussab Bin Shahid Sap-Id: 2024 Assignment: Machine-Learning
5 pages
ML Practical 205160694034
PDF
No ratings yet
ML Practical 205160694034
33 pages
Project-4 (KNN CLASSIFICATION) (2) PRANAB
PDF
No ratings yet
Project-4 (KNN CLASSIFICATION) (2) PRANAB
2 pages
ML Cheatsheet
PDF
No ratings yet
ML Cheatsheet
4 pages
ML practical Kunal 6-10
PDF
No ratings yet
ML practical Kunal 6-10
10 pages
ML LAB Rec
PDF
No ratings yet
ML LAB Rec
9 pages
Machine Learning Lab
PDF
No ratings yet
Machine Learning Lab
13 pages
MACHINE LEARNING LAB MANUAL
PDF
No ratings yet
MACHINE LEARNING LAB MANUAL
36 pages
SPPUML5
PDF
No ratings yet
SPPUML5
4 pages
ML Lab Manual (1-10) FINAL
PDF
No ratings yet
ML Lab Manual (1-10) FINAL
34 pages
bda 3.1
PDF
No ratings yet
bda 3.1
2 pages
KNN_colab_illustration
PDF
No ratings yet
KNN_colab_illustration
5 pages
K-Nearest Neighbor On Python Ken Ocuma
PDF
100% (2)
K-Nearest Neighbor On Python Ken Ocuma
9 pages
Activity 01: Python Set/s of Source Code Use in The Activity (Paste Below)
PDF
No ratings yet
Activity 01: Python Set/s of Source Code Use in The Activity (Paste Below)
2 pages
pratham ML
PDF
No ratings yet
pratham ML
14 pages
ML practical Manjot 6-10
PDF
No ratings yet
ML practical Manjot 6-10
10 pages
Machine Learning Cheatsheet
PDF
No ratings yet
Machine Learning Cheatsheet
5 pages
Practice Test
PDF
No ratings yet
Practice Test
12 pages
AIML_ECE304_Assign-2_kartikeya_Kandpal_Ajitesh_S.ipynb - Colab
PDF
No ratings yet
AIML_ECE304_Assign-2_kartikeya_Kandpal_Ajitesh_S.ipynb - Colab
4 pages
ML Lab
PDF
No ratings yet
ML Lab
7 pages
indexdw (1)
PDF
No ratings yet
indexdw (1)
34 pages
Exercise and Experiment 3
PDF
No ratings yet
Exercise and Experiment 3
14 pages
LabProgram 8 K-Nearest Neighbour Classifier
PDF
No ratings yet
LabProgram 8 K-Nearest Neighbour Classifier
3 pages
ML Lab PT
PDF
No ratings yet
ML Lab PT
25 pages
210596_ML_Labtask5.ipynb_k - Colab
PDF
No ratings yet
210596_ML_Labtask5.ipynb_k - Colab
8 pages
ML Practical 2D
PDF
No ratings yet
ML Practical 2D
6 pages
Scikit-Learn: Scikit-Learn Is An Open Source Python Library That
PDF
100% (1)
Scikit-Learn: Scikit-Learn Is An Open Source Python Library That
1 page
Machine Learning Lab (17CSL76)
PDF
No ratings yet
Machine Learning Lab (17CSL76)
48 pages
Machine Learning Algorithms (Python & R) PDF
PDF
No ratings yet
Machine Learning Algorithms (Python & R) PDF
11 pages
machinelearning
PDF
No ratings yet
machinelearning
26 pages
ml_labmanual (3)
PDF
No ratings yet
ml_labmanual (3)
33 pages
program
PDF
No ratings yet
program
19 pages