python 使用Pycaret从logistic回归模型中获取参数估计值

e0bqpujr  于 2023-01-19  发布在  Python
关注(0)|答案(2)|浏览(124)

我正在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(),它返回模型的hiperparameters,然而,我对我的调整决策不太感兴趣,相反,我对模型的真实的参数很感兴趣。Logistic回归中估计的值。
我怎样才能使用pycaret得到它们呢?(我可以很容易地使用其他包,如statmodels,但我想知道在pycaret)

v2g6jxz6

v2g6jxz61#

怎么样

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

ru9i0ody2#

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

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.

现在我们可以创建一个 Dataframe ,这样我们就可以清楚地看到它是如何与自变量相关的。

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.

相关问题