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

Segmenting the market based on shopping patterns


Let's see how to apply unsupervised learning techniques to segment the market based on customer shopping habits. You have been provided with a file named sales.csv. This file contains the sales details of a variety of tops from a number of retail clothing stores. Our goal is to identify the patterns and segment the market based on the number of units sold in these stores.

Create a new Python file and import the following packages:

import csv 
 
import numpy as np 
import matplotlib.pyplot as plt 
from sklearn.cluster import MeanShift, estimate_bandwidth 

Load the data from the input file. Since it's a csv file, we can use the csv reader in python to read the data from this file and convert it into a NumPy array:

# Load data from input file 
input_file = 'sales.csv' 
file_reader = csv.reader(open(input_file, 'r'), delimiter=',') 
 
X = [] 
for count, row in enumerate(file_reader): 
    if...