我有一个代码
df.select([
pl.all().exclude("elapsed_time_linreg"),
pl.col("elapsed_time_linreg").arr.get(0).suffix("_slope"),
pl.col("elapsed_time_linreg").arr.get(1).suffix("_intercept"),
pl.col("elapsed_time_linreg").arr.get(2).suffix("_resid_std"),
])
Run Code Online (Sandbox Code Playgroud)
解压函数的结果
@jit
def linear_regression(session_np: np.ndarray) -> np.ndarray:
w = len(session_np)
x = np.arange(w)
sx = w ** 2 / 2
sy = np.sum(session_np)
sx2 = (w * (w + 1) * (2 * w + 1)) / 6
sxy = np.sum(x * session_np)
slope = (w * sxy - sx * sy) / (w * sx2 - sx**2)
intercept = (sy - slope * sx) / w
resids = session_np - (x * …Run Code Online (Sandbox Code Playgroud)