Machine Learning and Artificial Intelligence have become the new buzz words in the tech world; literally, everyone seems to have realized how important this field of study is.
A data scientist would agree that you can barely do without using a Jupyter notebook at some point in time, well, if not every time. A wide range of AI/ML engineers has adopted the use of Jupyter Notebook as a tool they use to write and test the algorithms/models.
But what is Jupyter? And why is it referred to as a Notebook?
According to Wikipedia, a notebook is a book or binder of paper of pages, often ruled, used for many purposes such as recording notes or memoranda, writing, drawing or scrap booking.
So basically, we could say a notebook is used to express a particular context, idea, or knowledge using text, diagrams, drawings, pictures, equations, tables, or even charts.
Why then is Jupyter referred to as a notebook?
Because it does exactly what the above stated does! It is used to draft out documents, codes, texts, pictures, equations, draft charts, and visualizations and even draw tables.
What is Jupyter Notebook?
The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations, and narrative text. It uses include data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more.
Most often, the Jupyter Notebook is used in a Python environment. They have very interactive outputs and can be easily shareable, just like a regular notebook.
What can Jupyter Notebook be used for?
Writing multiple languages.
The Jupyter system supports over 100 programming languages (called “kernels” in the Jupyter ecosystem), including Python, Java, R, Julia, Matlab, Octave, Scheme, Processing, Scala, and many more. You can share the code written in Notebook with others.
Here are a few languages that can be written in Jupyter notebook.
Of all languages that can be written with Jupyter, python is the most popular with the notebook. Almost everyone that writes code within the Jupyter environment writes the Python. By default, Jupyter supports Python in their environment without the use of special magic commands.
const text = "hello world"
It allows integrating additional “kernels” – languages. Such a kernel can be installed by following the set of installation instructions here. After installing, run the following command in your Jupyter terminal if on Linux.
jupyter console --kernel=java
Jupyter console 5.1.0
Java 9.0.4+11 :: IJava kernel 1.1.0-SNAPSHOT
Protocol v5.0 implementation by jupyter-jvm-basekernel 2.2.1-SNAPSHOT
Matlab is a high-performance language for technical computing; It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation.
To use Matlab in Jupyter Notebook, you first have to install Jupyter-Matlab. The first thing we need to do is to create a virtual environment.
Open your Jupyter prompt on windows or just your terminal on Linux and type in the following command
conda create -vv -n jmatlab python=3.5 jupyter
Make sure you remain in this terminal, then type the code
Once launched, there should now be an option for both Matlab and python.
Jupyter notebook comes in handy when it comes to writing markdown, and this can be very useful when you want to give a verbose or well-detailed explanation of a piece of code, write documentation, or a dictionary for a particular dataset.
Type the below code in a notebook.
Used for data analysis
Used for numerical analysis
Used for data visualizations
The output should be as follows;
Jupyter Notebooks allows the use of bash script by using the %%bash magic command.
To test, let’s create a folder in your current working directory. Type the following code in a Notebook cell.
Run the code, now check your working directory by typing the code
You will see that the folder Test_Folderhas been added to it. You can also navigate to the folder physically to check.
With the use of Python libraries like matplotlib, you can run and display data visualizations right in your browser.
Let’s try to make a very basic visualization using matplotlib.
We would first import the library
from matplotlib import pyplot as plt
Even more intriguing is we could do 3d visualizations!!
We first need to import the 3d visualization library
from mpl_toolkits import mplot3d
import numpy as np
Then make a 3d projection
fig = plt.figure()
ax = plt.axes(projection='3d')
Our output should look like this
Now, run the following scripts.
def f(x, y):
return np.sin(np.sqrt(x ** 2 + y ** 2))
x = np.linspace(-6, 6, 30)
y = np.linspace(-6, 6, 30)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
ax = plt.axes(projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
Mathematical And Scientific Notations
We can use tools like Latex right inside our Jupyter Notebook type mathematical and scientific equations.
LaTeX is a high-quality typesetting system; it includes features designed for the production of technical and scientific documentation. You can learn more about latex here here. Let’s try to run some simple LaTex codes.
Type in the following LaTex commands
This article just scratches the surface of what could be achieved with the use of Jupyter notebooks. You can find most of the examples in this article in this Jupyter notebook I created here on collaboratory
Python is a very versatile language, and Python developers often have to work with a variety of files and get information stored in them for processing. One popular file format you’re bound to encounter as a Python developer is the Portable Document Format popularly known as PDF