31,19 €
The Jupyter Notebook allows you to create and share documents that contain live code, equations, visualizations, and explanatory text. The Jupyter Notebook system is extensively used in domains such as data cleaning and transformation, numerical simulation, statistical modeling, and machine learning. Learning Jupyter 5 will help you get to grips with interactive computing using real-world examples.
The book starts with a detailed overview of the Jupyter Notebook system and its installation in different environments. Next, you will learn to integrate the Jupyter system with different programming languages such as R, Python, Java, JavaScript, and Julia, and explore various versions and packages that are compatible with the Notebook system. Moving ahead, you will master interactive widgets and namespaces and work with Jupyter in a multi-user mode.
By the end of this book, you will have used Jupyter with a big dataset and be able to apply all the functionalities you’ve explored throughout the book. You will also have learned all about the Jupyter Notebook and be able to start performing data transformation, numerical simulation, and data visualization.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 191
Veröffentlichungsjahr: 2018
Copyright © 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Pravin DhandreAcquisition Editor: Tushar GuptaContent Development Editor: Chris D'cruzTechnical Editor: Suwarna PatilCopy Editor: Safis EditingProject Coordinator: Nidhi JoshiProofreader: Safis EditingIndexer: Priyanka DhadkeGraphics: Tom ScariaProduction Coordinator: Arvindkumar Gupta
First published: November 2016 Second edition: August 2018
Production reference: 1290818
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-78913-740-8
www.packtpub.com
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Dan Toomey has been developing application software for over 20 years. He has worked in a variety of industries and companies, in roles from sole contributor to VP/CTO-level. For the last few years he has been contracting for companies in the eastern Massachusetts area. Dan has been contracting under Dan Toomey Software Corp. Dan has also written R for Data Science, Jupyter for Data Sciences, and the Jupyter Cookbook, all with Packt.
Juan Tomás Oliva Ramos is an environmental engineer from University of Guanajuato, Mexico, with a master's degree in administrative engineering and quality. He has more than 5 years of experience in management and development of patents, technological innovation projects, and technological solutions through the statistical control of processes. He has been a teacher of statistics, entrepreneurship, and technological development since 2011. He has developed prototypes via programming and automation technologies for the improvement of operations, which have been registered for patents.
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Title Page
Copyright and Credits
Learning Jupyter 5 Second Edition
Packt Upsell
Why subscribe?
PacktPub.com
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews
Introduction to Jupyter
First look at Jupyter
Installing Jupyter
Notebook structure
Notebook workflow
Basic Notebook operations
File operations
Duplicate
Rename
Delete
Upload
New text file
New folder
New Python 3
Security in Jupyter
Security digest
Trust options
Configuration options for Jupyter
Summary
Jupyter Python Scripting
Basic Python in Jupyter
Python data access in Jupyter
Python pandas in Jupyter
Python graphics in Jupyter
Python random numbers in Jupyter
Summary
Jupyter R Scripting
Adding R scripting to your installation
Adding R scripts to Jupyter on macOS
Adding R scripts to Jupyter on Windows
Adding R packages to Jupyter
R limitations in Jupyter
Basic R in Jupyter
R dataset access
R visualizations in Jupyter
R 3D graphics in Jupyter
R 3D scatterplot in Jupyter
R cluster analysis
R forecasting
R machine learning
Dataset
Summary
Jupyter Julia Scripting
Adding Julia scripting to your installation
Adding Julia scripts to Jupyter
Adding Julia packages to Jupyter
Basic Julia in Jupyter
Julia limitations in Jupyter
Standard Julia capabilities
Julia visualizations in Jupyter
Julia Gadfly scatterplot
Julia Gadfly histogram
Julia Winston plotting
Julia Vega plotting
Julia PyPlot plotting
Julia parallel processing
Julia control flow
Julia regular expressions
Julia unit testing
Summary
Jupyter Java Coding
Adding the Java kernel to your installation
Installing Java 9 or later
A Jupyter environment is required
Configuring IJava
Downloading the IJava project from GitHub
Building and installing the kernel
Available options
Jupyter Java console
Jupyter Java output
Java Optional
Java compiler errors
Java lambdas
Java Collections
Java streams
Java summary statistics
Summary
Jupyter JavaScript Coding
Adding JavaScript scripting to your installation
Adding JavaScript scripts to Jupyter on macOS or Windows
JavaScript Hello World Jupyter Notebook
Adding JavaScript packages to Jupyter
Basic JavaScript in Jupyter
JavaScript limitations in Jupyter
Node.js d3 package
Node.js stats-analysis package
Node.js JSON handling
Node.js canvas package
Node.js plotly package
Node.js asynchronous threads
Node.js decision-tree package
Summary
Jupyter Scala
Installing the Scala kernel
Scala data access in Jupyter
Scala array operations
Scala random numbers in Jupyter
Scala closures
Scala higher-order functions
Scala pattern matching
Scala case classes
Scala immutability
Scala collections
Named arguments
Scala traits
Summary
Jupyter and Big Data
Apache Spark
Installing Spark on macOS
Windows install
First Spark script
Spark word count
Sorted word count
Estimate pi
Log file examination
Spark primes
Spark text file analysis
Spark evaluating history data
Summary
Interactive Widgets
Installing widgets
Widget basics
Interact widget
Interact widget slidebar
Interact widget checkbox
Interact widget textbox
Interact dropdown
Interactive widget
Widgets
The progress bar widget
The listbox widget
The text widget
The button widget
Widget properties
Adjusting widget properties
Adjusting properties
Widget events
Widget containers
Summary
Sharing and Converting Jupyter Notebooks
Sharing Notebooks
Sharing Notebooks on a Notebook server
Sharing encrypted Notebooks on a Notebook server
Sharing Notebooks on a web server
Sharing Notebooks through Docker
Sharing Notebooks on a public server
Converting Notebooks
Notebook format
Scala format
HTML format
Markdown format
Restructured text format
LaTeX format
PDF format
Summary
Multiuser Jupyter Notebooks
A sample interactive Notebook
JupyterHub
Installation
Operation
Continuing with operations
JupyterHub summary
Docker
Installation
Starting Docker
Building your Jupyter image for Docker
Docker summary
Summary
What's Next?
JupyterHub
JupyterLab
Scale
Custom frontends
Interactive computing standards
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
Learning Jupyter discusses using Jupyter to record your scripts and produce results for data analysis projects. Jupyter allows data scientists to record their complete analysis process, much in the same way that other scientists use a lab notebook for recording tests, progress, results, and conclusions. Jupyter works in a variety of operating systems, and this book covers the use of Jupyter in Windows and macOS, along with the various steps necessary to enable your specific needs. Jupyter supports a variety of scripting languages by the addition of language engines, so the user can use their particular script in a native fashion.
This book is written for readers who wants to portray software solutions to others in a natural programming context. Jupyter provides a mechanism to execute a number of different languages and stores the results directly for display, as if the user ran those scripts on their own machine.
Chapter 1, Introduction to Jupyter, investigates the various user interface elements available in a notebook. We will learn how to install the software on a macOS or a PC. We will expose the notebook structure. We will see the typical workflow used when developing a notebook. We will walk through the user interface operations available in a Notebook. And lastly, we will see some of the configuration options available to advanced users for their notebook.
Chapter 2, Jupyter Python Scripting, walks through a simple notebook and the underlying structure. Then, we will see an example of using pandas and looked at a graphics example. Finally, we will look at an example using random numbers in a Python script.
Chapter 3, Jupyter R Scripting, adds the ability to use R scripts in our Jupyter Notebook. We will add an R library that's not included in the standard R installation, and we will make a Hello World script in R. We will then see R data access built-in libraries and some of the simpler graphics and statistics that are automatically generated. We will use an R script to generate 3D graphics in a couple of different ways. We will then perform a standard cluster analysis (which I think is one of the basic uses of R) and use one of the forecasting tools. We will also build a prediction model and test its accuracy.
Chapter 4, Jupyter Julia Scripting, adds the ability to use Julia scripts in our Jupyter Notebook. We will add a Julia library that's not included in the standard Julia installation. We will see the basic features of Julia in use, and also outline some of the limitations that are encountered using Julia in Jupyter. We will display graphics using some of the available graphics packages. Finally, we will see parallel processing in action, a small control flow example, and how to add unit testing to your Julia script.
Chapter 5, Jupyter Java Coding, explains how to install the Java engine into Jupyter. We will see examples of the different output presentations available from Java in Jupyter. Then, we will investigate using optional fields. We will see what a compile error looks like in Java in Jupyter. Next, we will see several examples of lambdas. We will use collections for several purposes. Lastly, we will generate summary statistics for one of the standard datasets.
Chapter 6, Jupyter JavaScript Coding, shows how to add JavaScript to our Jupyter Notebook. We will see some of the limitations of using JavaScript in Jupyter. We will look at examples of several packages that are typical of Node.js coding, including graphics, statistics, built-in JSON handling, and creating graphics files with a third-party tool. We will also see how multithreaded applications can be developed using Node.js under Jupyter. Lastly, we will use machine learning to develop a decision tree.
Chapter 7, Jupyter Scala, explains how to install Scala for Jupyter. We will use Scala coding to access large datasets. We will see how Scala can manipulate arrays. We will generate random numbers in Scala. There are examples of higher-order functions and pattern matching. We will use case classes. We will see examples of immutability in Scala. We will build collections using Scala packages, and we will look at Scala traits.
Chapter 8, Jupyter and Big Data, discusses using Spark functionality via Python coding for Jupyter. First, we will install the Spark additions to Jupyter on a Windows machine and a macOS machine. We will write an initial script that just read lines from a text file. We will go further and determine the word count in that file. We will add sorting to the results. There is a script to estimate pi. We will evaluate web log files for anomalies. We will determine a set of prime numbers, and we will evaluate a text stream for some characteristics.
Chapter 9, Interactive Widgets, explains how to add widgets to our Jupyter installation. We will use the interact and interactive widgets to produce a variety of user input controls. We will then look at the widgets package in depth to investigate some of the available user controls, properties available in the containers, and events that can be emitted from the controls, and we'll how to build containers of controls.
Chapter 10, Sharing and Converting Jupyter Notebooks, covers how to share notebooks on a Notebook server. We will add a notebook to a web server distribute it using GitHub. We will also look into converting our notebooks into different formats, such as HTML and PDF.
Chapter 11, Multiuser Jupyter Notebooks, shows how to expose a notebook so that multiple users can use a Notebook at the same time. We will see an example of the sharing error occurring. We will install a Jupyter server that addresses the problem, and we will use Docker to alleviate the issue as well.
Chapter 12, What's Next?, looks into some ideas that may be incorporated into Jupyter in the future.
The steps in this book assume you have a modern Windows or macOS with internet access. There are several points where you will need to install software, so you will need administrative privileges on the machine to do so.
The expectation is you have one or more favorite implementation languages you wish to use on Jupyter.
You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register at
www.packtpub.com
.
Select the
SUPPORT
tab.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR/7-Zip for Windows
Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Learning-Jupyter-5-Second-Edition. In case there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Feedback from our readers is always welcome.
General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packtpub.com.
Jupyter is a tool that allows data scientists to record their complete analysis process, much in the same way other scientists use a Lab Notebook to record tests, progress, results, and conclusions.
The Jupyter product was originally developed as part of the IPython project. The IPython project was used to provide interactive online access to Python. Over time, it became useful to interact with other data analysis tools, such as R, in the same manner. With this split from Python, the tool grew into its current manifestation of Jupyter. IPython is still an active tool that's available for use. The name Jupyter itself is derived from the combination of Julia, Python, and R.
Jupyter is available as a web application from a number of places. It can also be used locally over a wide variety of installations. In this book, we will be exploring using Jupyter on a macOS and a Windows PC, as well as over the internet with other providers.
With Jupyter 5.0, there were significant enhancements for the following:
Cell tagging
Customizing keyboard shortcuts
Copying and pasting cells between Notebooks
A more attractive default style for tables
In this chapter, we will cover the following topics:
First look at Jupyter
Installing Jupyter
Notebook structure
Notebook workflow
Basic Notebook operations
Security in Jupyter
Configuration options for Jupyter
Here is a sample opening page when using Jupyter (this screenshot is on a Windows machine):
You should get yourself acquainted with the environment. The Jupyter user interface has a number of components:
The product title,
Jupyter
, in the top left (as expected). The logo and the title name are clickable and will return you to the Jupyter Notebook home page.
There are three tabs which are displayed:
Files
,
Running
, and
Clusters
:
The
Files
tab shows the list of files in the current directory of the page (described later on in this section).
The
Running
tab presents another screen, which shows the currently running processes and Notebooks. The drop-down lists for
Terminals
and
Notebooks
are populated with their running members:
The
Clusters
tab presents another screen which displays a list of available clusters. This topic is covered in a later chapter:
In the top right corner of the screen, are three buttons:
Upload
,
New
(menu), and a
Refresh notebook list
button.
The
Upload
button is used to add files to the Notebook space. You may also just drag and drop as you would when handling files. Similarly, you can drag and drop Notebooks into specific folders as well.
The menu with
New
at the top presents a further menu of the Notebook for the different Notebook engines that have been installed (I had installed Jupyter earlier these are not default values)
Javascript (
Node.js)
,
Julia 0.6.1
,
Python 2
(which will not be covered in this book), and
Python 3
. The additional
Other
menu items are
Text File
,
Folder
,
and
Terminal
:
The
Text File
option is used to add a text file to the current directory. Jupyter will open a new browser window for you, running a text editor. The text entered is automatically saved and will be displayed in your Notebook f
iles and directory
display:
The
Folder
option creates a new folder with the name
Untitled Folder
. Remember that all of the file and folder names are editable:
The
Terminals
option is used to open a new Terminal (command) window. The resulting display on a Windows machine looks as follows:
The
Python 3