KNN algo matplotlib

plt.scatter(X[:,0],X[:,1],c=Y)
When I am executing this, it’s showing error and when I am using color argument it is coloring both with same color. How do I distinguish two classes?

first of all its a single scatter plot and ti will only represent one class to plot the other class u will have to do it like this:
rom matplotlib import pyplot as plt
plt.scatter(X[:,0],Y,color=‘red’)
plt.scatter(X[:,1],Y,color=‘blue’)
plt.show()

Then how did it worked in Sir’s code?

plt.scatter(X[:,0],Y,color=‘red’)
plt.scatter(X[:,1],Y,color=‘blue’)

This one’s not working, please look at sir’s knn algo code and then tell me

@Anshuman-Anshuman-89 the color argument c can take two types of values
Either it can be string like “green”, “red” or it can be a sequence.

in My case it is sequence Y = [0,1,1,1,0,0,0,0,…] is sequence of lables for all data points. Plot function automatically allots one color correponding to the label value.

@yash97your code is not correct assuming X is the training matrix with features x1 and x2.

1 Like