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

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

fkubota
August 17, 2021

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

fkubota

August 17, 2021
Tweet

More Decks by fkubota

Other Decks in Programming

Transcript

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

    View full-size slide

  2. 2
    ࣗݾ঺հ
    fkubota (Twitter, Kaggle)
    - όϯυϧΧʔυͷձࣾ(ΧϯϜ)ͰػցֶशΤϯδχΞ
    - Kaggle Expert
    - ԭೄग़਎(౦ژʹग़͖ͯͯ3೥൒)
    - ෺ཧֶՊग़਎(ڧ૬ؔిࢠܥɺ4.2KͷӷମϔϦ΢Ϝʹ࣓ੑମಥͬࠐΜͰͨ)
    - ϓϩάϥϛϯάྺ͸2೥൒͙Β͍
    - झຯ
    - ૣى͖(4࣌൒ىচ)
    - Kaggle
    - ίʔώʔɺϏʔϧɺ΢ΟεΩʔ
    - ಡॻɺ෺ཧɺ఩ֶ

    View full-size slide

  3. 3
    Contents
    debug ʹ͍ͭͯ JupyterNotebookͰ
    debug ʹೖ໳
    ͳͥσόοΨ͕ඞཁ͔ͱ
    ͔ɻ
    ෼ੳίϯϖͰඞͣͱߦͬͯ
    ͍͍΄Ͳ࢖͏
    JupyterNotebookͰͷdebug
    ํ๏ʹ͍ͭͯ؆୯ʹ঺հɻ
    ओʹϏΪφʔʹ޲͚ͯʂ

    View full-size slide

  4. 4
    ͋Δ͋Δʁ
    ίϯϖ΍ͬͨΔͰʔʂ
    ͜ͷϊʔτϒοΫͰೖ໳͠Α͏ɻ
    ͏ʔʔʔΜɻ
    ਓͷίʔυಡΉͷ͠ΜͲ͍ɻ
    ࣗ෼ͷ؀ڥͩͱಈ͔ͳ͍ͷͰमਖ਼͕ඞཁɻ
    ͽ͑Μ͑ͯ͜ͺ͓Μɻ*1
    *1 ࠓ͞Βฉ͚ͳ͍ʮͽ͑Μʯͱʮͺ͓Μʯͷ࢖͍ํ
    debugྗߴΊΕ͹
    ͠ΜͲܰ͞ݮ͞ΕΔ͔΋ʁ

    View full-size slide

  5. 5
    ͜Μͳܦݧͳ͍Ͱ͔͢ʁ
    outputFͷ஋Λ֬ೝ͍ͨ͠ɻ
    outputF͸input_ʹґଘ͍ͯͯ͠ɺ
    input_͸outputCʹґଘ͍ͯͯ͠ɺ
    outputC͸funcCͷhogeʹґଘ͍ͯͯ͠ɺ
    hoge͸funcBʹґଘ͍ͯͯ͠..........(T T)
    ਂ͗͢Δʂ

    View full-size slide

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

    View full-size slide

  7. 7
    େม
    print debug ΋ѱ͘ͳ͍͠ɺ๻΋Α͘࢖͏ΜͰ͕͢ɺinput_ Λม͑ͨͱ͖
    ͷ outputF ͷڍಈΛ֬ೝ͍ͨ͠ͱ͖ͳΜ͔ΊͪΌͪ͘ΌେมͰ͢ΑͶɻ
    ͦ΋ͦ΋ɺfuncB ͔Β funcF ʹ౸ୡ͢Δ·Ͱʹ਺෼͔͔ΔͱͳΔͱ࣌ؒ
    ΋͔͔ͬͯ͠·͏ɻ

    View full-size slide

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

    View full-size slide

  9. 9
    σόοΨ࢖͏ͱָͩΑ
    pdb, ipdb, IDE, %debug, etc...

    View full-size slide

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

    View full-size slide

  11. 11
    ͲΕ͕͍͍ʁ(202108࣌఺)
    pdb %debug ipdb pudb xeus-python
    JupyterNotebook ˕ ˕ ̋ ˚ ˚
    JupyterLab ˕ ˕ ̋ ˚ ˚
    KaggleNotebook ˕ ˕ ̋ ʁ ʁ
    Colaboratory ˕ ˕ ̋ ʁ ʁ
    ߴػೳ
    ˕: Πϯετʔϧෆཁ
    ̋: Πϯετʔϧඞཁ(؆୯)
    ˚: Πϯετʔϧඞཁ(ͪΐͬͱΊΜͲ͍͘͞)
    ʁ: ಈ͔ͨ͜͠ͱͳ͍
    Ұ෦Λ঺հ

    View full-size slide

  12. 12
    ಈֶ͔ͤͯ΂Δαϯϓϧ
    pdbͱ%debugֶ͕΂Δαϯϓϧ࡞Γ·ͨ͠ʂ
    https://colab.research.google.com/drive/
    1di0EBQ5FaGME82JOLDP0kjaerk1fqakk?usp=shari
    ng
    3ਓͷํʹ
    ςετϢʔβͱͯ͠
    ڠྗͯ͠΋Β͍·ͨ͠
    @natsumin_0813
    @tnot_fount
    @chi1234s

    View full-size slide