Getting Started With Machine Learning Instructions
Getting Started With Machine Learning Instructions
A 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. Uses include data cleaning and transformation, numerical simulation,
statistical modeling, data visualization, and machine learning.
After completing this simulation, you will know how to do the following:
Duration
This simulation requires approximately 30 minutes to complete.
5. This page lists all notebook instances. Running notebooks have a Status of
InService.
A new notebook opens, and the Python 3 kernel starts. The kernel provides the
ability to run Python code in this notebook.
Menus
In the notebook, review the options in the menu bar:
By default, the default file type for a notebook is .ipynb. A .ipynb file is a text file
that describes the contents of your notebook in a format called JavaScript Object
Notation (JSON). Each cell and its contents, including image attachments that have
been converted into strings of text, is listed in the file along with some metadata.
Code cells
11. Choose the first notebook cell, and enter the following Python code:
print('Hello Jupyter!')
One of the notebook features is autocomplete. For example, if you type pri and then
press Tab, the text completes to print .
12. On the toolbar, choose Run to run the code in the cell.
Note: To run the code in the cell in a live Jupyter environment, you can also press
Shift + Enter.
After you run the cell, the output displays just below the code. Notice that the cell's
label also changed from In [ ] to In [1]. A new cell also appears below the output.
Next, you will write some code that will not return results immediately. When you
are working with a large dataset in a notebook, code will often take some time to
run.
14. Choose the new cell to populate the code below, which will show you what
the notebook looks like when code is running in the background.
Note: In a live Jupyter environment you would enter and run the following
code in a code cell.
import time
time.sleep(10)
While the code is running, notice that the cell label displays In [*] with an
asterisk in the brackets, as shown in the following image. This indicates that
the kernel is busy, and the cell is currently running the task.
16. Choose the new cell to populate the following code, which performs a few
basic arithmetic operations.
Note: In a live Jupyter environment you would enter and run the following
code in a code cell.
a = 12
b=2
print(a + b)
print(a**b)
print(a/b)
Markdown cells
The primary cell types in a notebook are code and Markdown. A Markdown cell
displays text, and you can use the Markdown markup language to format the text.
The type for the current cell changes from code to Markdown.
19. Choose the new Markdown cell to see how the following is shown as text.
Note: In a live Jupyter environment you would enter and run the following code
in a code cell.
# Technical Report
20. To run the cell and render the Markdown, choose Run.
By using a combination of code cells and Markdown cells, you can create a
document that runs Python code and includes text to explain what the code does.
21. Choose the new cell, and change the cell type to Markdown.
22. Choose the new Markdown cell to see the formatted text for how the
headers will look.
Note: In a live Jupyter environment you would enter and run the following code
in a code cell.
# Header 1
## Header 2
### Header 3
#### Header 4
The output shows the different heading levels that you can use in Markdown.
Note: In a live Jupyter environment you would enter and run the following
code in a code cell.
- Item 1
- Item 2
- Item 3
With Markdown, you can also insert a code example for your reader to review but
not run. For inline code, surround the code with backticks ( ` ).
To insert a code block, use three backticks ( ``` ) before and after the code block. A
best practice is to specify the code language after the first three backticks.
26. To create a code block, enter and run the following text in a Markdown cell:
```python
s = 'Syntax highlighting for Python'
print(x)x ```
Shell commands
You can also run shell commands within code cells. In the next few steps, you will
run a few basic Linux commands.
ls -l
The output shows the contents of the folder that the notebook is in.
To write and run multiple lines of bash code, use the %%bash prompt before your
commands.
%%bash
pwd
ls -l
date
The output displays the current working directory, contents of the folder the
notebook is in, and current date and time.
Note: For a list of keyboard shortcuts and commands, choose the keyboard icon on
the toolbar, as shown in the following image.
Before you download the notebook, you will first clear the outputs and re-run all of
the cells. Clearing the outputs helps to ensure that the notebook doesn't contain
intermediary output or have a stale state. It also helps to ensure that everything
runs as it should if you share the notebook.
31. To clear the output for all cells, choose Cell > All Output > Clear.
32. To restart the kernel and re-run all of the cells, choose Kernel > Restart &
Run All.
Wait for the cells to finish running. Make sure that the brackets in each cell label
contain a number and that all cells ran successfully.
33. To export the notebook, choose File > Download as > HTML (.html).
34. In a web browser, open and review the HTML file that you just downloaded.
35. Return to the notebook and download it as a Notebook .ipynb file.
Now you have two files. The HTML file is convenient to view and share quickly. You
can upload or share the notebook (.ipynb) file as needed.
Summary
In this simulation, you created a Jupyter notebook and learned about notebook
functionality. You learned that you can use a notebook to learn or teach a
programming language, such as Python. You can also use a notebook to share data.
Simulation complete
Congratulations! You have completed the simulation.
36. Choose End Simulation at the top of this page, and then select Yes to
confirm that you want to end the simulation.
A panel indicates that DELETE has been initiated... You may close this message box
now.
37. To close the panel, choose the X icon in the upper-right corner.
Additional resources
For more information about AWS Training and Certification, see
https://aws.amazon.com/training/.
To share any suggestions or corrections, use the AWS Training and Certification
Contact Form.
© 2021 Amazon Web Services, Inc. and its affiliates. All rights reserved. This work may
not be reproduced or redistributed, in whole or in part, without prior written permission
from Amazon Web Services, Inc. Commercial copying, lending, or selling is prohibited.