我正在查看不能在其曲线下方有点的线性回归?

I am looking at a linear regression that cannot have points below its curve?

基本上,如图所示,我想知道是否有一个线性回归模型允许所有点都在其曲线上方,同时仍然进行线性回归。在此图像中,所有时间最短的点都很有趣,因为多余的时间只是由于噪声造成的。

因此,是否有一个线性回归模型允许所有点都高于(或低于)它的曲线,同时仍然进行适当的线性回归?

#########################

这是我希望在不使用 witchcratftry 的情况下获得的结果的说明。

我可以在所有点都在曲线上方的约束条件下进行线性回归吗?

我认为 scikit-learn 中没有这样的东西,但您可以使用 scipy 的最小化最小化函数与点的平方距离,同时激活约束最小化。

首先我生成一个例子

np.random.seed(0)
x = np.linspace(0,250,100)
y = 0.5*x+np.abs(np.random.normal(0,10,x.shape))
y[np.random.randint(0,y.shape[0],3)] += 100

我做你的约束最小二乘法

def con(a):
    return np.min(y-(a[0]*x+a[1]))

cons=({'type': 'ineq','fun': con})

def f(a):
    return np.linalg.norm(y-(a[0]*x+a[1]))

x0 = [0.1,-1]

res = minimize(f, x0, constraints=cons)

并绘制结果

a,b = res.x
plt.plot(x,y)
plt.plot(x,a*x+b)