• 用三种不同颜色表示的三个决策边界


    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.colors import ListedColormap
    from sklearn import datasets
    from sklearn.neighbors import KNeighborsClassifier
    iris = datasets.load_iris()
    x = iris.data[:,:2]
    y = iris.target
    x_min,x_max = x[:,0].min() - .5,x[:,0].max() + .5
    y_min,y_max = x[:,1].min() - .5,x[:,1].max() + .5
    cmap_light = ListedColormap(['#AAAAFF','#AAFFAA','#FFAAAA'])
    h = .02
    xx,yy = np.meshgrid(np.arange(x_min,x_max,h),np.arange(y_min,y_max,h))
    knn = KNeighborsClassifier()
    knn.fit(x,y)
    Z = knn.predict(np.c_[xx.ravel(),yy.ravel()])
    Z = Z.reshape(xx.shape)
    plt.figure()
    plt.pcolormesh(xx,yy,Z,cmap=cmap_light)
    plt.scatter(x[:,0],x[:,1],c=y)
    plt.xlim(xx.min(),xx.max())
    plt.ylim(yy.min(),yy.max())
    plt.show()

  • 相关阅读:
    类与对象
    类的声明与实例化
    面向对象的基本概念
    css下拉导航栏代码
    面向对象的三大特性
    面向对象三大基本特性,五大基本原则
    dom事件
    PHP 流程
    权限 查找
    留言板案例
  • 原文地址:https://www.cnblogs.com/wei23/p/13151105.html
Copyright © 2020-2023  润新知