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

Creating an environment


We will be using a package called OpenAI Gym to build reinforcement learning agents. You can learn more about it here: https://gym.openai.com . We can install it using pip by running the following command on the Terminal:

$ pip3 install gym

You can find various tips and tricks related to its installation here: https://github.com/openai/gym#installation . Now that you have installed it, let's go ahead and write some code.

Create a new python file and import the following package:

import argparse 
 
import gym 

Define a function to parse the input arguments. We will be able to specify the type of environment we want to run:

def build_arg_parser(): 
    parser = argparse.ArgumentParser(description='Run an environment') 
    parser.add_argument('--input-env', dest='input_env', required=True, 
            choices=['cartpole', 'mountaincar', 'pendulum', 'taxi', 'lake'],  
            help='Specify the name of the environment') 
   ...