\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb}
\usepackage{algorithm,algpseudocode}
\usepackage{bm}
\usepackage{hyperref}
\usepackage{float}
\usepackage{subcaption}
\usepackage{enumitem}
\usepackage{xcolor}
\definecolor{darkgreen}{rgb}{0.0, 0.5, 0.0}
\definecolor{aaltoBlue}{RGB}{0, 51, 102}
\definecolor{pinegreen}{cmyk}{0.92,0,0.59,0.25}
\definecolor{royalblue}{cmyk}{1,0.50,0,0}
\definecolor{lavander}{cmyk}{0,0.48,0,0}
\definecolor{violet}{cmyk}{0.79,0.88,0,0}
\definecolor{lightblue}{RGB}{173, 216, 230}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc,arrows.meta,positioning,fit,shapes.geometric,shapes.misc,intersections,patterns,decorations.pathreplacing,backgrounds,matrix}
\usepgfplotslibrary{fillbetween,groupplots}
\setcounter{secnumdepth}{-\maxdimen}
% Long unbreakable tokens (the ISO/IEC author names in citations, term names
% in the title) otherwise overflow the margin by a few points; a modest
% emergency stretch lets TeX loosen the paragraph instead.
\emergencystretch=2em
\usepackage{mleftright}
% Project macros used by this entry (auto-extracted).
\newcommand{\condnumber}[1]{\kappa\!\left(#1\right)}
\newcommand{\dataset}{\mathcal{D}}
\newcommand{\defeq}{:=}
\newcommand{\eigval}[1]{\lambda_{#1}}
\newcommand{\feature}{x}
\newcommand{\featuredim}{d}
\newcommand{\featureidx}{j}
\newcommand{\featuremtx}{\mX}
\newcommand{\featurevec}{\vx}
\newcommand{\iteridx}{t}
\newcommand{\labelvec}{\vy}
\newcommand{\mX}[0]{{\bf X}}
\newcommand{\norm}[1]{\Vert  {#1} \Vert}
\newcommand{\nrfeatures}{\featuredim}
\newcommand{\pinv}[1]{{#1}^{+}}
\newcommand{\reals}{\mathbb{R}}
\newcommand{\sampleidx}{r}
\newcommand{\samplesize}{m}
\newcommand{\truelabel}{y}
\newcommand{\vr}[0]{{\bf r}}
\newcommand{\vu}[0]{{\bf u}}
\newcommand{\vv}[0]{{\bf v}}
\newcommand{\vw}[0]{{\bf w}}
\newcommand{\vx}[0]{{\bf x}}
\newcommand{\vy}[0]{{\bf y}}
\newcommand{\weight}{w}
\newcommand{\weights}{\vw}

\begin{document}

\section{feature matrix}

\subsection*{Author and editors}
Alexander Jung\textsuperscript{*}, Department of Computer Science, Aalto University, Espoo, Finland (ORCID \mbox{\href{https://orcid.org/0000-0001-7538-0990}{0000-0001-7538-0990}}) \\
Editors: Konstantina Olioumtsevits (ORCID \mbox{\href{https://orcid.org/0000-0003-2697-8659}{0000-0003-2697-8659}}), Ekkehard Schnoor (ORCID \mbox{\href{https://orcid.org/0000-0001-8252-1499}{0000-0001-8252-1499}}), Aalto University, Espoo, Finland \\
\textsuperscript{*}Corresponding author: \href{mailto:alex.jung@aalto.fi}{alex.jung@aalto.fi}

\subsection{Synonyms}
design matrix, data matrix

\subsection{Abstract}
The feature matrix of a dataset collects the
		feature vectors of its data points as its rows, one row
		per data point and one column per feature. Its two most
		basic properties are the number of rows, which is the number of
		data points in the dataset, and the number of columns,
		which is the number of features of each data point. More
		properties of a dataset follow from the singular values
		of its feature matrix. The number of nonzero
		singular values is the rank, and a rank below the
		number of features leaves linear regression with infinitely many
		solutions. The ratio of the largest to the smallest nonzero
		singular value is the condition number of the feature matrix.
		The condition number determines the number of
		gradient descent (GD) steps required by linear regression and its robustness
		against perturbations of the features and labels in
		the training set.

\subsection{Definition}
A weather station at Krems an der
		Donau records eight measurements on each of the $366$ days of the leap
		year $2024$: the lowest,
		highest, and mean air temperature, the humidity, the wind speed, the
		precipitation, the sunshine duration, and the air pressure. Writing
		the eight measurements of one day as a row, and placing the rows of
		the $366$ days under one another, gives a two-dimensional numeric
		array with
		$366$ rows and eight columns. That array is a matrix, the
		feature matrix of the dataset whose data points are the
		$366$ days, and each of its rows is the feature vector of one day. The feature matrix is the form
		in which machine learning (ML) software expects a dataset, and properties
		of the ML methods applied to the dataset, such as
		whether linear regression has a unique solution or how fast gradient descent (GD)
		converges, are determined by it.
		\begin{figure}[H]
		\centering
		\begin{tikzpicture}[scale=0.9,
			every node/.style={font=\footnotesize},
			cell/.style={draw, minimum width=1.32cm, minimum height=0.55cm, inner sep=1pt},
			rowcell/.style={cell, fill=black!12},
			colcell/.style={cell, line width=1.2pt},
			bothcell/.style={cell, fill=black!12, line width=1.2pt}]
			\node[anchor=east] at (-0.81,0.00) {1 Jan};
			\node[colcell] at (0.00,0.00) {$2.6$};
			\node[cell] at (1.32,0.00) {$9.6$};
			\node[cell] at (2.64,0.00) {$6.1$};
			\node[cell] at (3.96,0.00) {$67$};
			\node[cell] at (5.28,0.00) {$1.5$};
			\node[cell] at (6.60,0.00) {$\cdots$};
			\node[anchor=east] at (-0.81,-0.55) {2 Jan};
			\node[bothcell] at (0.00,-0.55) {$-0.6$};
			\node[rowcell] at (1.32,-0.55) {$7.2$};
			\node[rowcell] at (2.64,-0.55) {$3.3$};
			\node[rowcell] at (3.96,-0.55) {$85$};
			\node[rowcell] at (5.28,-0.55) {$0.6$};
			\node[rowcell] at (6.60,-0.55) {$\cdots$};
			\node[anchor=east] at (-0.81,-1.10) {3 Jan};
			\node[colcell] at (0.00,-1.10) {$4.4$};
			\node[cell] at (1.32,-1.10) {$14.3$};
			\node[cell] at (2.64,-1.10) {$9.4$};
			\node[cell] at (3.96,-1.10) {$54$};
			\node[cell] at (5.28,-1.10) {$3.8$};
			\node[cell] at (6.60,-1.10) {$\cdots$};
			\node[anchor=east] at (-0.81,-1.65) {$\vdots$};
			\node[colcell] at (0.00,-1.65) {$\vdots$};
			\node[cell] at (1.32,-1.65) {$\vdots$};
			\node[cell] at (2.64,-1.65) {$\vdots$};
			\node[cell] at (3.96,-1.65) {$\vdots$};
			\node[cell] at (5.28,-1.65) {$\vdots$};
			\node[cell] at (6.60,-1.65) {$\ddots$};
			\node[anchor=east] at (-0.81,-2.20) {31 Dec};
			\node[colcell] at (0.00,-2.20) {$-8$};
			\node[cell] at (1.32,-2.20) {$-1.1$};
			\node[cell] at (2.64,-2.20) {$-4.6$};
			\node[cell] at (3.96,-2.20) {$89$};
			\node[cell] at (5.28,-2.20) {$1$};
			\node[cell] at (6.60,-2.20) {$\cdots$};
			\node[anchor=west, rotate=55] at (-0.12,0.36) {lowest temp.};
			\node[anchor=west, rotate=55] at (1.20,0.36) {highest temp.};
			\node[anchor=west, rotate=55] at (2.52,0.36) {mean temp.};
			\node[anchor=west, rotate=55] at (3.84,0.36) {humidity};
			\node[anchor=west, rotate=55] at (5.16,0.36) {wind speed};
			\draw[decorate, decoration={brace, amplitude=5pt}]
				(-2.25,-2.48) -- (-2.25,0.28)
				node[midway, left=8pt, align=center] {$\samplesize = 366$\\ data points};
			\draw[decorate, decoration={brace, amplitude=5pt, mirror}]
				(-0.66,-2.60) -- (7.26,-2.60)
				node[midway, below=8pt] {$\nrfeatures = 8$ features};
		\end{tikzpicture}
		\caption{The feature matrix of the $366$ days of $2024$ at
			Krems an der Donau: one row per day and one column per
			measurement, with the first three days and the last shown, and
			five of the eight measurements (the precipitation, the sunshine
			duration, and the air pressure are omitted). Temperatures are in
			degrees Celsius, the humidity in percent, and the wind speed in
			meters per second. The shaded row is the transposed
			feature vector of 2 January; the heavily framed column collects
			the lowest temperature of every day
			\label{fig_featuremtx_dict}}
		\end{figure}
		In general, consider a dataset $\dataset$ 
		of $\samplesize$ data points with feature vectors 
		$\featurevec^{(1)}, \,\ldots, \,\featurevec^{(\samplesize)}$, each in
		$\reals^{\nrfeatures}$. 
		Stacking the feature vectors row-wise yields the feature
		matrix:
		$$\featuremtx \defeq \big(\featurevec^{(1)}, \,\ldots, \,\featurevec^{(\samplesize)}\big)^{\top} =
		\begin{pmatrix}
			\feature^{(1)}_{1} & \feature^{(1)}_{2} & \cdots & \feature^{(1)}_{\nrfeatures} \\
			\feature^{(2)}_{1} & \feature^{(2)}_{2} & \cdots & \feature^{(2)}_{\nrfeatures} \\
			\vdots      & \vdots      & \ddots & \vdots \\
			\feature^{(\samplesize)}_{1} & \feature^{(\samplesize)}_{2} & \cdots & \feature^{(\samplesize)}_{\nrfeatures}
		\end{pmatrix}
		\in \reals^{\samplesize \times \nrfeatures} \text{.}$$
		The feature matrix is of size
		$\samplesize \times \nrfeatures$, i.e., it has $\samplesize$ rows
		and $\nrfeatures$ columns. Each row is the transposed
		feature vector of one data point, and each column holds the
		values of one feature for all data points (see
		Fig.~\ref{fig_featuremtx_dict}). Many properties of a dataset,
		and of the learning tasks built from it, are computed from
		$\featuremtx$. The most basic ones are the numbers of rows and
		columns, $\samplesize$ and $\nrfeatures$.
\par
		The feature matrix also defines a linear map. A linear model with
		model parameters $\weights$ from the parameter space
		$\reals^{\nrfeatures}$ predicts
		$\weights^{\top} \featurevec^{(\sampleidx)}$ for the
		$\sampleidx$-th data point, so the $\samplesize$
		predictions are the entries of $\featuremtx \weights$. The
		feature matrix therefore maps each
		$\weights \in \reals^{\nrfeatures}$ to the vector
		$\featuremtx \weights \in \reals^{\samplesize}$, which is
		compared with the label vector
		$\labelvec = \big(\truelabel^{(1)}, \,\ldots,
		\,\truelabel^{(\samplesize)}\big)^{\top} \in \reals^{\samplesize}$.
		Linear regression on a training set with feature matrix
		$\featuremtx$ and label vector $\labelvec$ is the search for a
		vector $\weights$ whose image $\featuremtx \weights$ is
		close to $\labelvec$ in Euclidean norm.
\par
		Linear regression has a unique
		solution only when $\featuremtx$ has full column rank, which
		requires $\samplesize \geq \nrfeatures$
		(Golub and Van Loan, 2013, Sect.~5.3.1) (see
		normal equations). A rank below $\nrfeatures$ leaves
		infinitely many parameter vectors $\weights$ with the same
		training error
		(Hastie et al., 2009, Sect.~3.2), and the one a
		method returns can have a large loss outside the
		training set. Using more features than data points
		(i.e., $\nrfeatures > \samplesize$) forces this case, since then $\featuremtx$ has fewer rows than
		columns, which rules out full column rank.
\par
		More properties of a dataset follow from the
		singular values of its feature matrix
		$\featuremtx$. The singular value decomposition (SVD) can be written as
		(Golub and Van Loan, 2013, Sect.~2.4)
		$$\featuremtx = \sum_{\featureidx=1}^{\min\{\samplesize, \nrfeatures\}}
		\eigval{\featureidx} \vv^{(\featureidx)}
		\big(\vu^{(\featureidx)}\big)^{\top} \text{,}$$
		where the vectors
		$\vv^{(1)}, \,\ldots, \,\vv^{(\min\{\samplesize, \nrfeatures\})} \in \reals^{\samplesize}$
		are orthonormal among themselves, the vectors
		$\vu^{(1)}, \,\ldots, \,\vu^{(\min\{\samplesize, \nrfeatures\})} \in \reals^{\nrfeatures}$
		are orthonormal among themselves. The singular values
		are ordered as
		$\eigval{1} \geq \ldots \geq \eigval{\min\{\samplesize, \nrfeatures\}} \geq 0$.
		The number of nonzero singular values is the rank of
		$\featuremtx$ (Golub and Van Loan, 2013, Cor.~2.4.6). A rank below
		$\nrfeatures$ means that some feature is a linear combination
		of the others and adds no information beyond them. A small but
		nonzero singular value is the approximate form of such a
		dependence. When $\samplesize \geq \nrfeatures$, the
		$\nrfeatures$ right singular vectors form an
		orthonormal basis of $\reals^{\nrfeatures}$, and the
		smallest singular value is the smallest
		Euclidean norm of a linear combination of the feature
		columns with unit-norm coefficients,
		\[
		\eigval{\nrfeatures}
		= \min_{\vu \in \reals^{\nrfeatures}, \, \norm{\vu} = 1}
		\norm{\featuremtx \vu} \text{,}
		\]
		attained at the right singular vector
		$\vu^{(\nrfeatures)}$. The identity holds since a unit-norm $\vu =
		\sum_{\featureidx=1}^{\nrfeatures} c_{\featureidx}
		\vu^{(\featureidx)}$ gives $\norm{\featuremtx \vu}^{2} =
		\sum_{\featureidx=1}^{\nrfeatures} c_{\featureidx}^{2} \eigval{\featureidx}^{2}$,
		a weighted average of the squared singular values. When
		$\nrfeatures > \samplesize$, a unit-norm $\vu$ orthogonal to
		all $\samplesize$ right singular vectors gives
		$\featuremtx \vu = \mathbf{0}$, so the minimum is $0$. A small
		singular value therefore says that some combination of the
		feature columns with unit-norm coefficients is nearly the zero
		vector: the features are nearly collinear, and the right
		singular vector names the combination. For the weather year
		of Fig.~\ref{fig_featuremtx_dict}, with every measurement scaled to
		zero sample mean and unit sample variance, the smallest
		singular value is $0.05$ against a largest of $36.4$. Its
		right singular vector places all of its weight on the lowest, the highest, and the mean temperature,
		with coefficients $-0.37$, $-0.46$, and $0.81$, because the mean
		temperature of a day is the midpoint of its lowest and its highest
		up to a residual with standard deviation $0.03$ degrees. Dropping the mean
		temperature raises the smallest singular value to $4.19$
		(\texttt{pythondemos/featuremtx.py}). The size of a
		singular value depends on the units of the columns, which is
		why the scaling to unit sample variance comes first. The
		squares of the
		singular values are the eigenvalues of
		$\featuremtx^{\top} \featuremtx$, which for features with zero
		sample mean is $\samplesize$ times their sample covariance matrix.
\par
		The same eigenvalues and eigenvectors of
		$\featuremtx^{\top} \featuremtx$ determine principal component analysis (PCA). Its
		dimensionality reduction keeps the eigenvectors of the largest
		eigenvalues as the new features, and the sum over the
		data points of the squared errors of reconstructing the
		feature vectors from them is the sum of the eigenvalues
		dropped (Bishop, 2006, Sect.~12.1.2).
\par
		Another important property of a feature matrix is the
		condition number
		$\condnumber{\featuremtx} = \eigval{1} / \eigval{\operatorname{rank}(\featuremtx)}$,
		the ratio of the largest singular value to the smallest nonzero
		one. For full column rank, it is the ratio of the largest to the
		smallest singular value (Golub and Van Loan, 2013, Sect.~5.3.1).
		The condition number enters linear regression twice: through the number of
		GD steps, and through the robustness of the learned
		model parameters against perturbations of the training set. The
		number that matters in both is its square
		$\condnumber{\featuremtx}^{2}$. The
		objective function
		$f(\weights) = (1/\samplesize) \norm{\featuremtx \weights -
		\labelvec}^{2}$
		has the constant Hessian
		$(2/\samplesize) \featuremtx^{\top} \featuremtx$, whose
		eigenvalues are the squared singular values of
		$\featuremtx$ scaled by $2/\samplesize$. The condition number of
		$\featuremtx^{\top} \featuremtx$ is therefore
		\begin{equation}
			\label{eq_featuremtx_condsq_dict}
			\condnumber{\featuremtx^{\top} \featuremtx} = \condnumber{\featuremtx}^{2} \text{.}
		\end{equation}
\par
		The square \eqref{eq_featuremtx_condsq_dict} determines the
		convergence speed of GD on the empirical risk minimization (ERM) problem of
		linear regression. One
		step with an exact line search multiplies the gap between
		$f\big(\weights^{(\iteridx)}\big)$ and the minimum
		$f\big(\widehat{\weights}\big)$ by at most
		$1 - 1/\condnumber{\featuremtx}^{2}$
		(Boyd and Vandenberghe, 2004, Sect.~9.3.1). The number of steps that
		reaches a given gap therefore grows in proportion to
		$\condnumber{\featuremtx}^{2}$.
\par
		Fig.~\ref{fig_featuremtx_transform_dict} shows this for two
		feature matrices built from the weather measurements of
		Fig.~\ref{fig_featuremtx_dict}. The features are the
		relative humidity and the wind speed, the label is the highest
		temperature, and each has its sample mean removed. In the
		recorded units the condition number is $14.5$. After scaling each
		feature to unit sample variance, it is $1.45$. GD
		starts at the point at distance $\norm{\widehat{\weights}}$
		from $\widehat{\weights}$ for which it is slowest, where the gap
		shrinks per step by exactly the factor in
		\eqref{eq_featuremtx_exactrate_dict} (Boyd and Vandenberghe, 2004, Sect.~9.3.2),
		\begin{equation}
			\label{eq_featuremtx_exactrate_dict}
			f\big(\weights^{(\iteridx+1)}\big) - f\big(\widehat{\weights}\big)
			= \Big( \frac{\condnumber{\featuremtx}^{2} - 1}
			{\condnumber{\featuremtx}^{2} + 1} \Big)^{2}
			\Big( f\big(\weights^{(\iteridx)}\big) - f\big(\widehat{\weights}\big) \Big) \text{.}
		\end{equation}
		From no start does the gap shrink by less, since this factor
		bounds the shrinkage of every
		exact-line-search step on a quadratic objective function
		(Bertsekas, 2016, Prop.~1.3.1). A gap of $10^{-6}$ of the
		initial one then takes $731$ steps in the recorded units and $7$
		after the scaling.
		\begin{figure}[H]
		\begin{center}
		\begin{tikzpicture}
		\begin{axis}[
			width=0.8\linewidth, height=0.46\linewidth,
			axis lines=left, ymode=log,
			xlabel={GD step $\iteridx$},
			ylabel={$\big(f(\weights^{(\iteridx)}) - f^{\star}\big) / \big(f(\weights^{(0)}) - f^{\star}\big)$},
			xmin=0, xmax=50, ymin=1e-12, ymax=2,
			unbounded coords=discard,
			tick label style={font=\small},
			label style={font=\small},
			legend style={draw=none, fill=none, font=\small},
			legend cell align=left,
			legend style={at={(0.97,0.78)}, anchor=north east},
			]
			\addplot[line width=1.2pt]
				table[col sep=comma, x=step, y=recorded]{featuremtx_gdtrace.csv};
			\addlegendentry{recorded units}
			\addplot[line width=1.2pt, dashed]
				table[col sep=comma, x=step, y=scaled]{featuremtx_gdtrace.csv};
			\addlegendentry{unit sample variance}
		\end{axis}
		\end{tikzpicture}
		\end{center}
		\caption{The convergence of GD with an exact line search for
			the features relative humidity and wind speed of the $366$
			days, in their recorded units (solid curve)
			and after scaling each to unit sample variance (dashed
			curve). Shown is the gap between $f\big(\weights^{(\iteridx)}\big)$
			and the minimum $f^{\star} = \min_{\weights \in \reals^{2}} f(\weights)$,
			relative to its initial value, over the first $50$ steps.
			Both runs start at the point at distance $\norm{\widehat{\weights}}$
			from $\widehat{\weights}$ for which GD is slowest; the
			dashed curve ends where the gap falls below $10^{-12}$. Data
			generated by \texttt{pythondemos/featuremtx.py}
			\label{fig_featuremtx_transform_dict}}
		\end{figure}
		The condition number $\condnumber{\featuremtx}$ also governs the
		robustness of the model parameters $\widehat{\weights}$
		delivered by linear regression against perturbations of the
		training set. Let $\featuremtx$
		have full column rank. Linear regression delivers the
		model parameters $\widehat{\weights} = \pinv{\featuremtx} \labelvec$
		with the pseudoinverse
		$\pinv{\featuremtx} = \big(\featuremtx^{\top} \featuremtx\big)^{-1}
		\featuremtx^{\top}$ (Golub and Van Loan, 2013, Sect.~5.5.2). They
		are the unique solution of the normal equations
		$\featuremtx^{\top} \featuremtx \widehat{\weights} =
		\featuremtx^{\top} \labelvec$, which state that the gradient
		of $f$ vanishes at $\widehat{\weights}$.
\par
		Consider perturbations of the training set that change
		$\featuremtx$ to
		$\featuremtx + \delta \featuremtx$ and $\labelvec$ to
		$\labelvec + \delta \labelvec$, with
		$\featuremtx + \delta \featuremtx$ still of full column
		rank, and let $\widehat{\weights} + \delta \widehat{\weights}$
		be the model parameters learned by linear regression on the perturbed
		training set. They solve the normal equations of the
		perturbed training set,
		$$(\featuremtx + \delta \featuremtx)^{\top}
		(\featuremtx + \delta \featuremtx)
		\big(\widehat{\weights} + \delta \widehat{\weights}\big)
		= (\featuremtx + \delta \featuremtx)^{\top}
		(\labelvec + \delta \labelvec) \text{.}$$
		Moving the terms with $\widehat{\weights}$ to the right side and
		using $\featuremtx^{\top} \vr = \mathbf{0}$ for the
		least squares residual
		$\vr = \labelvec - \featuremtx \widehat{\weights}$, which is
		the normal equations of the unperturbed training set, gives
		the exact equation
		$$(\featuremtx + \delta \featuremtx)^{\top}
		(\featuremtx + \delta \featuremtx) \, \delta \widehat{\weights}
		= (\featuremtx + \delta \featuremtx)^{\top}
		\big(\delta \labelvec - \delta \featuremtx \, \widehat{\weights}\big)
		+ \delta \featuremtx^{\top} \vr \text{.}$$
		Solving for $\delta \widehat{\weights}$ applies the
		pseudoinverse of $\featuremtx + \delta \featuremtx$ to the
		noise in the labels and to the noise in the features
		acting on $\widehat{\weights}$, and the inverse of
		$(\featuremtx + \delta \featuremtx)^{\top}
		(\featuremtx + \delta \featuremtx)$ to the noise in the
		features acting on the residual.
\par
		The largest
		singular value of $\pinv{\featuremtx}$ is
		$1 / \eigval{\nrfeatures}$, and that of
		$\big(\featuremtx^{\top} \featuremtx\big)^{-1}$ is
		$1 / \eigval{\nrfeatures}^{2}$
		(Golub and Van Loan, 2013, Sect.~5.3.6). The same holds for
		$\featuremtx + \delta \featuremtx$ with its own smallest
		singular value. Let the largest
		singular value of $\delta \featuremtx$ be at most
		$\varepsilon \eigval{1}$ and the Euclidean norm of
		$\delta \labelvec$ at most $\varepsilon \norm{\labelvec}$, with
		$\varepsilon \, \condnumber{\featuremtx} < 1$. The smallest
		singular value of $\featuremtx + \delta \featuremtx$ is then at
		least $\eigval{\nrfeatures} - \varepsilon \eigval{1}$
		(Golub and Van Loan, 2013, Cor.~8.6.2), and taking Euclidean
		norms in the exact equation gives the perturbation bound
		\begin{equation}
		\label{eq_featuremtx_bound}
		\norm{\delta \widehat{\weights}} \leq
		\frac{\varepsilon \, \condnumber{\featuremtx}}
		{1 - \varepsilon \, \condnumber{\featuremtx}}
		\Big( \frac{\norm{\labelvec}}{\eigval{1}}
		+ \norm{\widehat{\weights}} \Big)
		+ \frac{\varepsilon \, \condnumber{\featuremtx}^{2}}
		{\big(1 - \varepsilon \, \condnumber{\featuremtx}\big)^{2}}
		\frac{\norm{\vr}}{\eigval{1}} \text{.}
		\end{equation}
		The bound \eqref{eq_featuremtx_bound} holds for every perturbation
		with $\varepsilon \, \condnumber{\featuremtx} < 1$.
\par
		The bound \eqref{eq_featuremtx_bound} carries over to the
		prediction for any given feature vector $\featurevec$,
		such as that of a test data point. The learned linear model
		predicts $\featurevec^{\top} \widehat{\weights}$ before and
		$\featurevec^{\top} \big(\widehat{\weights} + \delta \widehat{\weights}\big)$
		after the perturbation. The prediction therefore changes by
		$\featurevec^{\top} \delta \widehat{\weights}$, and the
		Cauchy-Schwarz inequality bounds this change by
		\begin{equation}
		\label{eq_featuremtx_predbound}
		\big| \featurevec^{\top} \delta \widehat{\weights} \big|
		\leq \norm{\featurevec} \, \norm{\delta \widehat{\weights}}
		\leq \norm{\featurevec} \Bigg(
		\frac{\varepsilon \, \condnumber{\featuremtx}}
		{1 - \varepsilon \, \condnumber{\featuremtx}}
		\Big( \frac{\norm{\labelvec}}{\eigval{1}}
		+ \norm{\widehat{\weights}} \Big)
		+ \frac{\varepsilon \, \condnumber{\featuremtx}^{2}}
		{\big(1 - \varepsilon \, \condnumber{\featuremtx}\big)^{2}}
		\frac{\norm{\vr}}{\eigval{1}} \Bigg) \text{.}
		\end{equation}
		The change of the prediction is therefore at most
		$\norm{\featurevec}$ times the right-hand side of the bound
		\eqref{eq_featuremtx_bound}, and grows with the norm of the
		feature vector.
\par
		Fig.~\ref{fig_featuremtx_spread_dict} shows the robustness of
		$\widehat{\weights}$ against perturbations on a related but
		different and smaller dataset, the first days of the twelve
		months of $2024$, twelve of the rows of
		Fig.~\ref{fig_featuremtx_dict}. Each day has the feature vector
		$\featurevec = (1, \feature)^{\top}$ with $\feature$ its lowest
		temperature, and its highest temperature as the label. A
		hypothesis of the linear model then has intercept
		$\weight_{1}$ and slope $\weight_{2}$, and the feature matrix has a
		column of ones and the column of the lowest temperatures. Its
		condition number is $14.9$, and the least squares residual is
		$0.20$ times the norm of $\labelvec$.
\par
		Two constructions of a perturbation of relative size
		$\varepsilon = 0.01$ are compared. The first is chosen adversarially,
		to make the change of the model parameters learned by
		linear regression as large as possible:
		$\delta \featuremtx = -\varepsilon \eigval{1} \vv^{(2)} \big(\vu^{(2)}\big)^{\top}$
		and $\delta \labelvec = \pm \varepsilon \norm{\labelvec} \vv^{(2)}$,
		with the sign for which $\widehat{\weights}$ moves more. It changes
		$\widehat{\weights}$ by norm $2.23$, which is $64$ percent of
		the right-hand side of the bound \eqref{eq_featuremtx_bound}. The
		second
		construction uses $100$ realizations of random
		$\delta \featuremtx$ and $\delta \labelvec$. They are generated
		with independent and identically distributed (i.i.d.) Gaussian random variables (RVs) as their entries and then
		normalized so that the largest
		singular value of $\delta \featuremtx$ is
		$\varepsilon \eigval{1}$ and the Euclidean norm of
		$\delta \labelvec$ is $\varepsilon \norm{\labelvec}$. The largest
		change among the $100$ realizations is $1.17$, which is $34$
		percent of the right-hand side of the bound
		\eqref{eq_featuremtx_bound}.
\par
		For a day with lowest temperature $\feature$ the feature vector
		$(1, \feature)^{\top}$ has
		norm $\sqrt{1 + \feature^{2}}$. By the prediction bound
		\eqref{eq_featuremtx_predbound} the prediction therefore
		changes by at most $\sqrt{1 + \feature^{2}}$ times the right-hand
		side of the bound \eqref{eq_featuremtx_bound}: $3.5$ degrees at
		$\feature = 0$ and $69$ degrees at $\feature = 20$. The two dotted curves in
		Fig.~\ref{fig_featuremtx_spread_dict}(a) trace that bound and leave the plotted
		range. The hypotheses learned from the random
		perturbations stay within $1.6$ degrees of the learned
		hypothesis over the plotted range, and the hypothesis
		after the adversarial construction within $3.1$ degrees. Panel
		(b) repeats the comparison for $\varepsilon$ from
		$5 \cdot 10^{-4}$ to $5 \cdot 10^{-2}$. The adversarial
		construction reaches more than half of the right-hand side of the
		bound \eqref{eq_featuremtx_bound} up to $\varepsilon = 0.02$, the
		random construction less than half at every $\varepsilon$.
		\begin{figure}[H]
		\begin{center}
		\begin{tikzpicture}
		\begin{axis}[
			width=0.78\linewidth, height=0.56\linewidth,
			axis lines=left,
			xlabel={lowest temperature of the day ($^{\circ}$C)},
			ylabel={highest temperature of the day ($^{\circ}$C)},
			xmin=-6, xmax=20, ymin=-10, ymax=45,
			tick label style={font=\small},
			label style={font=\small},
			legend style={draw=none, fill=none, font=\small,
				at={(0.5,-0.28)}, anchor=north},
			legend columns=1,
			legend cell align=left,
			]
			\addplot[fill=black!35, draw=black!70, line width=0.4pt, area legend]
				table[col sep=comma, x=x, y=y]{featuremtx_fan.csv} -- cycle;
			\addlegendentry{hypotheses after one hundred random constructions}
			\addplot[only marks, mark=*, mark size=1.6pt]
				table[col sep=comma, x=x, y=y]{featuremtx_oneline.csv};
			\addlegendentry{the twelve days}
			\addplot[line width=1.2pt]
				table[col sep=comma, x=x, y=fit]{featuremtx_lines.csv};
			\addlegendentry{least squares hypothesis}
			\addplot[line width=1.2pt, dashed]
				table[col sep=comma, x=x, y=adv]{featuremtx_lines.csv};
			\addlegendentry{hypothesis after the adversarial construction}
			\addplot[line width=1.2pt, dash pattern=on 1.2pt off 1.8pt]
				table[col sep=comma, x=x, y=bndhi]{featuremtx_lines.csv};
			\addlegendentry{bound \eqref{eq_featuremtx_predbound}}
			\addplot[line width=1.2pt, dash pattern=on 1.2pt off 1.8pt, forget plot]
				table[col sep=comma, x=x, y=bndlo]{featuremtx_lines.csv};
		\end{axis}
		\end{tikzpicture}
		\\[1mm]
		{\small (a)}
		\\[3mm]
		\begin{tikzpicture}
		\begin{axis}[
			width=0.78\linewidth, height=0.46\linewidth,
			axis lines=left, xmode=log, ymode=log,
			ymin=5e-3, ymax=2000,
			xlabel={relative size $\varepsilon$ of the perturbation},
			ylabel={change $\norm{\delta \widehat{\weights}}$},
			tick label style={font=\small},
			label style={font=\small},
			legend style={draw=none, fill=none, font=\small,
				at={(0.5,-0.28)}, anchor=north},
			legend cell align=left,
			]
			\addplot[line width=1.2pt]
				table[col sep=comma, x=eps, y=bound]{featuremtx_perturb.csv};
			\addlegendentry{right-hand side of \eqref{eq_featuremtx_bound}}
			\addplot[line width=1.2pt, dashed]
				table[col sep=comma, x=eps, y=adversarial]{featuremtx_perturb.csv};
			\addlegendentry{adversarial construction}
			\addplot[line width=1.2pt, dotted, mark=o, mark size=1.8pt]
				table[col sep=comma, x=eps, y=random]{featuremtx_perturb.csv};
			\addlegendentry{largest of one hundred random constructions}
		\end{axis}
		\end{tikzpicture}
		\\[1mm]
		{\small (b)}
		\end{center}
		\caption{The perturbation bound for the features
			$(1, \feature)$, with $\feature$ the lowest temperature of a
			day, and the highest temperature as the label, over the
			first days of the twelve months of $2024$ (filled circles). (a)
			The least squares hypothesis (solid
			line), the hypothesis learned after the adversarial
			construction of a perturbation of relative size
			$\varepsilon = 0.01$ (dashed line), the range of the
			hypotheses learned after $100$ random constructions
			of the same relative size (gray band), and the bound
			\eqref{eq_featuremtx_predbound} above and below the learned
			hypothesis
			(dotted curves, leaving the plotted range).
			(b) The change of the learned model parameters against
			$\varepsilon$: the right-hand side of the bound
			\eqref{eq_featuremtx_bound} (solid curve), the adversarial
			construction (dashed curve), and the largest change among $100$
			random constructions (dotted curve with circles). Data generated
			by \texttt{pythondemos/featuremtx.py}
			\label{fig_featuremtx_spread_dict}}
		\end{figure}

\subsection{Cross References}
dataset, data point, feature vector, feature, array, matrix, design matrix, linear model, parameter space, SVD, singular value, rank, condition number, sample covariance matrix, PCA, dimensionality reduction, column space

\subsection{References}
\begin{enumerate}
  \item Bertsekas (2016). Nonlinear Programming. 3rd ed., Athena Scientific, Belmont, MA, USA.
  \item Bishop (2006). Pattern Recognition and Machine Learning. Springer Science+Business Media, New York, NY, USA.
  \item Boyd and Vandenberghe (2004). Convex Optimization. Cambridge Univ. Press, Cambridge, U.K.
  \item Golub and Van Loan (2013). Matrix Computations. 4th ed., The Johns Hopkins Univ. Press, Baltimore, MD, USA.
  \item Hastie et al. (2009). The Elements of Statistical Learning: Data Mining, Inference, and Prediction. 2nd ed., Springer Science+Business Media, New York, NY, USA.
\end{enumerate}

\end{document}
