我有一个简单的 keras 模型(正常套索线性模型),其中输入被移动到单个“神经元”Dense(1, kernel_regularizer=l1(fdr))(input_layer) 但是权重从这个模型中永远不会完全设置为零。我发现这很有趣,因为 scikit-learn 的套索可以将系数精确设置为零。
我用过Adam和tensorflow的FtrlOptimizer进行优化,他们也有同样的问题。
我已经检查过这个 question已经但是这并不能解释为什么 sklearn 可以将值精确设置为零,更不用说他们的模型如何在我的服务器上收敛约 500 毫秒,而 Keras 中的相同模型需要 2.4 秒并提前终止。
这都是因为使用了优化器还是我遗漏了什么?
请您参考如下方法:
Is this all because of the optimizer being used or am I missing something?
的确如此。如果您查看实际的 function that gets called当您从 scikit-learn 中拟合 Lasso(它从 ElasticNet 类调用)时,您会看到它使用不同的优化算法。
scikit-learn 的 ElasticNet 中的坐标下降 starts with coefficient vector equal to zero ,然后考虑一次添加一个非零条目(这与线性回归的逐步特征选择有关)。
用于优化 L1 正则化回归的其他方法也以这种方式工作:例如 LARS (最小角度回归)也可以在 scikit-learn 中使用。
与此相反,paper on FTRL算法说
Unfortunately, OGD is not particularly effective at producing sparse models. In fact, simply adding a subgradient of the L1 penalty to the gradient of the loss (Ow`t(w)) will essentially never produce coefficients that are exactly zero.
