When you first encounter machine learning methods, or statistics in general, you are often directly presented with a sample from a data set $D = \{ (x_1, y_1), (x_2,y_2), \cdots, (x_n,y_n)\}$.
The general paradigm which ignores theory is that you then split into training/testing data, train your model, then evaluate on testing data. What many practitioners do not think about, but that is important for understanding theory, but even more importantly for understanding your data, is what is the data generating process.
The data $D$ is generally assumed to be $n$ samples from some joint distribution $P(X,Y)$ satisfying certain assumptions (below). As a concrete example, we could imagine your data is generated as follows:
$$\begin{align} X &\sim \textrm{Unif}[0,1]\\ Y &= X + \epsilon \\ \epsilon &\sim N(0,1)\end{align}$$
In this case, points of $X$ are sampled from the standard uniform distribution, $Y$ is generated by applying the linear function + noise. We of course do not know the data generating process ahead of time but we make certain assumptions about it that Brian's answer above already describes: eg. data is I.I.D and training and testing data come from the same distribution. If these assumptions were false (eg. train and test data are different distributions) then our model trained on training data would have no predictive value on testing data. Our goal in modeling the data is to try to find the relationship between $Y$ and $X$ when the equations above are not privy to us (and probably don't even exist in some analytical form).
Assuming our data comes from a fixed reference distribution $P(X,Y)$ is actually a strong assumption, and it can be confusing for people new to the field to think through. It is reasonable to ask - why should my data be generated by some fixed reference distribution at all? How can I verify this assumption? I won't go into more details here, but I bring this up just to point out that the assumptions here aren't "obvious" and requires very careful consideration by the model builder. Let's just say that both the theory and application of ML in practice would fail if this wasn't true.
Concrete Practical Example: A common issue that practitioners in industry must deal with is Covariate Shift where variables shift over time.
- For example, a model trained for facial recognition may be trained on predominantly male faces, and then fail to generalize to females when applied to the general population. In this case $P_{\textrm{train}}(X,Y) \neq P_{\textrm{test}}(X,Y)$. This is one of the reasons models need to be trained on samples representative of the population in which it will be used.
- Another example is considering a model that is used to predict if someone will click on an ad. If this model is then used to generate new ads that are shown to users, it is actually changing the underlying distribution of the data generating process itself. This is a common challenge faced in deploying ML models in production and there are many resources available for you to read about it.
This answer is far from complete but hopefully helps point you in the right direction for thinking through these questions.