# Introduction to K-Nearest Neighbors

In this lesson of the machine learning fundamentals course, we’ll learn about k-nearest neighbors, which is a useful machine learning technique. __Machine learning__ is a process of discovering patterns in existing data to make predictions.

To learn how k-nearest neighbors works, we will explore AirBnB data to find optimal rental pricing — low enough to be competitive, but not so low that we miss out on potential revenue.

In the real world, you would likely use `scikit-learn` to implement the k-nearest neighbors algorithm. But understanding how this algorithm works “under the hood” will help you understand when to apply it, so in this lesson we will implement the algorithm by hand.

As we work through the AirBnB pricing question, we will walk through the entire machine learning workflow — from selecting a feature to testing the model — so you can see what it’s like to explore a problem like a data scientist would.

As with all our courses, you will be asked to apply what you’re learning in our in-browser app, which will also check your answers so you can ensure you’ve fully mastered each concept.

## Objectives

- The basics of the machine learning workflow.
- How the k-nearest neighbors algorithm works.
- The role of Euclidean distance in machine learning.

## Lesson Outline

- Problem definition
- Introduction to the data
- K-nearest neighbors
- Euclidean distance
- Calculate distance for all observations
- Randomizing, and sorting
- Average price
- Function to make predictions
- Next steps
- Takeaways

Get started for free

No credit card required.

**Already have an account?** Sign in →

By creating an account you agree to accept our terms of use and privacy policy.