plt.scatter(X [:50,0],X [:50,1],color ='red',marker ='o',label ='setosa')

问题描述 投票:-2回答:1

关于plt.scatter,我有一个noobie问题。

我正在研究一些机器学习教程,我们正在分析两朵花的花瓣长度。

df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data', header = None)
print(df.tail())

y = df.iloc[0:100,4].values                         #This is going to print out the 5th column of the dataset.


y = np.where(y == 'Iris-setosa', -1, 1)             #Where y has 'Iris-setosa' in there, it is going to yield a -1. Else it is going to yield a 1.


X = df.iloc[0:100, [0,2]].values                    #1st and 3rd column of the Iris dataset online
                                           #printout the 1st and 3rd

plt.scatter(X[:50,0],     X[:50, 1],    color = 'red',  marker = 'o', label = 'setosa')


plt.scatter(X[50:100, 0], X[50:100, 1], color = 'blue', marker = 'x', label = 'versicolor')

我不太明白为什么每个plt.scatter线,有两个X [:50,0]和X [:50,1]。那是什么意思?我认为plt.scatter用于在进行散点图时显示一种类型的项目。就像我认为它会像它一样。你知道从第0行到第50行,你想要分散某个花,所以它只是X [:50,0]等等......

提前感谢您对此的任何意见..

enter image description here

python pandas numpy matplotlib machine-learning
1个回答
0
投票

数据存储在2×50阵列中。因此X [50,0]可以是50叶子的宽度,而X [1,50]可以是相同50叶子的长度。因此,您可以绘制宽度与长度的关系图。该组合包括一个绘图集。数据将用红色圆圈表示。

© www.soinside.com 2019 - 2024. All rights reserved.