zoukankan      html  css  js  c++  java
  • 用三种不同颜色表示的三个决策边界

    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()

  • 相关阅读:
    NOIP2006代码及简析
    设计模式的原则
    UML应用
    关系
    活动图
    状态图
    UML概序
    UML基本图示
    用例
    介绍一个好的英语学习网站!
  • 原文地址:https://www.cnblogs.com/wei23/p/13151105.html
Copyright © 2011-2022 走看看