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 classifier based on Gaussian Mixture Models


Let's build a classifier based on a Gaussian Mixture Model. Create a new Python file and import the following packages:

import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib import patches 
 
from sklearn import datasets 
from sklearn.mixture import GMM 
from sklearn.cross_validation import StratifiedKFold 

Let's use the iris dataset available in scikit-learn for analysis:

# Load the iris dataset 
iris = datasets.load_iris() 

Split the dataset into training and testing using an 80/20 split. The n_folds parameter specifies the number of subsets you'll obtain. We are using a value of 5, which means the dataset will be split into five parts. We will use four parts for training and one part for testing, which gives a split of 80/20:

# Split dataset into training and testing (80/20 split) 
indices = StratifiedKFold(iris.target, n_folds=5) 

Extract the training data:

# Take...