美文网首页
鸢尾花散点图

鸢尾花散点图

作者: C_Z_Q_ | 来源:发表于2020-01-06 21:02 被阅读0次
    #import warnings
    #warnings.filterwarnings('ignore')
    from sklearn import datasets
    from matplotlib import pyplot as plt
    iris = datasets.load_iris()
    iris.keys
     <function Bunch.keys>
    #iris['DESCR']
    #print(iris.DESCR)
    X= iris.data
    X.ndim
    2
    X.shape
    (150, 4)
    X.size
    600
    iris.feature_names
    ['sepal length (cm)',
     'sepal width (cm)',
     'petal length (cm)',
     'petal width (cm)']
    y= iris.target
    y
    array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
           0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
           1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
           1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
           2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
           2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])
    iris.target_names
    array(['setosa', 'versicolor', 'virginica'], dtype='<U10')
    
    #绘制萼片额度
    
    X = X[:,:2]
    X[y==0,:0]
    array([], shape=(50, 0), dtype=float64)
    
    #绘制散点图
    
    plt.scatter(X[y==0,0],X[y==0,1],color = 'r') #setosa
    plt.scatter(X[y==1,0],X[y==1,1],color = 'b') #versicolor
    plt.scatter(X[y==2,0],X[y==2,1],color = 'g') #virginica
    plt.show()
    
    效果图
    y= iris.target
    y
    array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
           0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
           1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
           1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
           2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
           2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])
    #绘制萼片维度
    X = iris.data[:,2:]
    X[y==0,0]
    array([1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.5, 1.5, 1.6, 1.4,
           1.1, 1.2, 1.5, 1.3, 1.4, 1.7, 1.5, 1.7, 1.5, 1. , 1.7, 1.9, 1.6,
           1.6, 1.5, 1.4, 1.6, 1.6, 1.5, 1.5, 1.4, 1.5, 1.2, 1.3, 1.5, 1.3,
           1.5, 1.3, 1.3, 1.3, 1.6, 1.9, 1.4, 1.6, 1.4, 1.5, 1.4])
    plt.scatter(X[y==0,0],X[y==0,1],color = 'r') #setosa
    plt.scatter(X[y==1,0],X[y==1,1],color = 'b') #versicolor
    plt.scatter(X[y==2,0],X[y==2,1],color = 'g') #virginica
    plt.show()
    

    相关文章

      网友评论

          本文标题:鸢尾花散点图

          本文链接:https://www.haomeiwen.com/subject/ixhlactx.html