Notebooks are a very interesting coding technique that have risen to prominence recently. Basically, they allow us to write code in a particular language, Python in this case, in an environment where we can see the code, results and comments in a single view. This is extremely useful in scenarios where we want to showcase our techniques and results to our colleagues. Let's take a look at the Notebook within AML Workbench.
iris Notebook |
Page 1 |
Notebook Started |
We also notice is that the top-right corner now says "EDIT MODE" instead of "PREVIEW MODE". This means that we now have the ability to interact with the Notebook. However, we first need to instantiate a "kernel". For clarity, the term "kernel" here refers to the computer science term. You can read more about the other types of kernels here. Basically, without a kernel, we don't have any way of actually running our code. So, let's spin one up.
Kernel Selection |
Notebook Ready |
The creators of this notebook were nice enough to provide some additional information in the notebook. This formatted text is known as "Markdown". Basically, it's a very easy way to add cleanly formatted text to the notebook. You can read more about it here.
Depending on your setup, you may need to run these two commands from the "Command Prompt". We looked at how to use the Command Prompt in the first post in this series. If you run into any issues, try running the commands in the first post and restarting the kernel. Let's look at the first segment of code.
Segment 1 |
We also see one of the major advantages of utilizing notebooks. The "%azureml history off" command creates an output in the console. The notebook captures this and displays it just below the code segment. We'll see this in a much more useful manner later in this post. Let's check out the next code segment.
In Python, we have a few options for importing existing objects. Basically, libraries contain modules, which contain functions. We have the option of importing the entire library, an individual module within that library or an individual function within that module. In Python, we often refer to modules and functions using "dot notation". We'll see this a little later. We bring it up now because it can be cumbersome to refer to the "matplotlib.pyplot.figure" function using its full name. So, we see that the above code aliases this module using the "as plt" code snippet. Here's a brief synopsis of what each of these libraries/modules do, along with links.
pickle: Serializes and Deserializes Python Objects
sys: Contains System-Specific Python Parameters and Functions
os: Allows Interaction with the Operating System
numpy: Allows Array-based Processing of Python Objects
matplotlib: Allows 2-Dimensional Plotting
sklearn (aka scikit-learn): Contains Common Machine Learning Capabilities
azureml: Contains Azure Machine Learning-specific Functions
Let's move on to the next segment.
Segment 3 |
Finally, this code prints the current version of Python we are utilizing. Again, we see the advantage of using notebooks, as we get to see the code and the output in a single block. Let's move on the final code segment for this post.
Segment 4 |
Hopefully, this post opened your minds to the possibilities of using Python Notebooks within AML Workbench. Notebooks are quickly becoming the industry standard technique for sharing data science experiments, and will no doubt play a major role in the day-to-day tasks of most Data Scientists. Stay tuned for the next post where we'll walk through the data science code within the "iris" notebook. Thanks for reaching. We hope you found this informative.
Brad Llewellyn
Senior Analytics Associate - Data Science
Syntelli Solutions
@BreakingBI
www.linkedin.com/in/bradllewellyn
llewellyn.wb@gmail.com
No comments:
Post a Comment