Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Andrews Curves

DZone's Guide to

Andrews Curves

· Big Data Zone
Free Resource

Learn how you can maximize big data in the cloud with Apache Hadoop. Download this eBook now. Brought to you in partnership with Hortonworks.

Andrews curves are a method for visualizing multidimensional data by mapping each observation onto a function. This function is defined as

It has been shown the Andrews curves are able to preserve means, distance (up to a constant) and variances. Which means that Andrews curves that are represented by functions close together suggest that the corresponding data points will also be close together. Now, we will demonstrate the effectiveness of the Andrew curves on the iris dataset (which we already used here). Let's create a function to compute the values of the functions give a single sample:

import numpy as np
def andrew_curve4(x,theta):# iris has 4 four dimensions
    base_functions =[lambda x : x[0]/np.sqrt(2.),lambda x : x[1]*np.sin(theta),lambda x : x[2]*np.cos(theta),lambda x : x[3]*np.sin(2.*theta)]
    curve = np.zeros(len(theta))for f in base_functions:
        curve = curve + f(x)return curve

At this point we can load the dataset and plot the curves for a subset of samples:

samples = np.loadtxt('iris.csv', usecols=[0,1,2,3], delimiter=',')#samples = samples - np.mean(samples)#samples = samples / np.std(samples)
classes = np.loadtxt('iris.csv', usecols=[4], delimiter=',',dtype=np.str)
theta = np.linspace(-np.pi,np.pi,100)import pylab as pl
for s in samples[:20]:# setosa
    pl.plot(theta, andrew_curve4(s,theta),'r')for s in samples[50:70]:# versicolor
    pl.plot(theta, andrew_curve4(s,theta),'b')for s in samples[100:120]:# virginica
    pl.plot(theta, andrew_curve4(s,theta),'g')

pl.xlim(-np.pi,np.pi)
pl.show()

In the plot above, the each color used represents a class and we can easily note that the lines that represent samples from the same class have similar curves.

Hortonworks DataFlow is an integrated platform that makes data ingestion fast, easy, and secure. Download the white paper now.  Brought to you in partnership with Hortonworks

Topics:

Published at DZone with permission of Giuseppe Vettigli, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}