Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing coefficients
#1
Hi Everyone,

I am trying to print coefficients for my logistic regression model so I can get the scores for each variable input to see how predictive they are. Does anyone know how to print the coefficients with their input column (or variable) names?

final_model = grid_search.best_estimator_

X_test = test_set.drop("default.payment.next.month", axis=1)
y_test = test_set["default.payment.next.month"].copy()

X_test_prepared = cred_pipeline.transform(X_test)
final_predictions = final_model.predict(X_test_prepared)

final_mse = mean_squared_error(y_test, final_predictions)
final_rmse = np.sqrt(final_mse)
display_scores(final_rmse)

coef = np.array(final_predictions.coef_)
print(coef)
my error

coef = np.array(final_predictions.coef_)
print(coef)
Traceback (most recent call last):

File "<ipython-input-25-f79449f13b02>", line 1, in <module>
coef = np.array(final_predictions.coef_)

AttributeError: 'numpy.ndarray' object has no attribute 'coef_'
Reply
#2
What about the coef_ of final_model?

final_model = grid_search.best_estimator_
...
print(final_model.coef_)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  AR roots for VAR coefficients Scott 2 1,051 Nov-30-2022, 09:23 PM
Last Post: Scott
  Neural Network importance weights / coefficients jkaustin 1 2,060 Nov-10-2020, 07:44 PM
Last Post: jefsummers
  Outputing LogisticRegression Coefficients (sklearn) RawlinsCross 6 4,770 Feb-27-2020, 02:47 PM
Last Post: RawlinsCross
  fit each group and extract coefficients Progressive 1 2,922 Jul-20-2019, 08:20 AM
Last Post: scidam
  using two arrays to fit a third one - find coefficients vaugirard 1 2,602 Jul-05-2018, 10:49 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020