  We propose and analyse numerical algorithms based on weighted least squares
for the approximation of a real-valued function on a general bounded domain
$\Omega \subset \mathbb{R}^d$. Given any $n$-dimensional approximation space
$V_n \subset L^2(\Omega)$, the analysis in [6] shows the existence of stable
and optimally converging weighted least-squares estimators, using a number of
function evaluations $m$ of the order $n \log n$. When an
$L^2(\Omega)$-orthonormal basis of $V_n$ is available in analytic form, such
estimators can be constructed using the algorithms described in [6,Section 5].
If the basis also has product form, then these algorithms have computational
complexity linear in $d$ and $m$. In this paper we show that, when $\Omega$ is
an irregular domain such that the analytic form of an $L^2(\Omega)$-orthonormal
basis is not available, stable and quasi-optimally weighted least-squares
estimators can still be constructed from $V_n$, again with $m$ of the order $n
\log n$, but using a suitable surrogate basis of $V_n$ orthonormal in a
discrete sense. The computational cost for the calculation of the surrogate
basis depends on the Christoffel function of $\Omega$ and $V_n$. Numerical
results validating our analysis are presented.
