<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/understanding-k-nearest-neighbors-yyeet6myj" -->

---
title: Understanding k-Nearest Neighbors | daily.dev
description: kNN is a lazy machine learning algorithm that doesn&#x27;t require training. It makes predictions by calculating distances between new samples and training samples,...
canonical: https://daily.dev/posts/understanding-k-nearest-neighbors-yyeet6myj
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Understanding k-Nearest Neighbors | daily.dev
og:description: kNN is a lazy machine learning algorithm that doesn&#x27;t require training. It makes predictions by calculating distances between new samples and training samples,...
og:url: https://daily.dev/posts/understanding-k-nearest-neighbors-yyeet6myj
og:image: https://api.daily.dev/og/posts/YyeeT6MYJ.png
og:image:alt: Understanding k-Nearest Neighbors
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Understanding k-Nearest Neighbors

**[The Palindrome](https://daily.dev/sources/palindrome)** · 8 min read · 17 upvotes · 0 comments

## Summary

kNN is a lazy machine learning algorithm that doesn't require training. It makes predictions by calculating distances between new samples and training samples, finding the k nearest neighbors, and classifying the new sample based on a majority vote from those neighbors. The value of 'k' is important as it determines the number of samples considered for prediction. The choice of 'k' can have a significant impact on the outcome. Different distance metrics, such as Euclidean distance, Manhattan distance, and Minkowski distance, can be used in kNN depending on the problem. Cosine similarity is another distance metric that can be useful for high-dimensional data.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://thepalindrome.org/p/understanding-k-nearest-neighbors>

---

Tags: [#machine-learning](https://daily.dev/tags/machine-learning), [#deep-learning](https://daily.dev/tags/deep-learning), [#classification](https://daily.dev/tags/classification)

[View this post on daily.dev](https://daily.dev/posts/understanding-k-nearest-neighbors-yyeet6myj)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Understanding k-Nearest Neighbors","url":"https://daily.dev/posts/understanding-k-nearest-neighbors-yyeet6myj","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/understanding-k-nearest-neighbors-yyeet6myj"},"datePublished":"2024-05-09T19:40:38.174Z","dateModified":"2024-05-09T19:40:36.223Z","description":"kNN is a lazy machine learning algorithm that doesn't require training. It makes predictions by calculating distances between new samples and training samples,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/224557b402aa2d1b0aae25b0f9804ca3?_a=AQAEuiZ","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/224557b402aa2d1b0aae25b0f9804ca3?_a=AQAEuiZ","isAccessibleForFree":true,"articleSection":"The Palindrome","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"The Palindrome","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/cfdfeb66e965438eb7a539c98ba83494","url":"https://daily.dev/sources/palindrome"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/understanding-k-nearest-neighbors-yyeet6myj","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":17},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"machine-learning,deep-learning,classification","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"The Palindrome","item":"https://daily.dev/sources/palindrome"},{"@type":"ListItem","position":3,"name":"Understanding k-Nearest Neighbors"}]}
```

