why is unsupervised learning said to be learning probability distribution? In the book Deep Learning by Ian Goodfellow et al., it is mentioned that

unsupervised learning involves observing several examples
of a random vector x, and attempting to implicitly or explicitly learn the probability distribution p(x)

However when I think about the typical unsupervised algorithms such as clustering and anomaly detection, I fail to understand why such algorithms are learning $p(x)$. For example in anomaly detection, is it not more accurate to say that it is learning $p(Y|X)$ where Y = 1 if the data is an anomaly and 0 otherwise?


For example in anomaly detection, is it not more accurate to say that it is learning $p(Y|X)$ where Y = 1 if the data is an anomaly and 0 otherwise?

If that was the case, how would this differ from classification? In anomaly detection you don't have labels, or have insufficient labels to treat this as classification. In such a case, you don't observe $Y$ so cannot learn $p(Y|X)$ from the data. Instead, you observe only $X$ and can learn $p(X)$, so you could make judgements like "$x'$ is not alike what we observed for $X$" (anomaly), or "$x'$ looks like the data $X$ that we previously observed". We can think of those as of probabilistic statements that $\Pr(X = x')$ is small. The models themselves can either be probabilistic and return the predictions in terms of probabilities or can do this indirectly by telling us what is the distance between $x'$ and the rest of the data. In each case, the model that is able to tell us things like this needs to have a notion of the underlying probability distribution, hence we say it learned to approximate the distribution.
