호돌찌의 AI 연구소
article thumbnail

이전 글에서는 모델과 실험 트래킹 기능에 집중을 해보았습니다. mlflow Tutorial 두 번째 글은 mlflow에 조금 더 친숙해지기 위해 logging 관련된 내용, 그리고 다른 예시 내용입니다.

 

 


 

1. 샘플 코드 살펴보기 - Automatic Logging

utils.py, pipeline.py를 wget으로 다운을 받습니다. 

 

https://github.com/mlflow/mlflow/tree/master/examples/sklearn_autolog

 

GitHub - mlflow/mlflow: Open source platform for the machine learning lifecycle

Open source platform for the machine learning lifecycle - GitHub - mlflow/mlflow: Open source platform for the machine learning lifecycle

github.com

wget https://raw.githubusercontent.com/mlflow/mlflow/master/examples/sklearn_autolog/utils.py
wget https://raw.githubusercontent.com/mlflow/mlflow/master/examples/sklearn_autolog/pipeline.py

 

위 코드들은 간단한 학습 데이터를 바탕으로 sklearn의 pipeline을 사용해 standardscaler 전처리 후 회귀분석을 수행하는 코드입니다. pipeline 코드를 살펴보면 utils.py의 fetch_logged_data함수를 활용하여 logging을 살펴볼 예정입니다. 

 

 

mlflow에서 scikit-learn과 같은 패키지는 autolog를 지원합니다. 즉, 모델의 parameters, metric과 model artifacts를 사용자가 명시하지 않아도, 자동으로 mlflow에 로깅합니다. 

 

 

 

pipeline.py를 수행하면 아래와 같이 터미널에서 확인이 가능합니다.

 

 

 

 

 

 

 

 

2. 샘플 코드 살펴보기 - XGB Model

train.py를 다운받아 수행해볼 예정입니다. 그전에 pip로 xgboost==1.4.2를 설치하고 수행합니다. 

https://github.com/mlflow/mlflow/tree/master/examples/xgboost/xgboost_native

 

GitHub - mlflow/mlflow: Open source platform for the machine learning lifecycle

Open source platform for the machine learning lifecycle - GitHub - mlflow/mlflow: Open source platform for the machine learning lifecycle

github.com

 

해당 코드는 mlflow에서 example로 제공해주는 하나의 코드이며, iris 데이터를 가지고 xgboost로 cls를 수행하는 코드입니다. xgboost 용 autolog를 사용했고, 추가적인 custom metric을 남기기 위해 mlflow.log_metrics()를 사용하였습니다.

 

 

train.py를 수행해봅니다.

 

해당 실험내용을 mlflow ui를 보고 확인해봅니다. 여러 내용을 확인할 수 있습니다. 

 

 

변수 중요도도 살펴볼 수 있다. 

 

automatic logging은 scikit-learn 뿐만 아니라 다른 라이브러리(torch, tf, fastai, lgbm 등)에도 모두 지원하기 때문에 여기를 참고하시면 될 것 같습니다. 

https://www.mlflow.org/docs/latest/tracking.html#automatic-logging

 

MLflow Tracking — MLflow 1.23.1 documentation

The MLflow Tracking component is an API and UI for logging parameters, code versions, metrics, and output files when running your machine learning code and for later visualizing the results. MLflow Tracking lets you log and query experiments using Python,

www.mlflow.org

 

 

다음 글은 모델 서빙 관련 내용으로 찾아뵙겠습니다. mlflow를 사용하여 서빙이 가능하지만 flask, seldon-core와 같은 tool을 사용하여 서빙을 다룰 예정입니다. 


https://bit.ly/37BpXiC

 

패스트캠퍼스 [직장인 실무교육]

프로그래밍, 영상편집, UX/UI, 마케팅, 데이터 분석, 엑셀강의, The RED, 국비지원, 기업교육, 서비스 제공.

fastcampus.co.kr

 

* 본 포스팅은 패스트캠퍼스 환급 챌린지 참여를 위해 작성되었습니다.

 


profile

호돌찌의 AI 연구소

@hotorch's AI Labs

포스팅이 도움이 되셨다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!