Book Image

Practical Data Analysis - Second Edition

By : Hector Cuesta, Dr. Sampath Kumar
Book Image

Practical Data Analysis - Second Edition

By: Hector Cuesta, Dr. Sampath Kumar

Overview of this book

Beyond buzzwords like Big Data or Data Science, there are a great opportunities to innovate in many businesses using data analysis to get data-driven products. Data analysis involves asking many questions about data in order to discover insights and generate value for a product or a service. This book explains the basic data algorithms without the theoretical jargon, and you’ll get hands-on turning data into insights using machine learning techniques. We will perform data-driven innovation processing for several types of data such as text, Images, social network graphs, documents, and time series, showing you how to implement large data processing with MongoDB and Apache Spark.
Table of Contents (21 chapters)
Practical Data Analysis - Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface

Implementing DTW


In this example, we will look for a similarity in 684 images from eight categories. We will use four imports of PIL, numpy, mlpy, and collections:

from PIL import Image 
from numpy import array 
import mlpy 
from collections import OrderedDict 

Tip

First, we need to obtain the time series representation of the images and store it in a dictionary (data) with the number of the image and its time series data[fn] = list:

data = {} 
  
for fn in range(1,685): 
    img = Image.open("ImgFolder\\{0}.jpg".format(fn)) 
    arr = array(img) 
    list = [] 
    for n in arr: list.append(n[0][0]) 
    for n in arr: list.append(n[0][1]) 
    for n in arr: list.append(n[0][2]) 
    data[fn] = list 

Tip

The performance of this process will lie in the number of images processed, so beware of the use of memory with large datasets.

Then, we need to select an image for reference, which will be compared to all the other images...