特征越多线性模型越完美

The more the features the more perfect the linear model

根据 Andreas C. Müller 和 Sarah Guido 着书 "Introduction to Machine Learning with Python" 第 47 页的这段内容,我需要了解更多关于特征数量与线性模型回归之间关系的信息:

"对于具有许多特征的数据集,线性模型可能非常强大。 特别是,如果您的特征多于训练数据点,则任何目标 y 可以完美地建模(在训练集上)作为线性函数

线性代数是怎么解释的?

谢谢

我可以试着给你一个直观的答案。

假设您有一个训练数据集,由二维的单个数据点组成。在这种情况下,我们有 n_data = 1(数据点数)和 n_features = 2n_features > n_data)。训练数据集可以通过一维线性函数y = a0.

完美建模

类似地,如果你有三个特征(即三维)和两个数据点(所以 n_features = 3 > n_data = 2),这两个点总是可以通过以下形式的二维线建模y = a0 + a1 x1.

在四个维度(四个特征)中,三个点总是可以由一个(超)平面建模,该(超)平面由 y = a0 + a1x1 + a2x2.

形式的线性方程定义

一般来说,超平面(定义为维数少于其环境维数 space 的任何平面)总是可以用线性公式 a1*x1 + a2*x2 + a3*x3 + ... + an*xn = b 定义。因此,如果点数小于维数,总能找到一个超平面,因此,如果样本数小于特征数(这对应于 space).

的维度

这个问题更适合Cross Validated社区。

这里的关键词是"on the training set"

"For datasets with many features, linear models can be very powerful. In particular, if you have more features than training data points, any target y can be perfectly modeled (on the training set) as a linear function", Introduction to Machine Learning with Python, by Andreas C. Müller & Sarah Guido.

一般来说 特征多于数据点(或 variables/predictors 多于 samples/observations)导致 model overfitting。如果我们有太多的特征,学到的假设可能非常适合训练集,但无法推广到新的例子(在测试集上)。例如,考虑一个由 1000 张图像组成的数据集,每张图像有 300x300 像素(1000 个样本和 90000 个特征)。

预测变量多于观测值的问题(通常表示为 p>n)是标准 linear regression 问题没有唯一解。 线性代数是这样解​​释的。如果数据点矩阵的行代表个案,列代表预测变量,那么矩阵的列之间必然存在线性相关性。因此,一旦找到 n 个预测变量的系数,其他 p-n 个预测变量的系数就可以表示为任意线性前 n 个预测变量的组合。 LASSOridge regression 等其他方法,或各种其他 machine-learning 方法,提供了在这种情况下进行处理的方法。

Cross Validated上有一个不错的answer

It's certainly possible to fit good models when there are more variables than data points, but this must be done with care.

When there are more variables than data points, the problem may not have a unique solution unless it's further constrained. That is, there may be multiple (perhaps infinitely many) solutions that fit the data equally well. Such a problem is called ill-posed or underdetermined. For example, when there are more variables than data points, standard least squares regression has infinitely many solutions that achieve zero error on the training data.

Such a model would certainly overfit because it's "too flexible" for the amount of training data. As model flexibility increases (e.g. more variables in a regression model) and the amount of training data shrinks, it becomes increasingly likely that the model will be able to achieve a low error by fitting random fluctuations in the training data that don't represent the true, underlying distribution. Performance will therefore be poor when the model is run on future data drawn from the same distribution.

在讨论特征数量与线性模型回归之间的关系之前,让我先弄清楚属性或预测变量与特征之间的区别。

属性或预测变量是第一级输入变量,而特征可以是第一级或第二级。这里,第一级意味着预测器作为预测响应或输出的输入变量。第二层意味着特征作为预测变量或输入变量的非线性变换,使用一些基础或特征图来捕获继承的特殊结构。

现在,从线性代数的角度来回答你的问题。如果特征的数量表示它的维度为 $p>>n$,则样本数量 n 太小而无法准确估计参数。在 $p>>n$ 的情况下,线性模型的关联线性系统 $y=\textbf{X}\omega$ 是欠定的并且有无限多个解,因此我们可以使用最小范数解找到最佳解.

另一种方法是,我们假设模型是稀疏的,但是如果真实模型是稀疏的,并且稀疏度为 $s