Introduction k-nearest neighbors (knn) algorithm is a type of supervised ml algorithm which can be used for both classification as well as regression predictive problems. However



Download 0,73 Mb.
Pdf ko'rish
bet4/17
Sana31.12.2021
Hajmi0,73 Mb.
#222840
1   2   3   4   5   6   7   8   9   ...   17
Bog'liq
machine learning with python tutorial-139-150

Implementation in Python 

As we know K-nearest neighbors (KNN) algorithm can be used for both classification as 

well as regression. The following are the recipes in Python to use KNN as classifier as well 

as regressor: 



 


Machine Learning with Python 

        


 

 

 



133 

 

KNN as Classifier 

First, start with importing necessary python packages:

 

import numpy as np   



import matplotlib.pyplot as plt   

import pandas as pd   

Next, download the iris dataset from its weblink as follows: 

path = "https://archive.ics.uci.edu/ml/machine-learning-

databases/iris/iris.data" 

Next, we need to assign column names to the dataset as follows: 

headernames = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 

'Class'] 

 

Now, we need to read dataset to pandas dataframe as follows: 



dataset = pd.read_csv(path, names=headernames) 

dataset.head()   

 


Download 0,73 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   17




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish