python - SKlearn 使用什么算法来最小化 MSE?

标签 python machine-learning scikit-learn linear-regression

我正在使用 Scikit-learn 库进行线性回归。一切都简单明了。 只需 6 行代码,我就可以完成这项工作。不过,我想知道到底发生了什么。

由于我是机器学习的初学者,也许我的问题是错误的,但我想知道 Scikit-learn 使用什么算法来最小化其线性回归方法中的均方误差。

最佳答案

来自documentation :

From the implementation point of view, this is just plain Ordinary Least Squares (scipy.linalg.lstsq) wrapped as a predictor object.

你也可以看一下源代码here ,它在哪里调用 linalg.lstsq .

<小时/>

关于背后发生的事情的额外说明:

如果线性公式为 a * x + b,您可以使用以下命令访问系数 (a) 和偏差 (b):训练模型的属性 coef_intercept_

一个从 3 个点生成恒等对角线以显示 coef_intercept_ 属性的玩具示例:

from sklearn.linear_model import LinearRegression

X = np.array([[1], [2], [3]])
y = np.array([1, 2, 3])

lg = LinearRegression()
lg.fit(X, y)
lg.coef_ # 1
lg.intercept_ # ~ 0

关于python - SKlearn 使用什么算法来最小化 MSE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53416427/

相关文章:

python - 减少python中markdown的功能

python - 从文件路径动态加载模块时强制python忽略pyc文件

python - 用于 python 或其他编程语言的 Mac 词典到文档工具提示

machine-learning - 过度拟合总是一件坏事吗?

python - 带有管道和 GridSearchCV 的 StandardScaler

machine-learning - K-NN : training MSE with K=1 not equal to 0

python - 匹配多个单词Regex,python

machine-learning - Weka OneR 给出?作为分类器模型

machine-learning - 如何查看失败的机器学习记录

python - 使用 python StandardScaler 进行特征缩放会产生负值