Book Image

The Applied Artificial Intelligence Workshop

By : Anthony So, William So, Zsolt Nagy
Book Image

The Applied Artificial Intelligence Workshop

By: Anthony So, William So, Zsolt Nagy

Overview of this book

You already know that artificial intelligence (AI) and machine learning (ML) are present in many of the tools you use in your daily routine. But do you want to be able to create your own AI and ML models and develop your skills in these domains to kickstart your AI career? The Applied Artificial Intelligence Workshop gets you started with applying AI with the help of practical exercises and useful examples, all put together cleverly to help you gain the skills to transform your career. The book begins by teaching you how to predict outcomes using regression. You will then learn how to classify data using techniques such as k-nearest neighbor (KNN) and support vector machine (SVM) classifiers. As you progress, you’ll explore various decision trees by learning how to build a reliable decision tree model that can help your company find cars that clients are likely to buy. The final chapters will introduce you to deep learning and neural networks. Through various activities, such as predicting stock prices and recognizing handwritten digits, you’ll learn how to train and implement convolutional neural networks (CNNs) and recurrent neural networks (RNNs). By the end of this applied AI book, you’ll have learned how to predict outcomes and train neural networks and be able to use various techniques to develop AI and ML models.
Table of Contents (8 chapters)
Preface

About the Book

You already know that Artificial Intelligence (AI) and Machine Learning (ML) are present in many of the tools you use in your daily routine. But do you want to be able to create your own AI and ML models and develop your skills in these domains to kickstart your AI career?

The Applied Artificial Intelligence Workshop gets you started with applying AI with the help of practical exercises and useful examples, all put together cleverly to help you gain the skills to transform your career.

The book begins by teaching you how to predict outcomes using regression. You'll then learn how to classify data using techniques such as K-Nearest Nneighbor (KNN) and Support Vector Machine (SVM) classifiers. As you progress, you'll explore various decision trees by learning how to build a reliable decision tree model that can help your company find cars that clients are likely to buy. The final chapters will introduce you to deep learning and neural networks. Through various activities, such as predicting stock prices and recognizing handwritten digits, you'll learn how to train and implement Convolutional Neural Networks (CNNs) and Recurrent Neural Networks (RNNs).

By the end of this applied AI book, you'll have learned how to predict outcomes and train neural networks, and be able to use various techniques to develop AI and ML models.

Audience

The Applied Artificial Intelligence Workshop is designed for software developers and data scientists who want to enrich their projects with machine learning. Although you do not need any prior experience in AI, it is recommended that you have knowledge of high-school-level mathematics and at least one programming language, preferably Python. While this is a beginner's book, experienced students and programmers can also improve their Python programming skills by focusing on the practical applications featured in this AI book.

About the Chapters

Chapter 1, Introduction to Artificial Intelligence, introduces AI. You will also be implementing your first AI through a simple tic-tac-toe game where you will be teaching the program how to win against a human player.

Chapter 2, An Introduction to Regression, introduces regression. You will come across various techniques, such as linear regression, with one and multiple variables, along with polynomial and support vector regression.

Chapter 3, An Introduction to Classification, introduces classification. Here, you will be implementing various techniques, including k-nearest neighbors and support vector machines.

Chapter 4, An Introduction to Decision Trees, introduces decision trees and random forest classifiers.

Chapter 5, Artificial Intelligence: Clustering, really starts getting you thinking in new ways with your first unsupervised models. You will be introduced to the fundamentals of clustering and will implement flat clustering with the k-means algorithm and hierarchical clustering with the mean shift algorithm.

Chapter 6, Neural Networks and Deep Learning, introduces TensorFlow, Convolutional Neural Networks (CNNs), and Recurrent Neural Networks (RNNs). You will also be implementing an image classification program using neural networks and deep learning.

Conventions

Code words in text, folder names, filenames, file extensions, pathnames, and user input are shown as follows: "Please note that this function is in the tensorflow namespace, which is not referred to by default.”

A block of code is set as follows:

features_train = features_train / 255.0
features_test = features_test / 255.0

New terms and important words are shown like this: "Mean-shift is an example of hierarchical clustering, where the clustering algorithm determines the number of clusters.”

Code Presentation

Lines of code that span multiple lines are split using a backslash ( \ ). When the code is executed, Python will ignore the backslash, and treat the code on the next line as a direct continuation of the current line.

For example:

history = model.fit(X, y, epochs=100, batch_size=5, verbose=1, \
                   validation_split=0.2, shuffle=False)

Comments are added into code to help explain specific bits of logic. Single-line comments are denoted using the # symbol, as follows:

# Print the sizes of the dataset
print("Number of Examples in the Dataset = ", X.shape[0])
print("Number of Features for each example = ", X.shape[1])

Multi-line comments are enclosed by triple quotes, as shown below:

"””
Define a seed for the random number generator to ensure the 
result will be reproducible
"””
seed = 1
np.random.seed(seed)
random.set_seed(seed)

Setting up Your Environment

Before we explore the book in detail, we need to set up specific software and tools. In the following section, we shall see how to do that.

Installing Jupyter on Your System

To install Jupyter on Windows, MacOS, and Linux, perform the following steps:

  1. Head to https://www.anaconda.com/distribution/ to install the Anaconda Navigator, which is an interface through which you can access your local Jupyter notebook.
  2. Now, based on your operating system (Windows, MacOS, or Linux), you need to download the Anaconda Installer. Have a look at the following figure where we have downloaded the Anaconda files for Windows:
    Figure 0.1: The Anaconda home screen

Figure 0.1: The Anaconda home screen

Launching the Jupyter Notebook

To launch the Jupyter Notebook from the Anaconda Navigator, you need to perform the following steps:

  1. Once you install the Anaconda Navigator, you will see the screen shown in Figure 0.2:
    Figure 0.2: Anaconda installation screen

    Figure 0.2: Anaconda installation screen

  2. Now, click on Launch under the Jupyter Notebook option and launch the notebook on your local system:
    Figure 0.3: Jupyter Notebook launch option

Figure 0.3: Jupyter Notebook launch option

You have successfully installed Jupyter Notebook on your system.

Installing Libraries

pip comes pre-installed with Anaconda. Once Anaconda is installed on your machine, all the required libraries can be installed using pip, for example, pip install numpy. Alternatively, you can install all the required libraries using pip install –r requirements.txt. You can find the requirements.txt file at https://packt.live/3erXq0B.

The exercises and activities will be executed in Jupyter Notebooks. Jupyter is a Python library and can be installed in the same way as the other Python libraries – that is, with pip install jupyter, but fortunately, it comes pre-installed with Anaconda. To open a notebook, simply run the command jupyter notebook in the Terminal or Command Prompt.

A Few Important Packages

Some of the exercises in this chapter require the following packages:

  • EasyAI
  • Quandl
  • TensorFlow 2.1.0

Install them by following this guide. On Windows, open up Command Prompt. On macOS or Linux, open up Terminal.

To install easyAI and Quandl, type the following command:

pip install easyAI==1.0.0.4 Quandl==3.5.0 tensorflow==2.1.0

Accessing the Code Files

You can find the complete code files of this book at https://packt.live/31biHYK. You can also run many activities and exercises directly in your web browser by using the interactive lab environment at https://packt.live/2Vbev7E.

We've tried to support interactive versions of all activities and exercises, but we recommend a local installation as well for instances where this support isn't available.

If you have any issues or questions about installation, please email us at [email protected].