Book Image

Artificial Intelligence with Python

Book Image

Artificial Intelligence with Python

Overview of this book

Artificial Intelligence is becoming increasingly relevant in the modern world. By harnessing the power of algorithms, you can create apps which intelligently interact with the world around you, building intelligent recommender systems, automatic speech recognition systems and more. Starting with AI basics you'll move on to learn how to develop building blocks using data mining techniques. Discover how to make informed decisions about which algorithms to use, and how to apply them to real-world scenarios. This practical book covers a range of topics including predictive analytics and deep learning.
Table of Contents (23 chapters)
Artificial Intelligence with Python
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Constructing a multilayer neural network


In order to enable higher accuracy, we need to give more freedom to the neural network. This means that a neural network needs more than one layer to extract the underlying patterns in the training data. Let's create a multilayer neural network to achieve that.

Create a new Python file and import the following packages:

import numpy as np 
import matplotlib.pyplot as plt 
import neurolab as nl 

In the previous two sections, we saw how to use a neural network as a classifier. In this section, we will see how to use a multilayer neural network as a regressor. Generate some sample data points based on the equation y = 3x^2 + 5 and then normalize the points:

# Generate some training data 
min_val = -15 
max_val = 15 
num_points = 130 
x = np.linspace(min_val, max_val, num_points) 
y = 3 * np.square(x) + 5 
y /= np.linalg.norm(y) 

Reshape the above variables to create a training dataset:

# Create data and labels...