Book Image

Python Machine Learning Workbook for Beginners

By : AI Sciences
Book Image

Python Machine Learning Workbook for Beginners

By: AI Sciences

Overview of this book

<p>Machine Learning (ML) is the lifeblood of businesses worldwide. ML tools empower organizations to identify profitable opportunities fast and help them to better understand potential risks. The ever-expanding data, cost-effective data storage, and competitively priced powerful processing continue to drive the growth of ML. </p><p> </p><p>This is the best time you could enter the exciting machine learning universe. Industries are reinventing themselves constantly by developing more advanced data analysis models. These models analyze larger and more complex data than ever while delivering instantaneous and more accurate results on enormous scales. </p><p>In this backdrop, it is evident that hands-on practice is everything in machine learning. Tons of theory will amount to nothing if you don’t have enough hands-on practice. Textbooks and online classes mislead you into a false sense of mastery. The easy availability of learning resources tricks you and you become overconfident. But when you try to apply the theoretical concepts you have learned, you realize it’s not that simple. </p><p> </p><p>This is where projects play a crucial role in your learning journey. Projects are doubtless the best investment of your time. You’ll not only enjoy learning but you’ll also make quick progress. And unlike studying boring theoretical concepts, you’ll find that working on projects is easier to stay motivated. </p><p> </p><p>The projects in this book cover ten different interesting topics. Each project will help you refine your ML skills and apply them in the real world. These projects also present you with an opportunity to enrich your portfolio, making it simpler to find a great job, explore interesting career paths, and even negotiate a higher pay package. Overall, this learning-by-doing book will help you accomplish your machine learning career goals faster. </p><p> </p><p>The code bundle for this course is available at https://www.aispublishing.net/ai-sciences-book</p>
Table of Contents (15 chapters)
1
About the Author

1.3. Environment Setup

1.3.1. Windows Setup

The time has come to install Python on Windows using an IDE. In fact, we will use Anaconda throughout this book, right from installing Python to writing multi-threaded codes in the coming lectures. Now, let us get going with the installation.

This section explains how you can download and install Anaconda on Windows.

Follow these steps to download and install Anaconda.

1.Open the following URL in your browser.
https://www.anaconda.com/distribution/

2.The browser will take you to the following webpage. Select the latest version of Python (3.7 at the time of writing this book). Now, click the Download button to download the executable file. Depending upon the speed of your internet, the file will download within 2–3 minutes.

image

3.Run the executable file after the download is complete. You will most likely find the download file in your download folder. The name of the file should be similar to “Anaconda3- 5.1.0-Windows-x86_64.” The installation wizard will open when you run the file, as shown in the following figure. Click the Next button.

image

4.Now click I Agree on the License Agreement dialog as shown in the following screenshot.

image

5.Check the Just Me radio button from the Select Installation Type dialogue box. Click the Next button to continue.

image

6.Now, the Choose Install Location dialog will be displayed. Change the directory if you want, but the default is preferred. The installation folder should at least have 3 GB of free space for Anaconda. Click the Next button.

image

7.Go for the second option, Register Anaconda as my default Python 3.7 in the Advanced Installation Options dialog box. Click the Install button to start the installation, which can take some time to complete.

image

8.Click Next once the installation is complete.

image

9.Click Skip on the Microsoft Visual Studio Code Installation dialog box.

image

10.You have successfully installed Anaconda on your Windows. Excellent job. The next step is to uncheck both checkboxes on the dialog box. Now, click on the Finish button.

image

1.3.2. Mac Setup

Anaconda’s installation process is almost the same for Mac. It may differ graphically, but you will follow the same steps you followed for Windows. The only difference is that you have to download the executable file, which is compatible with the Mac operating system.

This section explains how you can download and install Anaconda on Mac.

Follow these steps to download and install Anaconda.

1.Open the following URL in your browser.
https://www.anaconda.com/distribution/

2.The browser will take you to the following webpage. Select the latest version of Python for Mac. (3.7 at the time of writing this book). Now, click the Download button to download the executable file. Depending upon the speed of your internet, the file will download within 2–3 minutes.

image

3.Run the executable file after the download is complete. You will most likely find the download file in your download folder. The name of the file should be similar to “Anaconda3-5.1.0-Windows-x86_64.” The installation wizard will open when you run the file, as shown in the following figure. Click the Continue button.

image

4.Now, click, Continue on the Welcome to Anaconda 3 Installer window, as shown in the following screenshot.

image

5.The Important Information dialog will pop up. Simply click Continue to go with the default version that is Anaconda 3.

image

6.Click Continue on the Software License Agreement Dialog.

image

7.It is mandatory to read the license agreement and click the Agree button before you can click the Continue button again.

image

8.Simply click Install on the next window that appears.

image

The system will prompt you to give your password. Use the same password you use to login to your Mac computer. Now, click on Install Software.

image

9.Click Continue on the next window. You also have the option to install Microsoft VSCode at this point.

image

The next screen will display the message that the installation has been completed successfully. Click on the Close button to close the installer.

image

There you have it. You have successfully installed Anaconda on your Mac computer. Now, you can write Python code in Jupyter and Spyder the same way you wrote it in Windows.

1.3.3. Linux Setup

We have used Python’s graphical installers for installation on Windows and Mac. However, we will use the command line to install Python on Ubuntu or Linux. Linux is also more resource-friendly, and the installation of software is particularly easy as well.

Follow these steps to install Anaconda on Linux (Ubuntu distribution).

1.Go to the following link to copy the installer bash script from the latest available version.
https://www.anaconda.com/distribution/

image

2.The second step is to download the installer bash script. Log into your Linux computer and open your terminal. Now, go to /temp directory and download the bash you downloaded from Anaconda’s home page using curl.

3.You should also use the cryptographic hash verification through the SHA-256 checksum to verify the integrity of the installer.

$ sha256sum Anaconda3-5.2.0-Linux-x86_64.sh

You will get the following output.

09f53738b0cd3bb96f5b1bac488e5528df9906be2480fe61df40e0e0d19e3d48 Anaconda3-5.2.0-Linux-x86_64.sh

4.The fourth step is to run the Anaconda Script, as shown in the following figure.

$ bash Anaconda3-5.2.0-Linux-x86_64.sh

The command line will generate the following output. You will be asked to review the license agreement. Keep on pressing Enter until you reach the end.

Output

Welcome to Anaconda3 5.2.0

In order to continue the installation process, please review the license agreement.

Please, press Enter to continue

>>>

Do you approve the license terms? [yes|No]

Type, Yes, when you get to the bottom of the License Agreement.

5.The installer will ask you to choose the installation location after you agree to the license agreement. Simply press Enter to choose the default location. You can also specify a different location if you want.

Output

Anaconda3 will now be installed on this location: /home/tola/anaconda3

- Press ENTER to confirm the location

- Press CTRL-C to abort the installation

- Or specify a different location below

[/home/tola/anaconda3] >>>

The installation will proceed once you press Enter. Once again, you have to be patient as the installation process takes some time to complete.

6.You will receive the following result when the installation is complete. If you wish to use the conda command, type Yes.

Output

Installation finished.

Do you wish the installer to prepend Anaconda3 install location to path in your /home/tola/.bashrc? [yes|no]

[no]>>>

At this point, you will also have the option to download the Visual Studio Code. Type yes or no to install or decline, respectively.

7.Use the following command to activate your brand new installation of Anaconda3.

$ source `/.bashrc

8.You can also test the installation using the conda command.

$ conda list

Congratulations. You have successfully installed Anaconda on your Linux system.

1.3.4. Using Google Colab Cloud Environment

In addition to local Python environments such as Anaconda, you can run deep learning applications on Google Colab, as well, which is Google’s platform for deep learning with GPU support. All the codes in this book have been run using Google Colab. Therefore I would suggest that you use Google Colab, too.

To run deep learning applications via Google Colab, all you need is a Google/Gmail account. Once you have a Google/ Gmail account, you can simply go to:

https://colab.research.google.com/

Next, click on File -> New notebook, as shown in the following screenshot.

image

Next, to run your code using GPU, from the top menu, select Runtime -> Change runtime type, as shown in the following screenshot:

image

You should see the following window. Here from the dropdown list, select GPU, and click the Save button.

image

To make sure you are running the latest version of TensorFlow, execute the following script in the Google Colab notebook cell. The following script will update your TensorFlow version.

pip install --upgrade tensorflow

To check if you are really running TensorFlow version > 2.0, execute the following script.

1. import tensorflow as tf

2. print(tf.__version__)

With Google Cloud, you can import the datasets from your Google drive. Execute the following script. And click on the link that appears, as shown below:

image

You will be prompted to allow Google Colab to access your Google drive. Click the Allow button, as shown below:

image

You will see a link appear, as shown in the following image (the link has been blinded here).

image

Copy the link and paste it in the empty field in the Google Colab cell, as shown below:

image

This way, you can import datasets from your Google drive to your Google Colab environment.

In the next chapter, you will see how to write your first program in Python, along with other Python programming concepts.