#### Overview of this book

Machine learning is becoming increasingly pervasive in the modern data-driven world. It is used extensively across many fields such as search engines, robotics, self-driving cars, and more. With this book, you will learn how to perform various machine learning tasks in different environments. We’ll start by exploring a range of real-life scenarios where machine learning can be used, and look at various building blocks. Throughout the book, you’ll use a wide variety of machine learning algorithms to solve real-world problems and use Python to implement these algorithms. You’ll discover how to deal with various types of data and explore the differences between machine learning paradigms such as supervised and unsupervised learning. We also cover a range of regression techniques, classification algorithms, predictive modeling, data visualization techniques, recommendation engines, and more with the help of real-world examples.
Python Machine Learning Cookbook
Credits
www.PacktPub.com
Preface
Free Chapter
The Realm of Supervised Learning
Visualizing Data
Index

## Animating bubble plots

Let's look at how to animate a bubble plot. This is useful when you want to visualize data that's transient and dynamic.

### How to do it…

1. Create a new Python file, and import the following packages:

```import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation ```
2. Let's define a `tracker` function that will dynamically update the bubble plot:

```def tracker(cur_num):
# Get the current index
cur_index = cur_num % num_points```
3. Define the color:

```    # Set the color of the datapoints
datapoints['color'][:, 3] = 1.0```
4. Update the size of the circles:

```    # Update the size of the circles
datapoints['size'] += datapoints['growth']```
5. Update the position of the oldest datapoint in the set:

```    # Update the position of the oldest datapoint
datapoints['position'][cur_index] = np.random.uniform(0, 1, 2)
datapoints['size'][cur_index] = 7
datapoints['color'][cur_index] = (0, 0, 0, 1)
datapoints['growth'][cur_index] = np.random.uniform(40...```