本文实现一个最简单的knn二分类算法,加深对knn算法的理解,代码如下:
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 2 18:40:00 2019
@author: 联想310-15
"""
import numpy as np
import matplotlib.pyplot as plt # 画图用
import math
# 训练集
train_x = [[3.39, 2.33],
[3.11, 1.78],
[1.34, 3.36],
[3.58, 4.67],
[2.28, 2.86],
[7.42, 4.69],
[