0

I am training and tuning a model in pycaret such as:

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)

I would like to get the parameters estimated for the features in the Logistic Regression, so I could proceed with understanding the effect size of each feature on the target. However, the object optimized_lr has a function optimized_lr.get_params() which returns the hyperparameters of the model, however, I am not quite interested in my tuning decisions, instead, I am very interested in the real parameters of the model, the ones estimated in Logistic Regression.

How could I get them to use pycaret? (I could easily get those using other packages such as statsmodels, but I want to know in pycaret)

Sheracore
  • 21
  • 4
Gustavomoty
  • 87
  • 1
  • 5

2 Answers2

0

how about

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

To get the coefficients, use this code:

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.

Now we can create a dataframe so that we could see clearly how it correlates with the independent variable.

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.
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Amarah
  • 1
  • 1