python - GEKKO Python - 来自文档的简单线性回归
问题描述
通过遵循 GEKKO 文档,我使用了线性和多项式回归的示例。这只是关于简单线性回归的部分。
from gekko import GEKKO
import numpy as np
xm = np.array([0.1,0.3,0.2,0.5,0.8])
ym = np.array([0.52,0.53,0.4,0.6,1.01])
#### Solution
m = GEKKO()
m.options.IMODE=2
# coefficients
c = [m.FV(value=0) for i in range(2)]
c[0].STATUS=1
c[1].STATUS=1
x = m.Param(value=xm)
yd = m.Param(value=ym)
y = m.CV(value=ym)
y.FSTATUS = 1
######### uncomment ############
#y = m.Var()
#m.Minimize((y-yd)**2)
################################
# polynomial model
m.Equation(y==c[0]+c[1]*x)
# linear regression
m.solve(disp=False)
p1 = [c[1].value[0],c[0].value[0]]
p1
我只是想知道为什么取消注释行时会得到不同的结果
y = m.Var()
m.Minimize((y-yd)**2)
文档中获得的结果(线性、二次、三次)似乎不是最小二乘法。在这些情况下使用了哪些最小化标准?
最好的问候, 拉多万
解决方案
Switch to m.options.EV_TYPE=2
to get a squared error objective.
The default in Gekko is the l1-norm objective. Here is a description of the differences:
The l1-norm objective (sum of the absolute error) is less sensitive to outliers and bad data.
推荐阅读
- javascript - gulp 将多个 js 合并为一个 dist 索引
- excel - 嵌套 For 循环运行缓慢且无法正常工作
- php - 将本地图像迁移到 Laravel 中的数据库
- .net - 使用 Jenkins 持续部署 .net 核心
- opencart - 是否可以创建同时支持 OpenCart 2.3 和 3.0 的插件?
- hibernate - 如何将具有角色的新用户添加到数据库/ Hibernate、Spring Security、Spring MVC
- docker - Kubernetes-Kafka 无法在主题上写入消息
- xcode - Xcode 中自定义键绑定的命令列表是什么?
- c# - 为什么 ListBox ItemTemplateSelector="{StaticResource MyDataTemplateSelector}" 不能与资源一起使用?
- python - Z3 python模型比较