Reputation: 321
In this code:
from sklearn.datasets import make_moons
import matplotlib.pyplot as plt
X, y = make_moons(n_samples=100, random_state=123)
plt.scatter(X[y==0,0], X[y==0,1], color='red', marker='^', alpha=0.5)
plt.scatter(X[y==1,0], X[y==1,1], color='blue', marker='o', alpha=0.5)
plt.show()
What exactly does the operation X[y==0,0]
do to the dataset X
?
Upvotes: 1
Views: 3731
Reputation: 1
(X[y==0,0], X[y==0,1]) explaination:
X[y==0,0]
'y==0', This puts a condition that wherever y is 0. i.e only take those instances where y is 0
',0' , This is element of X at index 0 in a list or X[0]
X[y==0,0], This whole expression is the x co-ordinate and it says, 'Only in those lists where y is 0(ignore rest of the lists), take X[0] as x-coodinate.
X[y==0,1], This whole expression is the y co-ordinate and it says, 'Only in those lists where y is 0(ignore rest of the lists), take X[1] as y-coodinate.
(X[y==0,0], X[y==0,1]), This whole expression is the x and y cordinates of a point in the scatterplot
Upvotes: -1
Reputation: 870
In this case, both the variables X
and y
are of type numpy.ndarray.
And looking at the variables we can see that the variable X
has shape (100, 2). This means that X
has 100 rows and 2 columns. Similarly, y
has shape (100,) and is thus just a 1-D vector. It happens to hold only 0s and 1s.
Thus X[y==0,0]
finds all the rows of X that have a y
value of 0 (y == 0
), and are in the first column of X
Upvotes: 4