Skip to content

Latest commit

Β 

History

History
41 lines (24 loc) Β· 3.37 KB

python-translation.md

File metadata and controls

41 lines (24 loc) Β· 3.37 KB

ML μ•Œκ³ λ¦¬μ¦˜μ„ Python μ½”λ“œλ‘œ λ³€ν™˜

Jupyter λ…ΈνŠΈλΆμœΌλ‘œ μƒμ„±ν•œ ML μ•Œκ³ λ¦¬μ¦˜μ„ Python μ½”λ“œλ‘œ λ³€ν™˜ν•˜λŠ” 과정에 λŒ€ν•΄ μ„€λͺ…ν•©λ‹ˆλ‹€.

  1. ν™•μž₯μžκ°€ ipyb인 jupyter notebook νŒŒμΌμ„ μ•„λž˜ λͺ…λ Ήμ–΄λ₯Ό μ΄μš©ν•˜μ—¬ python 파일둜 λ³€ν™˜ ν•©λ‹ˆλ‹€.
jupyter nbconvert xgboost-wine-quality.ipynb --to script --output step0-xgboost-wine-quality

xgboost-wine-quality.ipynb을 상기 λͺ…λ Ήμ–΄λ‘œ λ³€ν™˜ν•˜λ©΄, step0-xgboost-wine-quality.py와 같이 python 파일둜 λ³€ν™˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

  1. λΆˆν•„μš”ν•œ μ½”λ“œ 정리

jupyter notebookμ—μ„œ λ°μ΄ν„°μ˜ ꡬ쑰λ₯Ό μ΄ν•΄ν•˜κ³ , λ„ν‘œλ₯Ό μž‘μ„±ν• λ•Œ μ‚¬μš©ν–ˆλ˜ μ½”λ“œλ“€μ€ 본격적인 ν•™μŠ΅μ—μ„œλŠ” μ‚¬μš©λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. λ”°λΌμ„œ, step1-xgboost-wine-quality.py와 같이 λΆˆν•„μš”ν•œ μ½”λ“œλ₯Ό μ‚­μ œν•©λ‹ˆλ‹€.

  1. Python ν•¨μˆ˜λ‘œ λ¦¬νŒ©ν„°λ§

ν•¨μˆ˜λ‘œ λ³€κ²½ν•˜λ©΄ refactoring이 μ‰¬μ›Œμ§€κ³  μœ μ§€ 관리가 μˆ˜μ›”ν•˜μ—¬ μ§€λ―€λ‘œ step2-xgboost-wine-quality.py와 같이 ν•¨μˆ˜λ‘œ λ³€ν™˜ν•©λ‹ˆλ‹€. μ΄λ•Œ, main은 μ§„μž…μ (entry point)μ΄λ―€λ‘œ 싀행쀑인지 μ—¬λΆ€λ₯Ό ν™•μΈν•˜μ—¬ μ•„λž˜μ²˜λŸΌ μ‚¬μš©ν•©λ‹ˆλ‹€.

if __name__ == '__main__':
    main()
  1. Inference

xgboost-wine-quality-inference.ipynb을 μ°Έμ‘°ν•˜μ—¬ μΆ”λ‘ (inference)λ₯Ό μœ„ν•œ python μ½”λ“œλ₯Ό μƒμ„±ν•©λ‹ˆλ‹€. 좔둠을 μœ„ν•΄μ„œλŠ” ν•™μŠ΅μ‹œ μ €μž₯ν•œ λͺ¨λΈμ„ λΆ€λ₯΄κ³ , RESTful API νŠΉμ„±μ— λ§žμΆ°μ„œ eventλ₯Ό μ²˜λ¦¬ν•  수 μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€. inference.py은 ν•™μŠ΅ν•œ λͺ¨λΈμ„ λ‘œλ“œν•˜κ³ , eventλ₯Ό parsingν•˜μ—¬ predict()μ—μ„œ μ‚¬μš©ν•  수 μžˆλŠ” 포맷으둜 λ³€ν™˜ν•œ λ‹€μŒμ— 좔둠을 μˆ˜ν–‰ν•˜κ³ , κ²°κ³Όλ₯Ό λ¦¬ν„΄κ°’μœΌλ‘œ μ „λ‹¬ν•˜λŠ” 것을 λ³΄μ—¬μ€λ‹ˆλ‹€.

μΆ”λ‘  λ™μž‘μ„ ν™•μΈν•˜κΈ° μœ„ν•΄ inference-test.pyμ—μ„œλŠ” samples.json을 λ‘œλ“œν•˜μ—¬, RESTful APIμ—μ„œ μ‚¬μš©ν•˜λŠ” event의 ν˜•νƒœλ₯Ό λ§Œλ“ ν›„μ—, inference.py의 handler()을 톡해 μΆ”λ‘  λ™μž‘μ„ μˆ˜ν–‰ν•©λ‹ˆλ‹€. λ”°λΌμ„œ, μ‹€μ œ 인프라λ₯Ό κ΅¬μΆ•ν•˜μ—¬ μΆ”λ‘  APIλ₯Ό μƒμ„±ν•˜κΈ° 전에 inference.py의 λ™μž‘μ„ 검증할 수 μžˆμŠ΅λ‹ˆλ‹€.

Reference

ML μ‹€ν—˜μ„ ν”„λ‘œλ•μ…˜ Python μ½”λ“œλ‘œ λ³€ν™˜

SageMaker basic - XGBoost

xgboost_starter_script.py