gpt4 book ai didi

scikit-learn - 在 sklearn 中计算 f 统计量

转载 作者:行者123 更新时间:2023-12-04 14:17:49 25 4
gpt4 key购买 nike

我一直在谷歌搜索,但找不到答案。

如何使用 sklearn 计算 f 统计量?考虑到以下公式,我真的必须手动计算吗:

f-statistic formula

(其中 𝑁 是观测值的数量,𝐾 是变量的数量)。

而且...如果我手动计算它,我如何获得关联的 p 值?

最佳答案

希望对您有所帮助!要找到 f 统计量,请尝试:

import sklearn
from sklearn.linear_model import LinearRegression

X, y = df[['x1','x2']], df[['y']]

model=LinearRegression().fit(X, y)

Rsq = model.score

fstat = (Rsq/(1-Rsq))*((N-K-1)/K) #you should find N and K yourself

求p值可以使用python包symbulate

import symbulate as sm

dfN = 5 -1 #degrees of freedom in the numerator of F-statistic
dfD = 2 -1 #degrees of freedom in the denominator of F-statistic

pVal = 1-sm.F(dfN,dfD).cdf(fstat)

关于scikit-learn - 在 sklearn 中计算 f 统计量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58497385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com