使用 pycaret 从逻辑回归模型中获取参数估计值

问题描述 投票:0回答:3

我正在 pycaret 中训练和调整模型,例如:

from pycaret.classification import *
clf1 = setup(data = train, target = 'target', feature_selection = True, test_data = test, remove_multicollinearity = True,  multicollinearity_threshold = 0.4)

# create model
lr = create_model('lr')

# tune model
tuned_lr = tune_model(lr)

# optimize threshold
optimized_lr = optimize_threshold(tuned_lr)

我想获得逻辑回归中特征的估计参数,这样我就可以继续了解每个特征对目标的影响大小。然而,对象

optimized_lr
有一个函数
optimized_lr.get_params()
,它返回模型的超参数,但是,我对我的调整决策不太感兴趣,相反,我对模型的真实参数非常感兴趣,即估计的参数在逻辑回归中。

我怎样才能让他们使用 pycaret? (我可以轻松地使用其他软件包(例如 statsmodels)获得这些信息,但我想在 pycaret 中知道)

python regression logistic-regression pycaret
3个回答
0
投票

怎么样

for f, c in zip (optimized_lr.feature_names_in_,tuned.coef_[0]):
      print(f, c)

0
投票

要获取系数,请使用以下代码:

tuned_lr.feature_importances_ #this will give you the coefficients

get_config('X_train').columns #this code will give you the names of the columns.

现在我们可以创建一个数据框,以便我们可以清楚地看到它与自变量的相关性。

Coeff=pd.DataFrame({"Feature":get_config('X_train').columns.tolist(),"Coefficients":tuned_lr.feature_importances_})

print(Coeff)

# It would give me the Coefficient with the names of the respective columns. Hope it helps.

0
投票

从pycaret分类模型中获取系数

## Getting Feature Names from the model
names = list(tuned_lr.feature_names_in_)
names.insert(0, 'Intercept')

## Intercept and slope estimates
coef = (tuned_lr.coef_.tolist()[0])
coef.insert(0, tuned_lr.intercept_.tolist()[0])

## Results
coefs = pd.DataFrame({'Estimate': coef})
coefs.index = names
coefs
© www.soinside.com 2019 - 2024. All rights reserved.