[TOC] 更新.更全的<机器学习>的更新网站,更有python.go.数据结构与算法.爬虫.人工智能教学等着你:https://www.cnblogs.com/nickchen121/ k近邻算法(鸢尾花分类) 一.导入模块 import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import ListedColormap from matplotlib.font_manager import Fon…
KNN的函数写法 import numpy as np from math import sqrt from collections import Counter def KNN_classify(k,X_train,y_train,x): assert 1<=k<X_train.shape[0],"k must be valid" assert X_train.shape[0] == y_train.shape[0],\ "the size of X_train…