Skip to content

Instantly share code, notes, and snippets.

@prerakmody
Last active June 9, 2019 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prerakmody/9df716756830d3ed998b807f1fd4d78b to your computer and use it in GitHub Desktop.
Save prerakmody/9df716756830d3ed998b807f1fd4d78b to your computer and use it in GitHub Desktop.
Jupyter Notebook Hacks

Fresh Install

  • pip install jupyter

Check Installations

  • pip freeze | grep jupyter
  • pip freeze | grep ipy
  • pip freeze | grep notebook

Notes

  • To upgrade any specific package : pip install --upgrade
  • Checking install directory : whereis jupyter

My Latest - 28/05/2019

  • pip freeze | grep jupyter
    • jupyter==1.0.0
      jupyter-client==5.2.4
      jupyter-console==6.0.0
      jupyter-core==4.4.0
      
  • pip freeze | grep ipy
    • ipydatawidgets==3.0.0
      ipykernel==5.1.1
      ipython==7.5.0
      ipython-genutils==0.2.0
      ipyvolume==0.4.5
      ipywebrtc==0.3.0
      ipywidgets==7.2.1
      scipy==0.19.1
      
  • pip freeze | grep note
    • notebook==5.7.8
      

Line Profiler - lprun

  • Useful to understand the memory and time consumption of each line
    • pip install line_profiler
    • %load_ext line_profiler
    • %lprun?
    • %lprun -f classifier.train classifier.train(X_train, W, Y_train)

Memory Profiles -

  • Profiles the memory consumption of a file
    • Step1 - create file
      •  %%file testfunc.py
         def testfunc(X_train, Y_train):
        
    • Step2 - import file and use memory profiler
    • pip install memory_profiler
    • %load_ext memory_profiler
    • from testfunc import testfunc
    • %mprun -f testfunc testfunc(X_train, Y_train)

timeit

  • %timeit -n 5 classifier.train(X_train, W, Y_train)

AutoReload

  • reload a file in jupyter notebook that you are editing in a .py file
  • %load_ext autoreload
  • %autoreload 2 #reload all modules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment