KNN Classification in Python

3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€44.05
List Price:  €61.68
You save:  €17.62
£37.58
List Price:  £52.62
You save:  £15.03
CA$69.44
List Price:  CA$97.22
You save:  CA$27.78
A$78.41
List Price:  A$109.78
You save:  A$31.37
S$65.75
List Price:  S$92.05
You save:  S$26.30
HK$387.76
List Price:  HK$542.90
You save:  HK$155.13
CHF 41.54
List Price:  CHF 58.16
You save:  CHF 16.61
NOK kr522.97
List Price:  NOK kr732.21
You save:  NOK kr209.23
DKK kr328.90
List Price:  DKK kr460.49
You save:  DKK kr131.58
NZ$83.99
List Price:  NZ$117.60
You save:  NZ$33.60
د.إ183.61
List Price:  د.إ257.07
You save:  د.إ73.46
৳6,091.40
List Price:  ৳8,528.46
You save:  ৳2,437.05
₹4,271.75
List Price:  ₹5,980.80
You save:  ₹1,709.04
RM218.65
List Price:  RM306.13
You save:  RM87.48
₦80,730.85
List Price:  ₦113,029.65
You save:  ₦32,298.80
₨14,091.30
List Price:  ₨19,728.96
You save:  ₨5,637.65
฿1,677.91
List Price:  ฿2,349.21
You save:  ฿671.30
₺1,920.75
List Price:  ₺2,689.20
You save:  ₺768.45
B$284.04
List Price:  B$397.68
You save:  B$113.64
R945.21
List Price:  R1,323.38
You save:  R378.16
Лв86.13
List Price:  Лв120.59
You save:  Лв34.45
₩71,921.98
List Price:  ₩100,696.53
You save:  ₩28,774.54
₪180.85
List Price:  ₪253.20
You save:  ₪72.35
₱2,814.26
List Price:  ₱3,940.19
You save:  ₱1,125.93
¥7,179.56
List Price:  ¥10,051.96
You save:  ¥2,872.40
MX$983.64
List Price:  MX$1,377.18
You save:  MX$393.53
QR182.75
List Price:  QR255.87
You save:  QR73.11
P686.29
List Price:  P960.87
You save:  P274.57
KSh6,463.70
List Price:  KSh9,049.70
You save:  KSh2,586
E£2,547.49
List Price:  E£3,566.69
You save:  E£1,019.20
ብር6,681.17
List Price:  ብር9,354.18
You save:  ብር2,673
Kz45,590.88
List Price:  Kz63,830.88
You save:  Kz18,240
CLP$46,812.37
List Price:  CLP$65,541.06
You save:  CLP$18,728.69
CN¥364.27
List Price:  CN¥510.01
You save:  CN¥145.74
RD$2,975.10
List Price:  RD$4,165.38
You save:  RD$1,190.28
DA6,619.03
List Price:  DA9,267.17
You save:  DA2,648.14
FJ$112.99
List Price:  FJ$158.20
You save:  FJ$45.20
Q386.10
List Price:  Q540.58
You save:  Q154.47
GY$10,489.05
List Price:  GY$14,685.51
You save:  GY$4,196.46
ISK kr6,375.22
List Price:  ISK kr8,925.82
You save:  ISK kr2,550.60
DH464.99
List Price:  DH651.02
You save:  DH186.03
L862.86
List Price:  L1,208.08
You save:  L345.21
ден2,708.74
List Price:  ден3,792.46
You save:  ден1,083.71
MOP$400.53
List Price:  MOP$560.77
You save:  MOP$160.24
N$935.59
List Price:  N$1,309.90
You save:  N$374.31
C$1,838.46
List Price:  C$2,573.99
You save:  C$735.53
रु6,841.02
List Price:  रु9,577.98
You save:  रु2,736.95
S/185.02
List Price:  S/259.04
You save:  S/74.02
K207.50
List Price:  K290.52
You save:  K83.01
SAR187.51
List Price:  SAR262.53
You save:  SAR75.02
ZK1,410.01
List Price:  ZK1,974.13
You save:  ZK564.11
L219.29
List Price:  L307.02
You save:  L87.73
Kč1,100.07
List Price:  Kč1,540.19
You save:  Kč440.12
Ft17,940.87
List Price:  Ft25,118.65
You save:  Ft7,177.78
SEK kr485.01
List Price:  SEK kr679.06
You save:  SEK kr194.04
ARS$58,712.48
List Price:  ARS$82,202.17
You save:  ARS$23,489.69
Bs346.41
List Price:  Bs485.01
You save:  Bs138.59
COP$215,920.08
List Price:  COP$302,305.39
You save:  COP$86,385.31
₡25,270.56
List Price:  ₡35,380.81
You save:  ₡10,110.24
L1,299.69
List Price:  L1,819.68
You save:  L519.98
₲401,259.06
List Price:  ₲561,794.79
You save:  ₲160,535.73
$U2,086.69
List Price:  $U2,921.54
You save:  $U834.84
zł188.24
List Price:  zł263.56
You save:  zł75.31
Already have an account? Log In

Transcript

Okay in Python we can also create a KNN classifier. If we want to predict a categorical variable we'll create our K neighbors classifier here we want to predict or those are numeric variable, we can import this attaining attainable requests are here. So for classification, so we have to employ all these k neighbor classifier from SK learn dot neighbors. Okay, so how do I create a models so I can create some t 90s model equal k neighbor? A neighbor cross c fire okay then set the neighbors to some tea lie Okay neighbors to maybe around our tree them border of the x train and y train okay there we are we can do prediction using something like this or the dot p d s s tests okay. And I have to pre my prediction even though there will be nothing to play and then to know the body bodies si have changed to minus one in why I have to to four, so minus one that means I'm going to need the first variable the second variable variable.

So minus one. So, I will take the first four variable and then four is our data fee variable, so 01234 Okay. So, that is why and then I trained I create a training set and testing set. So, training set is around 80% testing set is around 20%. So as train why train as test and then White House and then this is the Model Model equal k neighbor classifier, the number of neighbors is tree and then model dot feed, training set S train y train prediction, model dot predict as test. So, I print a prediction and I run this code can get a prediction something like this

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.