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

Building a learning agent


Let's see how to build a learning agent that can achieve a goal. The learning agent will learn how to achieve a goal. Create a new python file and import the following package:

import argparse 
 
import gym 

Define a function to parse the input arguments:

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'],  
            help='Specify the name of the environment') 
    return parser 

Parse the input arguments:

if __name__=='__main__': 
    args = build_arg_parser().parse_args() 
    input_env = args.input_env 

Build a mapping from the input arguments to the names of the environments in the OpenAI Gym package:

    name_map = {'cartpole': 'CartPole-v0',  
                'mountaincar': 'MountainCar-v0', 
                'pendulum...