I have two lists. One is target and another is predicted values in a binary classification. The target is always zero. And I have to plot the results of the prediction against target in such a way, that when I get a value of 1 in prediction, then i need to plot it with a black dot on a square plane. The plane should contain white area (which means it has both target and prediction as zero) and black dots (in case of target zero but prediction as one). How can I achieve this? Thanks for the help in advance. Something like this :

enter image description here


1 Answer 1


Well since the points would be shown when the target is zero and the predicted value is $1$, then all the plots would be located in the same place and would overlap. So I think you can give a random value for these points and then plot them.

If the white space is the density of $(0,0)$ values and depicts the ratio of $(0,0)$ points, then you should change the size of the figure or the points. Do you want to do so?

import numpy as np
import matplotlib.pyplot as plt
predicted = list([random.choice([0,1]) for i in range(100)])
target = np.zeros(100)

#adding a random value to the predicted and random values
randomed_predicted = [random.random() for i in range(predicted.count(1))]
randomed_target = [random.random() for i in range(len(randomed_predicted))]
plt.gca().axes.get_yaxis().set_visible(False) #hiding the yaxis labels
plt.gca().axes.get_xaxis().set_visible(False) #hiding the xaxis labels 
plt.scatter(randomed_target, randomed_predicted, c="black")

enter image description here

  • 1
    $\begingroup$ Yes this would get me in the right direction. Thanks. $\endgroup$ May 23, 2019 at 14:56
  • $\begingroup$ You're welcome, but you sure know that if the ratio of black dots comparing the white area is considered to represent the actual ratio of (0,1) points to (0,0) this plot and code should be changed. $\endgroup$ May 23, 2019 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.