微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python中的倒标准最小二乘回归ISR

如何解决python中的倒标准最小二乘回归ISR

嗨,我只是想执行逆最小二乘回归

Y -> m *x + c

python 中是否有可用的包或函数

解决方法

我假设 inverted least squares regression 是指最小化最佳拟合线与数据之间的水平距离而不是垂直距离的回归。如果是这种情况,您可以简单地在 x 上运行 y 的回归,然后设置 m* = 1/ma*=-a/m。举个例子:

import matplotlib.pyplot as plt
import pandas as pd 
from sklearn.linear_model import LinearRegression

# DATA
x = np.linspace(0,1,100).reshape((-1,1))
y = 0.5*x + np.random.normal(0,0.1,size=x.shape)

# INVERTED LINEAR REGRESSION
model = LinearRegression(fit_intercept=True)
model.fit(y,x)
m = 1/model.coef_[0][0]
a = -model.intercept_/model.coef_[0][0]

# PLOT
plt.scatter(x,y,color='r',s=12,alpha=0.5)
plt.plot(x,m*x + a)
plt.xlabel('x')
plt.ylabel('y')

enter image description here

,

您可以尝试 statsmodels 它有一些回归算法,如果它没有您要找的算​​法,请检查其他算法的实现并用它来实现您的

链接:https://www.statsmodels.org/stable/api.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。