Density of uniform distribution over two disjoint squares A probability distribution $P$ over $X \times \{0, 1\}$. $P$ can be defined in term of its marginal distribution over $X$ , which we will denote by $P_X$ and the conditional labeling distribution, which is defined by the regression function
$$
\mu(x) = P_{
(x,y) \sim P}
[y = 1 \mid x]
$$
Consider a 2-dimensional Euclidean domain, that is $X = \mathbb R^2$, and the
following process of data generation: The marginal distribution over $X$ is uniform over two square areas $[1, 2] \times [1, 2] \cup [3, 4] \times [1.5, 2.5]$. Points in the first
square $Q_1 = [1, 2] \times [1, 2]$ are labeled 0 (blue) and points in the second square
$Q_2 = [3, 4] \times [1.5, 2.5]$ are labeled 1 (red).

Describe the density function of $P_X$, and the regression function, Bayes predictor and Bayes risk of $P$.
In the image, I have defined the Probability density function. I am having trouble in figuring out the pdf of this function in 2 dimensional space.
The density $p_R$ of the uniform distribution over a rectangle $R$ is given by $p_R(x) = 0$ if $x \notin R$, and $p_R(x) = 1/\mathit{area}(R)$ otherwise. Indeed, up to scaling the distribution must have this form, and the choice $1/\mathit{area}(R)$ ensures that $p_R$ is a distribution.
In your case, you have a mixture of two such distributions: with probability $1/2$ you take a uniform point in $[1,2] \times [1,2]$, and with probability $1/2$ you take a uniform point in $[3,4] \times [1.5,2.5]$. The density function of the mixture is the average of the density functions of the individual distributions.