KNN实验
这篇博文我们来学习KNN 具体文件与代码可以从我的GitHub地址获取 https://github.com/liuzuoping/MeachineLearning-Case k-means实验 import numpy as np import matplotlib . pyplot as plt from sklearn . cluster import KMeans from sklearn . datasets import make_blobs plt . figure ( figsize = ( 12 , 12 ) ) # 选取样本数量 n_samples = 1500 # 选取随机因子 random_state = 170 # 获取数据集 X , y = make_blobs ( n_samples = n_samples , random_state = random_state ) # 聚类数量不正确时的效果 y_pred = KMeans ( n_clusters = 2 , random_state = random_state ) . fit_predict ( X ) plt . subplot ( 221 ) plt . scatter ( X [ y_pred == 0 ] [ : , 0 ] , X [ y_pred == 0 ] [ : , 1 ]