Online Course
Machine Learning with K-Nearest Neighbors

Master K-Nearest Neighbors using Python’s scikit-learn library: from theoretical foundations to practical applications

4.9

808 reviews on
4153 students already enrolled
  • Institute of Analytics
  • The Association of Data Scientists
  • E-Learning Quality Network
  • European Agency for Higher Education and Accreditation
  • Global Association of Online Trainers and Examiners

Skill level:

Intermediate

Duration:

2 hours
  • Lessons (1 hour)
  • Practice exams (25 minutes)

CPE credits:

2
CPE stands for Continuing Professional Education and represents the mandatory credits a wide range of professionals must earn to maintain their licenses and stay current with regulations and best practices. One CPE credit typically equals 50 minutes of learning. For more details, visit NASBA's official website: www.nasbaregistry.org

Accredited

certificate

What you learn

  • Fully grasp the inner workings and application of the KNN algorithm.
  • Get acquainted with different distance metrics.
  • Generate random datasets for practice and experimentation.
  • Understand the pros and cons of the KNN algorithm.
  • Plan, execute, and deliver a complete ML project independently.

Topics & tools

TheoryPythonMachine LearningProgrammingMachine and Deep Learning

Your instructor

Course OVERVIEW

Description

CPE Credits: 2 Field of Study: Information Technology
Delivery Method: QAS Self Study
Practical knowledge of various machine learning algorithms is essential for machine learning enthusiasts and experts alike. In this course, we focus extensively on one of the most intuitive and easy-to-implement ML algorithms out there – K-nearest neighbors, or KNN for short. Step by step, we will first lay the foundations and expand your mathematical toolbox. Then, you will progress to coding and using Python’s scikit-learn library to solve a randomly generated classification problem. Finally, you will apply KNN to a couple of regression tasks. In other words – you will learn all the subtleties that should be considered when applying the KNN algorithm in your future practice.

Prerequisites

  • Python (version 3.8 or later), Streamlit library, OpenAI API key, and a code editor or IDE (e.g., VS Code or Jupyter Notebook)
  • Intermediate Python skills are required.
  • Familiarity with basic statistics and linear algebra is helpful but not mandatory.

Curriculum

17 lessons 3 exercises 2 exams
  • 1. KNN Classifier – Theory
    13 min
    In this introductory section, we motivate the usage of a K-Nearest Neighbor classifier and give 2 intuitive examples. Following that is a short math refresher where we talk about the various ways in which the distance between 2 points in space can be defined. This would later serve us well when building our KNN model in Python.
    13 min
    In this introductory section, we motivate the usage of a K-Nearest Neighbor classifier and give 2 intuitive examples. Following that is a short math refresher where we talk about the various ways in which the distance between 2 points in space can be defined. This would later serve us well when building our KNN model in Python.
  • 2. Setting up the Environment
    5 min
    In advance of the hands-on part of the course, this section guides you through the installation process of relevant Python packages.
    5 min
    In advance of the hands-on part of the course, this section guides you through the installation process of relevant Python packages.
  • 3. KNN Classifier – Practical Example
    37 min
    To apply your skills in practice, you will first learn how to generate a random set of points, distribute them into 3 classes, and place them on the coordinate system. We will then use this dataset to train and test a KNN classification algorithm with the help of Python’s scikit-learn library. We will look at some edge cases that can arise during the classification process and discover how to handle them. Next, we will guide you through the process of building the so-called decision regions, which are a great way of visualizing the performance of your model. Finally, we will find out how to choose the best model parameters using a technique called ‘grid search’.
    37 min
    To apply your skills in practice, you will first learn how to generate a random set of points, distribute them into 3 classes, and place them on the coordinate system. We will then use this dataset to train and test a KNN classification algorithm with the help of Python’s scikit-learn library. We will look at some edge cases that can arise during the classification process and discover how to handle them. Next, we will guide you through the process of building the so-called decision regions, which are a great way of visualizing the performance of your model. Finally, we will find out how to choose the best model parameters using a technique called ‘grid search’.
  • 4. KNN Regressor
    19 min
    Continuing the practical part of the course, we will dive into solving regression tasks using the K-Nearest Neighbors method. Similar to what we did in the previous section, we will tackle this problem by generating 2 random datasets. One would represent a linear problem, while the other would be non-linear. We will apply a linear (parametric) model and a KNN (non-parametric model) on both datasets and argue which one performs better.
    19 min
    Continuing the practical part of the course, we will dive into solving regression tasks using the K-Nearest Neighbors method. Similar to what we did in the previous section, we will tackle this problem by generating 2 random datasets. One would represent a linear problem, while the other would be non-linear. We will apply a linear (parametric) model and a KNN (non-parametric model) on both datasets and argue which one performs better.
  • 5. Pros and Cons of the KNN Algorithm
    7 min
    In this final section of the course, the pros and cons of the KNN algorithm are discussed at length. We will study this method’s limitations, together with its strong sides.
    7 min
    In this final section of the course, the pros and cons of the KNN algorithm are discussed at length. We will study this method’s limitations, together with its strong sides.
  • 6. Course exam
    30 min
    30 min

Free lessons

What does the course cover?

1.1 What does the course cover?

7 min

Motivation

1.2 Motivation

2 min

Math Prerequisites: Distance Metrics

1.4 Math Prerequisites: Distance Metrics

4 min

Setting up the Environment

2.1 Setting up the Environment

1 min

Installing the Relevant Packages

2.2 Installing the Relevant Packages

4 min

Random Dataset: Generating the Dataset

3.1 Random Dataset: Generating the Dataset

3 min

Start for free

ACCREDITED certificates

Craft a resume and LinkedIn profile you’re proud of—featuring certificates recognized by leading global institutions.

Earn CPE-accredited credentials that showcase your dedication, growth, and essential skills—the qualities employers value most.

  • Institute of Analytics
  • The Association of Data Scientists
  • E-Learning Quality Network
  • European Agency for Higher Education and Accreditation
  • Global Association of Online Trainers and Examiners

Certificates are included with the Self-Study learning plan.

A LinkedIn profile mockup on a mobile screen showing Parker Maxwell, a Certified Data Analyst, with credentials from 365 Data Science listed under Licenses & Certification. A 365 Data Science Certificate of Achievement awarded to Parker Maxwell for completing the Data Analyst career track, featuring accreditation badges and a gold “Verified Certificate” seal.

How it WORKS

  • Lessons
  • Exercises
  • Projects
  • Practice exams
  • AI mock interviews

Lessons

Learn through short, simple lessons—no prior experience in AI or data science needed.

Try for free

Exercises

Reinforce your learning with mini recaps, hands-on coding, flashcards, fill-in-the-blank activities, and other engaging exercises.

Try for free

Projects

Tackle real-world AI and data science projects—just like those faced by industry professionals every day.

Try for free

Practice exams

Track your progress and solidify your knowledge with regular practice exams.

Try for free

AI mock interviews

Prep for interviews with real-world tasks, popular questions, and real-time feedback.

Try for free

Student REVIEWS

A collage of student testimonials from 365 Data Science learners, featuring profile photos, names, job titles, and quotes or video play icons, showcasing diverse backgrounds and successful career transitions into AI and data science roles.