Machine Learning For Dummies. John Paul Mueller

Читать онлайн книгу.

Machine Learning For Dummies - John Paul Mueller


Скачать книгу
you need to click Quit in the upper-right corner of the client window to exit Notebook. Otherwise, the Notebook server remains running in the background and you leave your environment in an uncertain state, which could cause data loss in some situations. After you click Quit, you see a Server Stopped message box, which you can dismiss by clicking the X in the upper-right corner. Close the browser window.

      If you’re done working with Anaconda, you choose File ⇒ Quit in the Anaconda Navigator window. During the first (and possibly subsequent) shutdown, you see a Quit Application dialog box, where you must click Yes to end Anaconda Navigator. If you don’t want to see this dialog box again, you can remove it by selecting Don’t Show Again before you click Yes.

      

Sometimes the server shutdown process takes longer than expected. In this case, Anaconda Navigator displays a message telling you that it’s still working in the background. Allow it to complete whatever processes it needs to complete before you quit. You could also see this message if you didn’t quit Jupyter Notebook correctly. In this case, you need to end Anaconda Navigator because the server will never stop.

      Defining the code repository

      The code you create and use in this book will reside in a repository on your hard drive. Think of a repository as a kind of filing cabinet where you put your code. Notebook opens a drawer, takes out the folder, and shows the code to you. You can modify it, run individual examples within the folder, add new examples, and simply interact with your code in a natural manner. The following sections get you started with Notebook so that you can see how this whole repository concept works.

      Defining the book’s folder

      It pays to organize your files so that you can access them more easily later. This book keeps your Python files in the ML4D2E and ML4D2ER folders. However, the book focuses on the Python code, so the following steps show how to create the Python folder within Notebook.

      1 After launching Notebook, choose New ⇒ Folder.Notebook creates a new folder named Untitled Folder, as shown in Figure 4-5. The file will appear in alphanumeric order, so you may not initially see it. You must scroll down to the correct location.FIGURE 4-5: New folders will appear with a name of Untitled Folder.

      2 Select the box next to the Untitled Folder entry.

      3 Click Rename at the top of the page.You see a Rename Directory dialog box.

      4 Type ML4D2E and click OK.Notebook changes the name of the folder for you.

      5 Click the new ML4D2E entry in the list.Notebook changes the location to the ML4D2E folder where you perform tasks related to the exercises in this book.

      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.

Snapshot of a notebook contains cells that the user use to hold code.

      FIGURE 4-6: A notebook contains cells that you use to hold 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.

Snapshot of the Notebook using cells to store the code.

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

      Exporting a notebook

      Creating notebooks and keeping them all to yourself isn't much fun. At some point, you want to share them with other people. To perform this task, you must export your notebook from the repository to a file. You can then send the file to someone else, who will import it into his or her repository.

      The previous section shows how to create a notebook named ML4D2E; 04; Sample. You can open this notebook by clicking its entry in the repository list. The file reopens so that you can see your code again. To export this code, choose File ⇒ Download As ⇒ Notebook (.ipynb). What you see next depends on your browser, but you generally see some sort of dialog box for saving the notebook as a file. Use the same method for saving the IPython Notebook file as you use for any other file you save using your browser.

      Removing a notebook

      Sometimes notebooks get outdated or you simply don’t need to work with them any longer. Rather than allow your repository to get clogged with files you don’t need, you can remove these unwanted notebooks from the list. Use these steps to remove the file:

      1 Select the box next to the ML4D2E; 04; Sample.ipynb entry.

      2 Click the trash can icon (Delete) at the top of the page.You see a Delete notebook warning message.

      3 Click Delete.The file gets removed from the list.

      Importing a notebook

      To use the source code from this book, you must import the downloaded files into your repository. The source code comes in an archive file that you extract to a location on your hard drive. The archive contains a list of .ipynb (Notebook) files containing the source code for this book (see the Introduction for details on downloading the source code). The following steps tell how to import these files into your repository:

      1 Click Upload at the


Скачать книгу