인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

doctorsong8309's profile image
doctorsong8309

asked

[Revised Edition] The Complete Guide to Python Machine Learning

Wisconsin Breast Cancer Prediction Using XGBoost (Using Python Native XGBoost)

사소한 질문

Resolved

Written on

·

374

0

fig, ax = plt.subplots(figsize=(1012))
plot_importance(xgb_model, ax=ax)
이 부분에서 (~, ax)로 안하시고
ax=ax 하신이유가 궁금합니다
머신러닝 배워볼래요? python통계

Answer 2

1

dooleyz3525님의 프로필 이미지
dooleyz3525
Instructor

안녕하십니까,

질문 중 (~, ax)를 사용해 본적이 없어서 일단 ax=ax를 부여한 이유를 말씀 드리겠습니다.

일반적으로 xgboost의 plot_importance() 호출시 ax 파라미터에 값을 부여하는 것은 plot의 크기를 조절하기 위해서 입니다.

강의 소스 코드에서 위와 같이 plt.subplots()을 호출하여 세부 axis 축을 반환 받지 않고도 아래와 같은 코드도 feature importance를 출력합니다.

plot_importance(xgb_wrapper)
plt.show()

하지만 위 경우는 plot의 사이즈가 조절이 안됩니다. 아래와 같이 plt에 figure size를 설정해도 마찬가지로 조절되지 않습니다.

plt.figure(figsize=(10, 12))
plot_importance(xgb_wrapper)
plt.show()

현 xgboost 버전에서 plt의 크기를 조절하려면 fig, ax = plt.subplots(figsize=(1012)) 와 subplots의 axis에 figsize를 설정한 다음, plot_importance(xgb_model, ax=ax) 로 ax 파라미터에 subplot로 반환된 ax 값을 입력해야만 조절이 가능합니다.

감사합니다.

0

doctorsong8309님의 프로필 이미지
doctorsong8309
Questioner

이 경우에만 되는 특수 케이스고 , 크기 조절하는 경우에는 같지 않을 수 있는거군요 ㅎㅎ

좋은 답변 감사합니다

doctorsong8309's profile image
doctorsong8309

asked

Ask a question