Читать книгу Machine Learning For Dummies - John Paul Mueller, John Mueller Paul, Luca Massaron - Страница 80

Creating a new notebook

Оглавление

Every new notebook is like a file folder. You can place individual examples within the file folder, just as you would sheets of paper into a physical file folder. Each example appears in a cell. You can put other sorts of things in the file folder, too, but you see how these things work as the book progresses. Use these steps to create a new notebook:

1 Click New ⇒ Python 3.A new tab opens in the browser with the new notebook, as shown in Figure 4-6. Notice that the notebook contains a cell and that Notebook has highlighted the cell so that you can begin typing code in it. The title of the notebook is Untitled right now. That's not a particularly helpful title, so you need to change it.

2 Click Untitled on the page.Notebook asks what you want to use as a new name.

3 Type ML4D2E; 04; Sample and press Enter.The new name tells you that this is a file for Machine Learning For Dummies, 2nd Edition, Chapter 4, Sample.ipynb. Using this naming convention will let you easily differentiate these files from other files in your repository.


FIGURE 4-6: A notebook contains cells that you use to hold code.

Of course, the Sample notebook doesn’t contain anything just yet. Place the cursor in the cell, and type the following code:

import sysprint('Python Version:\n', sys.version) import osresult = os.popen('conda list anaconda$').read()print('\nAnaconda Version:\n', result)

The first print() statement outputs the Python version number for your installation. The second print() statement prints the Anaconda version number for your installation. Both of these outputs depend on using external code using the import statement. The second call works directly with a command-line utility named conda that you see used several times in this book.

Click the Run button (the button with the right-pointing arrow on the toolbar). You see the output shown in Figure 4-7. The version numbers for your setup should match the version numbers shown in Figure 4-7. The output is part of the same cell as the code. However, Notebook visually separates the output from the code so that you can tell them apart. Notebook automatically creates a new cell for you.


FIGURE 4-7: Notebook uses cells to store your code.

When you finish working with a notebook, shutting it down is important. To close a notebook, choose File ⇒ Close and Halt. You return to the home page, where you can see the notebook you just created added to the list.

Machine Learning For Dummies

Подняться наверх