pandas Scikit 学习/熊猫中的线性回归和梯度下降?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34469237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linear Regression and Gradient Descent in Scikit learn/Pandas?
提问by Netro
in coursera course for machine learning https://share.coursera.org/wiki/index.php/ML:Linear_Regression_with_Multiple_Variables#Gradient_Descent_for_Multiple_Variables, it says gradient descent should converge.
在机器学习课程https://share.coursera.org/wiki/index.php/ML:Linear_Regression_with_Multiple_Variables#Gradient_Descent_for_Multiple_Variables 中,它说梯度下降应该收敛。
I m using Linear regression from scikit learn. It doesn't provide gradient descent info. I have seen many questions on stackoverflow to implement linear regression with gradient descent.
我正在使用来自 scikit learn 的线性回归。它不提供梯度下降信息。我在stackoverflow上看到了很多关于使用梯度下降实现线性回归的问题。
How do we use Linear regression from scikit-learn or pandas in real world? OR Why does scikit-learn or pandas doesn't provide gradient descent info in linear regression output?
我们如何在现实世界中使用来自 scikit-learn 或 pandas 的线性回归?或 为什么 scikit-learn 或 pandas 在线性回归输出中不提供梯度下降信息?
回答by lejlot
Scikit learn provides you two approaches to linear regression:
Scikit learn 为您提供了两种线性回归方法:
1) LinearRegression
object uses Ordinary Least Squares solver from scipy, as LR is one of two classifiers which have closed form solution. Despite the ML course - you can actually learn this model by just inverting and multiplicating some matrices.
1)LinearRegression
对象使用来自 scipy 的普通最小二乘法求解器,因为 LR 是具有封闭形式解的两个分类器之一。尽管有 ML 课程 - 您实际上可以通过反转和乘以一些矩阵来学习这个模型。
2) SGDClassifier
which is an implementation of stochastic gradient descent, very generic one where you can choose your penalty terms. To obtain linear regression you choose loss to be L2
and penalty also to none
(linear regression) or L2
(Ridge regression)
2)SGDClassifier
这是随机梯度下降的一种实现,非常通用,您可以在其中选择惩罚项。要获得线性回归,您选择损失为L2
,惩罚也为none
(线性回归)或L2
(岭回归)
There is no "typical gradient descent" because it is rarely usedin practise. If you can decompose your loss function into additive terms, then stochastic approach is known to behave better (thus SGD) and if you can spare enough memory - OLS method is faster and easier (thus first solution).
没有“典型的梯度下降”,因为它在实践中很少使用。如果您可以将损失函数分解为加性项,那么已知随机方法的表现会更好(因此 SGD)并且如果您可以节省足够的内存 - OLS 方法更快更容易(因此是第一个解决方案)。