Artificial Intelligence and Machine Learning Fundamentals

Artificial Intelligence and Machine Learning Fundamentals

Copyright © 2018 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Author: Zsolt Nagy

Reviewer: Richard Ackon

Managing Editor: Steffi Monteiro

Acquisitions Editor: Koushik Sen

Production Editor: Nitesh Thakur

Editorial Board: David Barnes, Ewan Buckingham, Simon Cox, Manasa Kumar, Alex Mazonowicz, Douglas Paterson, Dominic Pereira, Shiny Poojary, Saman Siddiqui, Erol Staveley, Ankita Thakur, and Mohita Vyas.

First published: December 2018

Production reference: 1071218

Published by Packt Publishing Ltd.

Livery Place, 35 Livery Street

Birmingham B3 2PB, UK

ISBN 978-1-78980-165-1

Table of Contents

Preface

Principles of Artificial Intelligence

Introduction

How does AI Solve Real World Problems?

Diversity of Disciplines

Fields and Applications of Artificial Intelligence

Simulating Intelligence – The Turing Test

AI Tools and Learning Models

Classification and Prediction

Learning Models

The Role of Python in Artificial Intelligence

Why is Python Dominant in Machine Learning, Data Science, and AI?

Anaconda in Python

Python Libraries for Artificial Intelligence

A Brief Introduction to the NumPy Library

Exercise 1: Matrix Operations Using NumPy

Python for Game AI

Intelligent Agents in Games

Breadth First Search and Depth First Search

Exploring the State Space of a Game

Exercise 2: Estimating the Number of Possible States in Tic-Tac-Toe Game

Exercise 3: Creating an AI Randomly

Activity 1: Generating All Possible Sequences of Steps in a Tic-Tac-Toe Game

Summary

AI with Search Techniques and Games

Introduction

Exercise 4: Teaching the Agent to Win

Activity 2: Teaching the Agent to Realize Situations When It Defends Against Losses

Activity 3: Fixing the First and Second Moves of the AI to Make it Invincible

Heuristics

Uninformed and Informed Search

Creating Heuristics

Admissible and Non-Admissible Heuristics

Heuristic Evaluation

Exercise 5: Tic-Tac-Toe Static Evaluation with a Heuristic Function

Using Heuristics for an Informed Search

Types of Heuristics

Pathfinding with the A* Algorithm

Exercise 6: Finding the Shortest Path to Reach a Goal

Exercise 7: Finding the Shortest Path Using BFS

Introducing the A* Algorithm

A* Search in Practice Using the simpleai Library

Game AI with the Minmax Algorithm and Alpha-Beta Pruning

Search Algorithms for Turn-Based Multiplayer Games

The Minmax Algorithm

Optimizing the Minmax Algorithm with Alpha-Beta Pruning

DRYing up the Minmax Algorithm – The NegaMax Algorithm

Using the EasyAI Library

Activity 4: Connect Four

Summary

Regression

Introduction

Linear Regression with One Variable

What Is Regression?

Features and Labels

Feature Scaling

Cross-Validation with Training and Test Data

Fitting a Model on Data with scikit-learn

Linear Regression Using NumPy Arrays

Fitting a Model Using NumPy Polyfit

Predicting Values with Linear Regression

Activity 5: Predicting Population

Linear Regression with Multiple Variables

Multiple Linear Regression

The Process of Linear Regression

Importing Data from Data Sources

Loading Stock Prices with Yahoo Finance

Loading Files with pandas

Loading Stock Prices with Quandl

Exercise 8: Using Quandl to Load Stock Prices

Preparing Data for Prediction

Performing and Validating Linear Regression

Predicting the Future

Polynomial and Support Vector Regression

Polynomial Regression with One Variable

Exercise 9: 1st, 2nd, and 3rd Degree Polynomial Regression

Polynomial Regression with Multiple Variables

Support Vector Regression

Support Vector Machines with a 3 Degree Polynomial Kernel

Activity 6: Stock Price Prediction with Quadratic and Cubic Linear Polynomial Regression with Multiple Variables

Summary

Classification

Introduction

The Fundamentals of Classification

Exercise 10: Loading Datasets

Data Preprocessing

Exercise 11: Pre-Processing Data

Minmax Scaling of the Goal Column

Identifying Features and Labels

Cross-Validation with scikit-learn

Activity 7: Preparing Credit Data for Classification

The k-nearest neighbor Classifier

Introducing the K-Nearest Neighbor Algorithm

Distance Functions

Exercise 12: Illustrating the K-nearest Neighbor Classifier Algorithm

Exercise 13: k-nearest Neighbor Classification in scikit-learn

Exercise 14: Prediction with the k-nearest neighbors classifier

Parameterization of the k-nearest neighbor Classifier in scikit-learn

Activity 8: Increasing the Accuracy of Credit Scoring

Classification with Support Vector Machines

What are Support Vector Machine Classifiers?

Understanding Support Vector Machines

Support Vector Machines in scikit-learn

Parameters of the scikit-learn SVM

Activity 9: Support Vector Machine Optimization in scikit-learn

Summary

Using Trees for Predictive Analysis

Introduction to Decision Trees

Entropy

Exercise 15: Calculating the Entropy

Information Gain

Gini Impurity

Exit Condition

Building Decision Tree Classifiers using scikit-learn

Evaluating the Performance of Classifiers

Exercise 16: Precision and Recall

Exercise 17: Calculating the F1 Score

Confusion Matrix

Exercise 18: Confusion Matrix

Activity 10: Car Data Classification

Random Forest Classifier

Constructing a Random Forest

Random Forest Classification Using scikit-learn

Parameterization of the random forest classifier

Feature Importance

Extremely Randomized Trees

Activity 11: Random Forest Classification for Your Car Rental Company

Summary

Clustering

Introduction to Clustering

Defining the Clustering Problem

Clustering Approaches

Clustering Algorithms Supported by scikit-learn

The k-means Algorithm

Exercise 19: k-means in scikit-learn

Parameterization of the k-means Algorithm in scikit-learn

Exercise 20: Retrieving the Center Points and the Labels

k-means Clustering of Sales Data

Activity 12: k-means Clustering of Sales Data

Mean Shift Algorithm

Exercise 21: Illustrating Mean Shift in 2D

Mean Shift Algorithm in scikit-learn

Image Processing in Python

Activity 13: Shape Recognition with the Mean Shift Algorithm

Summary

Deep Learning with Neural Networks

Introduction

TensorFlow for Python

Installing TensorFlow in the Anaconda Navigator

TensorFlow Operations

Exercise 22: Using Basic Operations and TensorFlow constants

Placeholders and Variables

Global Variables Initializer

Introduction to Neural Networks

Biases

Use Cases for Artificial Neural Networks

Activation Functions

Exercise 23: Activation Functions

Forward and Backward Propagation

Configuring a Neural Network

Importing the TensorFlow Digit Dataset

Modeling Features and Labels

TensorFlow Modeling for Multiple Labels

Optimizing the Variables

Training the TensorFlow Model

Using the Model for Prediction

Testing the Model

Randomizing the Sample Size

Activity 14: Written Digit Detection

Deep Learning

Adding Layers

Convolutional Neural Networks

Activity 15: Written Digit Detection with Deep Learning

Summary

Appendix

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.3.136