X
is a 100x2 vector that contains sepal and pethal length data for 2 kinds of flowers. y
is a 100x1 vector that contains label values for my data: -1 and 1. I create a meshgrid, then I plotted my meshgrid using countourf
method and now I load the data in the meshgrid with this code:
for idx, cl in enumerate (np.unique(y)):
plt.scatter (x=X[y == cl, 0], y= X[y == cl, 1], alpha=0.8, c=colors[idx], marker= markers [idx], label = cl, edgecolor = 'black')
alpha, colors, marker, edgecolor
are just secondary things. Also np.unique(y) = [-1 1]
.
My question is, Why [y==cl,0]
is a false and [y==,1]
is a true argument? and, How using ==
can I classifier my data?
In the for loop, cl
loops over the two unique values of y
i.e. [-1, 1]
. So in the first loop iteration, cl=-1
and y == cl
returns the rows where your y values are -1. Therefore, [y == cl, 0]
returns the locations where y is -1 and the data is the first column (index 0) which is Sepal length. Similarly, [y == cl, 1]
returns the locations where y is -1 and the data is the second column (index 1) which is Petal length.
The same applies in the second iteration of the loop when cl
is 1.