Artificial Intelligence with Python Cookbook
eBook - ePub

Artificial Intelligence with Python Cookbook

Proven recipes for applying AI algorithms and deep learning techniques using TensorFlow 2.x and PyTorch 1.6

Ben Auffarth

  1. 468 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Artificial Intelligence with Python Cookbook

Proven recipes for applying AI algorithms and deep learning techniques using TensorFlow 2.x and PyTorch 1.6

Ben Auffarth

Book details
Book preview
Table of contents
Citations

About This Book

Work through practical recipes to learn how to solve complex machine learning and deep learning problems using Python

Key Features

  • Get up and running with artificial intelligence in no time using hands-on problem-solving recipes
  • Explore popular Python libraries and tools to build AI solutions for images, text, sounds, and images
  • Implement NLP, reinforcement learning, deep learning, GANs, Monte-Carlo tree search, and much more

Book Description

Artificial intelligence (AI) plays an integral role in automating problem-solving. This involves predicting and classifying data and training agents to execute tasks successfully. This book will teach you how to solve complex problems with the help of independent and insightful recipes ranging from the essentials to advanced methods that have just come out of research.

Artificial Intelligence with Python Cookbook starts by showing you how to set up your Python environment and taking you through the fundamentals of data exploration. Moving ahead, you'll be able to implement heuristic search techniques and genetic algorithms. In addition to this, you'll apply probabilistic models, constraint optimization, and reinforcement learning. As you advance through the book, you'll build deep learning models for text, images, video, and audio, and then delve into algorithmic bias, style transfer, music generation, and AI use cases in the healthcare and insurance industries. Throughout the book, you'll learn about a variety of tools for problem-solving and gain the knowledge needed to effectively approach complex problems.

By the end of this book on AI, you will have the skills you need to write AI and machine learning algorithms, test them, and deploy them for production.

What you will learn

  • Implement data preprocessing steps and optimize model hyperparameters
  • Delve into representational learning with adversarial autoencoders
  • Use active learning, recommenders, knowledge embedding, and SAT solvers
  • Get to grips with probabilistic modeling with TensorFlow probability
  • Run object detection, text-to-speech conversion, and text and music generation
  • Apply swarm algorithms, multi-agent systems, and graph networks
  • Go from proof of concept to production by deploying models as microservices
  • Understand how to use modern AI in practice

Who this book is for

This AI machine learning book is for Python developers, data scientists, machine learning engineers, and deep learning practitioners who want to learn how to build artificial intelligence solutions with easy-to-follow recipes. You'll also find this book useful if you're looking for state-of-the-art solutions to perform different machine learning tasks in various use cases. Basic working knowledge of the Python programming language and machine learning concepts will help you to work with code effectively in this book.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Artificial Intelligence with Python Cookbook an online PDF/ePUB?
Yes, you can access Artificial Intelligence with Python Cookbook by Ben Auffarth in PDF and/or ePUB format, as well as other popular books in Computer Science & Data Processing. We have over one million books available in our catalogue for you to explore.

Information

Year
2020
ISBN
9781789137965
Edition
1
Advanced Topics in Supervised Machine Learning
Following the tasters with scikit-learn, Keras, and PyTorch in the previous chapter, in this chapter, we will move on to more end-to-end examples. These examples are more advanced in the sense that they include more complex transformations and model types.
We'll be predicting partner choices with sklearn, where we'll implement a lot of custom transformer steps and more complicated machine learning pipelines. We'll then predict house prices in PyTorch and visualize feature and neuron importance. After that, we will perform active learning to decide customer values together with online learning in sklearn. In the well-known case of repeat offender prediction, we'll build a model without racial bias. Last, but not least, we'll forecast time series of CO2 levels.
Online learning in this context (as opposed to internet-based learning) refers to a model update strategy that incorporates training data that comes in sequentially. This can be useful in cases where the dataset is very big (often the case with images, videos, and texts) or where it's important to keep the model up to date given the changing nature of the data.
In many of these recipes, we've shortened the description to the most salient details in order to highlight particular concepts. For the full details, please refer to the notebooks on GitHub.
In this chapter, we'll be covering the following recipes:
  • Transforming data in scikit-learn
  • Predicting house prices in PyTorch
  • Live decisioning customer values
  • Battling algorithmic bias
  • Forecasting CO2 time series

Technical requirements

The code and notebooks for this chapter are available on GitHub at https://github.com/PackPublishing/Artificial-Intelligence-with-Python-Cookbook/tree/master/chapter02.

Transforming data in scikit-learn

In this recipe, we will be building more complex pipelines using mixed-type columnar data. We'll use a speed dating dataset that was published in 2006 by Fisman et al.: https://doi.org/10.1162/qjec.2006.121.2.673
Perhaps this recipe will be informative in more ways than one, and we'll learn something useful about the mechanics of human mating choices.
The dataset description on the OpenML website reads as follows:
This data was gathered from participants in experimental speed dating events from 2002-2004. During the events, the attendees would have a four-minute first date with every other participant of the opposite sex. At the end of their 4 minutes, participants were asked whether they would like to see their date again. They were also asked to rate their date on six attributes: attractiveness, sincerity, intelligence, fun, ambition, and shared interests. The dataset also includes questionnaire data gathered from participants at different points in the process. These fields include demographics, dating habits, self-perception across key attributes, beliefs in terms of what others find valuable in a mate, and lifestyle information.
The problem is to predict mate choices from what we know about participants and their matches. This dataset presents some challenges that can serve an illustrative purpose:
  • It contains 123 different features, of different types:
    • Categorical
    • Numerical
    • Range features
It also contains the following:
  • Some missing values
  • Target imbalance
On the way to solving this problem of predicting mate choices, we will build custom encoders in scikit-learn and a pipeline comprising all features and their preprocessing steps.
The primary focus in this recipe will be on pipelines and transformers. In particular, we will build a custom transformer for working with range features and another one for numerical features.

Getting ready

We'll need the following libraries for this recipe. They are as follows:
  • OpenML to download the dataset
  • openml_speed_dating_pipeline_steps to use our custom transformer
  • imbalanced-learn to work with imbalanced classes
  • shap to show us the importance of features
In order to install them, we can use pip again:
pip install -q openml openml_speed_dating_pipeline_steps==0.5.5 imbalanced_learn category_encoders shap
OpenML is an organi...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. About Packt
  4. Contributors
  5. Preface
  6. Getting Started with Artificial Intelligence in Python
  7. Advanced Topics in Supervised Machine Learning
  8. Patterns, Outliers, and Recommendations
  9. Probabilistic Modeling
  10. Heuristic Search Techniques and Logical Inference
  11. Deep Reinforcement Learning
  12. Advanced Image Applications
  13. Working with Moving Images
  14. Deep Learning in Audio and Speech
  15. Natural Language Processing
  16. Artificial Intelligence in Production
  17. Other Books You May Enjoy
Citation styles for Artificial Intelligence with Python Cookbook

APA 6 Citation

Auffarth, B. (2020). Artificial Intelligence with Python Cookbook (1st ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/2035190/artificial-intelligence-with-python-cookbook-proven-recipes-for-applying-ai-algorithms-and-deep-learning-techniques-using-tensorflow-2x-and-pytorch-16-pdf (Original work published 2020)

Chicago Citation

Auffarth, Ben. (2020) 2020. Artificial Intelligence with Python Cookbook. 1st ed. Packt Publishing. https://www.perlego.com/book/2035190/artificial-intelligence-with-python-cookbook-proven-recipes-for-applying-ai-algorithms-and-deep-learning-techniques-using-tensorflow-2x-and-pytorch-16-pdf.

Harvard Citation

Auffarth, B. (2020) Artificial Intelligence with Python Cookbook. 1st edn. Packt Publishing. Available at: https://www.perlego.com/book/2035190/artificial-intelligence-with-python-cookbook-proven-recipes-for-applying-ai-algorithms-and-deep-learning-techniques-using-tensorflow-2x-and-pytorch-16-pdf (Accessed: 15 October 2022).

MLA 7 Citation

Auffarth, Ben. Artificial Intelligence with Python Cookbook. 1st ed. Packt Publishing, 2020. Web. 15 Oct. 2022.