0
$\begingroup$

I am given a dataset with features X and Y and need to learn to classify objects into 2 classes. The corresponding targets for the objects from the dataset are denoted as y:

enter image description here

Top left plot shows X vs Y scatter plot, produced with the following code:

# y is a target vector
plt.scatter(X, Y, c = y)

I use target variable y to colorcode the points.

The other three plots were produced by jittering X and Y values:

def jitter(data, stdev):
  N = len(data)
  return data + np.random.randn(N) * stdev
  
# sigma is a given std. dev. for Gaussian distribution
plt.scatter(jitter(X, sigma), jitter(Y, sigma), c = y)

That is, I add Gaussian noise to the features before drawing scatter plot.

I did that because I've read that some say that it is beneficial to jitter variables before building a scatter plot, or even a model. I don't understand why. To my mind,

target is completely determined by coordinates (x,y), i.e. the label of the point is completely determined by point's position (x,y). Saying the same in other words: if we only had two features (x,y), we could build a classifier, that would accurate 100% of time.

So I don't understand the point of jittering ...

It is always beneficial to jitter variables before building a scatter plot? Is it beneficial for a model?

$\endgroup$
2
  • 3
    $\begingroup$ See stats.stackexchange.com/questions/506540 for an example of what goes wrong with scatterplots and how jittering is one way to address the problem. $\endgroup$
    – whuber
    Commented Feb 3, 2021 at 18:53
  • 4
    $\begingroup$ In your un-jittered plot it is not possible to tell the difference between a single observation and several observations over-plotted at the same point. Sometimes, jittering can resolve the effects of multiple data points plotted at exactly the same location. This seems true in your example, but jittering does not reveal association between x and y--not because jittering is useless, but because there does not seem to be any significant association to reveal. (For my taste, the jittering in your plot at lower-right is far too extreme.) Please do look at @whuber's link. $\endgroup$
    – BruceET
    Commented Feb 3, 2021 at 19:18

0

Your Answer

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