Notebooks that displays HTML markup between executable Python code
The name Jupyter comes from the combination of Julia, Python, and R (the statistics package).
Jupyter is a web application that runs several separate environments (one on each port).
Each Jupyter notebook contains explanatory text, math equations, code, and visualizations all in one easily sharable document.
Notebooks used to be called “iPython” notebooks before languages other than Python were added.
Below is a guided learning experience. You perform actions in a planned sequence that takes you through various features. Commentary along the way describes concepts to understand.
You will open a notebook, add a Markdown text and add a header while you try various keyboard shortcuts.
This is based on excellent tutorials from several sources:
These occur within a Terminal window:
Make a directory to hold Jupyter session files.
Navigate to a URL containing Jupyter Notebook files.
Notebooks are JSON files with the extension .ipynb. However, “.txt” is added for storage.
analysis of gravitational waves from two colliding blackholes detected by the LIGO experiment.
Sentiment-network.zip from Andrew Trask contains notebooks for sentiment analysis.
Download a Jupyter Notebook file into your folder.
You may have to move downloaded files from your Downloads folder.
In a new Terminal window, enter Jupyter (with & to keep working on the command line):
jupyter notebook &
This creates a (hidden) file .jupyter in your home folder, invokes a web server locally, and pops up to your default browser a tab:
Additional notebook servers increment the port number from 8888.
- Shutdown the server from Terminal by pressing control + C twice.
Create a kernel by clicking on the New drop-down and selecting one.
NOTE: A kernel is each web page you are on.
Click on tab File to show all the files and folders in the current directory.
List all the currently running notebooks by clicking on the Running tab.
Select “Python [Conda root]” for a new window (with tabs).
CAUTION: Just closing the browser leaves a kernel running.
To close and halt the kernel, select File, then Close and Halt.
cd to the folder containing the Jupyter notebook above.
A) Create a conda environment based on the requirements file:
conda install --file requirements.txt
B) Create a stand-alone environment named PDSH with Python 3.5 and all the required package versions:
conda create -n PDSH python=3.5 --file requirements.txt
Source activate the conda environment.
Install packages from within the Conda environment:
conda install jupyter notebook numpy matplotlib scikit-learn bokeh
Click on the Edit tab.
NOTE: Cells are where code is written and run.
Several of the selections have an icon equivalent.
Press Esc key.
Each cell can be changed by just clicking on it.
When the thick left border on a box is colored green, the box is in edit mode.
If you don’t see a blinking cursor in the cell, click in the cell.
To exit from edit mode to display mode, hold down Shift and press Enter.
When a new cell is created, it is in command mode.
When the thick left border on a box is colored blue, the box is in command mode.
When the bar is blue, press H for a help screen about Keyboard shortcuts. It reads:
“Command mode binds the keyboard to notebook level actions.”
When the bar is blue, press A to create a new cell.
press B to create a cell below the currently selected cell.
NOTE: This does not work in Firefox and Internet Explorer, only in Chrome and Apple Safari.
When in command mode, click the little keyboard icon, called the “command palette”.
A panel appears with a search bar.
Press down arrow to scroll down.
Keyboard shortcuts are on the right side.
Enter a command to search for. Helpful for speeding up your workflow instead of looking around in the menus with your mouse.
Press Esc key.
Click on the “Code” drop-down, which specifies what is typed in the cell (input box).
Select Markdown to format syntax for writing web content.
Type in some markdown text.
Two dollar signs begin and end math entries.
To run the cell, click the >| icon (used to mean forward to the end) or press Shift + Enter or Control + Enter to run the Markdown cell,
Click the up/down arrows to position the cell above or below existing runned lines.
Select Heading and add a # to reduce the level before typing heading text.
Open and Rename Notebook
- Click Files tab.
- Click the checkbox to the right of the file name.
- Click the Rename button.
- Remove the “.txt” and press OK.
Click on the file name itself to open the file.
A new tab should appear.
To get the number of milliseconds a function took to run, put %timeit in front of commands to invoke.
To get the number of seconds it took for a cell to run, put %%timeit at the top of the cell.
%pdb at the top of the cell turns debugging on.
Visualization magic keywords
See http://ipython.readthedocs.io/en/stable/interactive/magics.html for docs about magic commands.
- Code to dynamically loaded:
NBConvert code modify the UI and behavior of Jupyter itself on the browser.
nbextensions are installed in the directory of the same name, either system wide or in your user profile. Their entry point is named
Output as HTML
To share a Notebook with others who do not have Notebook installed, convert the Notebook to HTML or Markdown.
PROTIP: Some prefer receiving Markdown text so they paste in blog editing software which formats the Markdown to their own liking.
jupyter nbconvert --to html notebook.ipynb
https://github.com/blog/1995-github-jupyter-notebooks-3 GitHub renders Jupyter Notebooks with Git Large File Support.
http://nbviewer.jupyter.org/ renders notebooks from a GitHub repo or from notebooks stored elsewhere.
Click the View tab.
Turi (Dato) Python algorithms
GraphLab Create from Dato provides scalable “pre-implemented” ML algorithms using Python installed using Anaconda. Entire courses on its use is at:
When the one-year free license is over, note scikit-learn also uses Python with Anaconda.
https://www.youtube.com/watch?v=GxZUdZMPGpQ Large-Scale Deep Learning with TensorFlow Turi, Inc.
Clusters is not longer used to create multiple kernels used in parallel computing.
https://bcourses.berkeley.edu/courses/1267848 Introduction to Data Science at UC Berkeley
Python for Data Analysis by Wes McKinney