当我将数据可视化为散点图时,我想使用滑块。
def fit_huber_line(x, y):
from sklearn.linear_model import HuberRegressor, LinearRegression
# given one dimensional x and y vectors - return x and y for fitting a line on top of the regression
A = np.vstack([x, np.ones(len(x))]).T
huber = HuberRegressor().fit(A, y)
c = huber.intercept_ + huber.coef_[1]
m = huber.coef_[0]
return m, c
suppdata = pd.DataFrame({"x" : list(np.arange(0, 5, 0.1)),
"y" : list(np.arange(0, 5, 0.1)*2) })
fig = px.scatter(suppdata, x='x', y='y',
hover_data=suppdata.columns.to_list(), title=mytitle)
m, c = fit_huber_line(x = suppdata['x'],
y = suppdata['y'])
# over lay the line - using a robus regression
my_x = suppdata['x']
fig.add_trace(
go.Scatter(
x= my_x,
y= m * my_x + c,
mode="lines",
line=go.scatter.Line(color="red"),
showlegend=False)
)
mid_point = (max(my_x) - min(my_y))/2
fig.update_layout(
showlegend=False,
annotations=[
go.layout.Annotation(
x=mid_point,
y=mid_point*m + c,
xref="x",
yref="y",
text=str(round(m, 2))+'x+'+str(round(c, 2)) ,
)
]
)
因此,理想情况下,我希望有两个滑块可以在x和y轴上进行过滤。