Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JupyterNotebookでのdebug入門(サンプルは説明欄にあります)

285cc95c4c9fe056b03afca581533266?s=47 fkubota
August 17, 2021

 JupyterNotebookでのdebug入門(サンプルは説明欄にあります)

285cc95c4c9fe056b03afca581533266?s=128

fkubota

August 17, 2021
Tweet

Transcript

  1. JupyterNotebookͰͷdebugೖ໳ pdb, ipdb, %debugͱ͔ fkubota

  2. 2 ࣗݾ঺հ fkubota (Twitter, Kaggle) - όϯυϧΧʔυͷձࣾ(ΧϯϜ)ͰػցֶशΤϯδχΞ - Kaggle Expert

    - ԭೄग़਎(౦ژʹग़͖ͯͯ3೥൒) - ෺ཧֶՊग़਎(ڧ૬ؔిࢠܥɺ4.2KͷӷମϔϦ΢Ϝʹ࣓ੑମಥͬࠐΜͰͨ) - ϓϩάϥϛϯάྺ͸2೥൒͙Β͍ - झຯ - ૣى͖(4࣌൒ىচ) - Kaggle - ίʔώʔɺϏʔϧɺ΢ΟεΩʔ - ಡॻɺ෺ཧɺ఩ֶ
  3. 3 Contents debug ʹ͍ͭͯ JupyterNotebookͰ debug ʹೖ໳ ͳͥσόοΨ͕ඞཁ͔ͱ ͔ɻ ෼ੳίϯϖͰඞͣͱߦͬͯ

    ͍͍΄Ͳ࢖͏ JupyterNotebookͰͷdebug ํ๏ʹ͍ͭͯ؆୯ʹ঺հɻ ओʹϏΪφʔʹ޲͚ͯʂ
  4. 4 ͋Δ͋Δʁ ίϯϖ΍ͬͨΔͰʔʂ ͜ͷϊʔτϒοΫͰೖ໳͠Α͏ɻ ͏ʔʔʔΜɻ ਓͷίʔυಡΉͷ͠ΜͲ͍ɻ ࣗ෼ͷ؀ڥͩͱಈ͔ͳ͍ͷͰमਖ਼͕ඞཁɻ ͽ͑Μ͑ͯ͜ͺ͓Μɻ*1 *1 ࠓ͞Βฉ͚ͳ͍ʮͽ͑Μʯͱʮͺ͓Μʯͷ࢖͍ํ

    debugྗߴΊΕ͹ ͠ΜͲܰ͞ݮ͞ΕΔ͔΋ʁ
  5. 5 ͜Μͳܦݧͳ͍Ͱ͔͢ʁ outputFͷ஋Λ֬ೝ͍ͨ͠ɻ outputF͸input_ʹґଘ͍ͯͯ͠ɺ input_͸outputCʹґଘ͍ͯͯ͠ɺ outputC͸funcCͷhogeʹґଘ͍ͯͯ͠ɺ hoge͸funcBʹґଘ͍ͯͯ͠..........(T T) ਂ͗͢Δʂ

  6. 6 ͱΓ͋͑ͣ͜͏͢ΔΑͶ print debug ʂʂ

  7. 7 େม print debug ΋ѱ͘ͳ͍͠ɺ๻΋Α͘࢖͏ΜͰ͕͢ɺinput_ Λม͑ͨͱ͖ ͷ outputF ͷڍಈΛ֬ೝ͍ͨ͠ͱ͖ͳΜ͔ΊͪΌͪ͘ΌେมͰ͢ΑͶɻ ͦ΋ͦ΋ɺfuncB

    ͔Β funcF ʹ౸ୡ͢Δ·Ͱʹ਺෼͔͔ΔͱͳΔͱ࣌ؒ ΋͔͔ͬͯ͠·͏ɻ
  8. 8 ͔͔࣌ؒΔ Α͘Θ͔ΒΜ͔Β plotͯ͠ΈΔ͔ɻ ͔ͦͬoutputF͸ೋ ࣍ݩ͔ͩΒΤϥʔ ͰͪΌ͏ͳɻ ͱΓ͋͑ͣ γΣΠϓ֬ೝɻ 30

    sec 30 sec 30 sec funcD ʹ౸ୡ͢Δ·Ͱʹ͕͔͔࣌ؒͬͯ͠·͏...
  9. 9 σόοΨ࢖͏ͱָͩΑ pdb, ipdb, IDE, %debug, etc...

  10. 10 .py ͱ .ipynb ෼ੳίϯϖ͸ɺ ϊʔτϒοΫ(.ipynb)Ͱೖ໳͢Δਓ͕ଟ͍ & ࢀߟࢿྉ͕গͳ͍ ͷͰϊʔτϒοΫܗࣜͰ࿩ਐΊ·͢ .ipynb

    JupyterNotebook, JupyterLab, Kaggle, Colab, etc... .py
  11. 11 ͲΕ͕͍͍ʁ(202108࣌఺) pdb %debug ipdb pudb xeus-python JupyterNotebook ˕ ˕

    ̋ ˚ ˚ JupyterLab ˕ ˕ ̋ ˚ ˚ KaggleNotebook ˕ ˕ ̋ ʁ ʁ Colaboratory ˕ ˕ ̋ ʁ ʁ ߴػೳ ˕: Πϯετʔϧෆཁ ̋: Πϯετʔϧඞཁ(؆୯) ˚: Πϯετʔϧඞཁ(ͪΐͬͱΊΜͲ͍͘͞) ʁ: ಈ͔ͨ͜͠ͱͳ͍ Ұ෦Λ঺հ
  12. 12 ಈֶ͔ͤͯ΂Δαϯϓϧ pdbͱ%debugֶ͕΂Δαϯϓϧ࡞Γ·ͨ͠ʂ https://colab.research.google.com/drive/ 1di0EBQ5FaGME82JOLDP0kjaerk1fqakk?usp=shari ng 3ਓͷํʹ ςετϢʔβͱͯ͠ ڠྗͯ͠΋Β͍·ͨ͠ @natsumin_0813

    @tnot_fount @chi1234s
  13. Thanks :)