Skip to content

Commit bec654b

Browse files
authored
Update build-a-k-nearest-neighbor-model-with-p5js.mdx
1 parent 7c7d26b commit bec654b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

projects/build-a-k-nearest-neighbor-model-with-p5js/build-a-k-nearest-neighbor-model-with-p5js.mdx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: Build a K-Nearest Neighbor Model with p5.js
2+
title: Build a K-Nearest Neighbors Model with p5.js
33
author: Alex Kuntz
44
uid: ZjTU0yoJGgNolU9xIJGOR3bxYKm2
55
datePublished: 2025-09-08
6-
description: Learn how to build a K-Nearest Neighbor (KNN) model from scratch using p5.js
6+
description: Learn how to build a K-Nearest Neighbors (KNN) model from scratch using p5.js
77
header: https://i.imgur.com/RmZDc8j.gif
88
bannerImage: https://i.imgur.com/RmZDc8j.gif
99
published: live
@@ -101,12 +101,12 @@ Let's begin by creating a `class` to represent our points. Each point will have:
101101
```js
102102
class Point {
103103
constructor() {
104-
this.x = Math.random() * width; // A random value along the x axis
105-
this.y = Math.random() * height; // A random value along the y axis
106-
this.class = floor(Math.random() * 2) // A random class: either 0 or 1
104+
this.x = Math.random() * width; // A random value along the x axis
105+
this.y = Math.random() * height; // A random value along the y axis
106+
this.class = floor(Math.random() * 2); // A random class: either 0 or 1
107107
}
108108

109-
display() {
109+
display() {
110110
stroke(0);
111111
strokeWeight(2);
112112

@@ -185,7 +185,7 @@ function classifyMouse() {
185185
let distances = [];
186186

187187
for (var i = 0; i < points.length; i++) {
188-
// TODO: Find the distance between each point and the mouse.
188+
// TODO... Find the distance between each point and the mouse.
189189
}
190190
}
191191
```
@@ -254,7 +254,7 @@ Now we just need to call it! At the bottom of the `draw()` function, call `class
254254

255255
Congrats on reaching the end of this project! You made a working KNN visualizer!
256256

257-
You now hopefully have a better understanding of how a K-Nearest Neighbor model works under the hood!
257+
You now hopefully have a better understanding of how a K-Nearest Neighbor model works under the hood.
258258

259259
### Bonus Challenges
260260

@@ -265,6 +265,10 @@ Want to level it up? Try these bonus challenges:
265265
- Add your own style! Rather than red and green points, you could draw your points as wizard 🧙‍♂️ or warrior ⚔️ emojis (calling back to our original example). Or come up with your own theme! Could you do something interesting with the background?
266266
- KNN models can work with multi-class problems. Rather than simply red and green points, what if you had red, green, and blue points? Refactor your code so your visualization works with _any_ number of classes.
267267

268+
### Video Walkthrough
269+
270+
<iframe width="560" height="315" src="https://www.youtube.com/embed/uq0kvzBX6uU?si=r4GbxX5BBG953-Ad" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
271+
268272
### Additional Resources
269273

270274
- [Codédex's Machine Learning course](https://www.codedex.io/machine-learning)

0 commit comments

Comments
 (0)