SlideShare a Scribd company logo
1 of 74
Download to read offline
Prof. Pier Luca Lanzi
Data Exploration!
Data Mining andText Mining (UIC 583 @ Politecnico di Milano)
Prof. Pier Luca Lanzi
Readings
•  “Data Mining and Analysis” – Chapter 2 & 3
•  Loading Data and Basic Formatting in R!
http://flowingdata.com/2015/02/18/loading-data-and-basic-formatting-in-r/
2
Prof. Pier Luca Lanzi
before trying anything,
you should know your data!
Prof. Pier Luca Lanzi
What is Data Exploration?
•  It is the preliminary exploration of the data aimed at identifying
their most relevant characteristics
•  What the key motivations?
! Helping to select the right tool for preprocessing and data
mining
! Exploiting humans’ abilities to recognize patterns!
not captured by automatic tools
•  Related to Exploratory Data Analysis (EDA), created by
statistician John Tukey
4
Prof. Pier Luca Lanzi
Exploratory Data Analysis
•  “An approach of analyzing data to summarize their main
characteristics without using a statistical model or having
formulated a prior hypothesis.”
•  “Exploratory data analysis was promoted by John Tukey
to encourage statisticians to explore the data, and
possibly formulate hypotheses that could lead to new
data collection and experiments.”!
•  Seminal book is “Exploratory Data Analysis” by Tukey
•  Nice online introduction in Chapter 1 of the NIST
Engineering Statistics Handbook !
http://www.itl.nist.gov/div898/handbook/index.htm
•  http://en.wikipedia.org/wiki/Exploratory_data_analysis!
5
Prof. Pier Luca Lanzi
http://vis.stanford.edu/files/2012-EnterpriseAnalysisInterviews-VAST.pdf
Prof. Pier Luca Lanzi
What Data Exploration Techniques?
•  Exploratory Data Analysis (as originally defined by Tukey),!
was mainly focused on
! Visualization
! Clustering and anomaly detection!
(viewed as exploratory techniques)
! In data mining, clustering and anomaly detection are major
areas of interest, and not thought of as just exploratory
•  In this section, we focus on data exploration using
! Summary statistics
! Visualization
•  We will come back later to data exploration when discussing
clustering
7
Prof. Pier Luca Lanzi
numerical attributes
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Geometric Interpretation of Correlation
•  The correlation coefficient is simply the cosine of the angle
between the two centered attribute vectors
20
Prof. Pier Luca Lanzi
normalization
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Summary Statistics
•  They are numbers that summarize properties of the data
•  Summarized properties include location, mean, spread, skewness,
standard deviation
•  Most summary statistics can be calculated in a single pass
37
Prof. Pier Luca Lanzi
Frequency and Mode
•  The frequency of an attribute value is the percentage of time the
value occurs in the data set
•  For example, given the attribute ‘gender’ and a representative
population of people, the gender ‘female’ occurs about 50% of
the time.
•  The mode of an attribute is the most frequent attribute value
•  The notions of frequency and mode are typically used with
categorical data
38
Prof. Pier Luca Lanzi
Measures of Location:!
Mean and Median
•  The mean is the most common measure of the location of a set
of points
•  However, the mean is very sensitive to outliers
•  Thus, the median or a trimmed mean is also commonly used
39
Prof. Pier Luca Lanzi
Measures of Spread: !
Range and Variance
•  Range is the difference between the max and min
•  The variance or standard deviation is the most common measure
of the spread of a set of points
•  However, this is also sensitive to outliers, so that other measures
are often used
40
Prof. Pier Luca Lanzi
Percentiles
•  For continuous data, the notion of a percentile is veryuseful
•  Given an ordinal or continuous attribute x and a number p
between 0 and 100, the p-th percentile is a value xp of x such
that p% of the observed values of x are less than xp
•  For instance, the 50th percentile is the value x50% such that 50%
of all values of x are less than x50%
41
Prof. Pier Luca Lanzi
Summary Statistics in R
# stringr is also needed to be installed
# required libraries
library(foreign)
library(rattle)
library(plyr)
# set working directory
setwd("~/Dropbox/Documents/Online/Corsi/DMTM/data")
# load data
wnum = read.arff("weather.numeric.arff")
# check the structure
str(wnum)
# names of the attributes
names(wnum)
# rename the attributes to normalize them in lowercase
names <- normVarNames(names(wnum))
42
Prof. Pier Luca Lanzi
Summary Statistics in R
# summary statistics
summary(wnum)
mean(wnum$humidity)
sd(wnum$humidity)
var(wnum$humidity)
median(wnum$humidity)
max(wnum$humidity)
min(wnum$humidity)
# first ten rows
head(wnum,10)
# first 5 rows columns 1 & 3
head(wnum[c(1,3)],5)
# naming the columns
head(wnum[c("humidity", "temperature")])
43
Prof. Pier Luca Lanzi
Summary Statistics in R
# sampling ten rows
head(wnum[sample(nrow(wnum), 10),c("humidity", "temperature")])
# selecting the rows based an attribute properties
wnum[wnum$outlook=="sunny",]
# exploring data with sorted attributes
wnum[order(wnum$temperature),]
###
### grouping and summarizing data
###
ddply(snum,"outlook",summarize, max=max(temperature, na.rm=TRUE))
44
Prof. Pier Luca Lanzi
Visualization
•  Visualization is the conversion of data into a visual or tabular
format so that the characteristics of the data and the relationships
among data items or attributes can be analyzed or reported
•  Data visualization is one of the most powerful and appealing
techniques for data exploration
! Humans have a well developed ability to analyze large
amounts of information that is presented visually
! Can detect general patterns and trends
! Can detect outliers and unusual patterns
45
Prof. Pier Luca Lanzi
Barplots
•  They use horizontal or vertical bars to compare categories.
•  One axis shows the compared categories, the other axis
represents a discrete value
•  Some bar graphs present bars clustered in groups of more than
one (grouped bar graphs), and others show the bars divided into
subparts to show cumulate effect (stacked bar graphs)
46
Prof. Pier Luca Lanzi
Barplot using R
# barplot
barplot(wnum$outlook)
###
### distribution of outlook values
### splitted according to attribute windy
###
counts <- table(wnum$windy,wnum$outlook)
barplot(counts,col=c("darkblue","red"))
# horizontal
barplot(counts,col=c("darkblue","red"), horiz=TRUE)
# grouped
barplot(counts,col=c("darkblue","red"), horiz=TRUE, beside=TRUE)
47
Prof. Pier Luca Lanzi
Histograms
•  They are a graphical representation of the distribution of data !
introduced by Karl Pearson in 1895
•  They estimate the probability distribution of a continuous variables
•  They are representations of tabulated frequencies depicted as adjacent
rectangles, erected over discrete intervals (bins). Their areas are proportional
to the frequency of the observations in the interval.
48
Prof. Pier Luca Lanzi
Histograms
•  The height of each bar indicates the number of objects
•  Shape of histogram depends on the number of bins
49
Example: Petal Width (10 and 20 bins, respectively)
Prof. Pier Luca Lanzi
Histograms in R
# distribution of temperature values
hist(wnum$temperature, xlab="Temperature",
main="Temperature Distribution", col="blue")
# fewer bins
hist(wnum$temperature, breaks=2, xlab="Temperature",
main="Temperature Distribution", col="blue")
# fit the distribution
d <- density(wnum$temperature)
plot(d, main="Temperature Distribution", xlab="Temperature")
polygon(d, col="red", border="blue")
# difference in bins the distribution
hist(iris$petalwidth, col="blue", breaks=10, xlab="Petal Width", main="")
hist(iris$petalwidth, col="blue", breaks=20, xlab="Petal Width", main="")
d <- density(iris$petalwidth)
plot(d, main="Petal Width Distribution", xlab="Petal Width")
polygon(d, col="red", border="blue")
50
Prof. Pier Luca Lanzi
Maps
•  Maps are a very effective communications tool that can visualize
thousands of data points in just one figure
51
Prof. Pier Luca Lanzi
Mapping Data with R
# http://togaware.com/onepager/MapsO.pdf
# required packages
install.packages("maps")
install.packages("ggmap")
install.packages("oz")
library(maps)
library(ggmap)
library(oz)
library(ggplot2)
library(scales)
ds <- map_data("world")
p <- ggplot(ds, aes(x=long, y=lat, group=group, fill=region))
p <- p + geom_polygon()
p <- p + theme(legend.position = "none”)
52
Prof. Pier Luca Lanzi
Mapping Data with R
# World map
p <- ggplot(ds, aes(x=long, y=lat, group=group, fill=region))
p <- p + geom_polygon()
p <- p + theme(legend.position = "none")
p
# Map of Europe
map <- get_map(location="Europe", zoom=4)
p <- ggmap(map)
p
# Google Map
map <- get_map(location="Sydney", zoom=14, maptype="roadmap",
source="google")
p <- ggmap(map)
p
53
Prof. Pier Luca Lanzi
Mapping Data with R
# Mapping arrests
arrests <- USArrests
names(arrests) <- tolower(names(arrests))
arrests$region <- tolower(rownames(USArrests))
head(arrests)
# maps the attribute state in their long/lat coordinates
states <- map_data("state")
# join the database of state information with the arrests information using
region
ds <- merge(states, arrests, sort=FALSE, by="region")
# reorder the points for plotting otherwise the borders are plotted
incorrectly
ds <- ds[order(ds$order), ]
g <- ggplot(ds, aes(long, lat, group=group, fill=ds$assault/ds$murder))
g <- g + geom_polygon()
print(g)
54
Prof. Pier Luca Lanzi
Mapping Data for Visualization
•  Data objects, their attributes, and the relationships among data
objects are translated into graphical elements such as points, lines,
shapes, and colors
•  Objects are often represented as points
•  Their attribute values can be represented as the position of the
points or the characteristics of the points, e.g., color, size, and
shape
•  If position is used, then the relationships of points, i.e., whether
they form groups or a point is an outlier, is easily perceived.
55
Prof. Pier Luca Lanzi
Data Arrangement
•  Is the placement of visual elements within a display
•  Influence on how easy it is to understand the data
56
Prof. Pier Luca Lanzi
Selection
•  Is the elimination or the de-emphasis of !
certain objects and attributes
•  Selection may involve choosing a subset of attributes
! Dimensionality reduction is often used to reduce the number
of dimensions to two or three
! Alternatively, pairs of attributes can be considered
•  Selection may also involve choosing a subset of objects
! A region of the screen can only show so many points
! Can sample, but want to preserve points in sparse areas
57
Prof. Pier Luca Lanzi
Box Plots
•  Box Plots (invented by Tukey)
•  Another way of displaying the distribution of data
•  Following figure shows !
the basic part of a box plot
•  IQR is the interquartile range !
or Q3-Q1
58
outlier
Min (> Q1 -1.5 IQR)
1st quartile (Q1)
3rd quartile (Q3)
2nd quartile (Q2)
Max ( < Q3 +1.5 IQR)
Prof. Pier Luca Lanzi
Box Plot Example 59
Prof. Pier Luca Lanzi
Boxplots in R
# set working directory
setwd("~/Dropbox/Documents/Online/Corsi/DMTM/data")
# load data
iris = read.arff("iris.arff")
boxplot(iris[,1:4], ylab="values (cm)", main="iris dataset")
boxplot(iris[,1:4], ylab="values (cm)", main="iris dataset", las=2,
names=c("sep len", "sep wid", "pet len", "pet wid"),
col=c("lightblue","lightblue","pink","pink"),
at=c(1,2,5,6))
boxplot(iris[,1:4], ylab="values (cm)", main="iris dataset", las=2,
names=c("sep len", "sep wid", "pet len", "pet wid"),
border=c("blue","blue","green","green"),
at=c(1,2,5,6))
# more examples
# http://www.r-bloggers.com/box-plot-with-r-tutorial/
60
Prof. Pier Luca Lanzi
Scatter Plots
•  Attributes values determine the position
•  Two-dimensional scatter plots most common, but can have
three-dimensional scatter plots
•  Often additional attributes can be displayed by using the size,
shape, and color of the markers that represent the objects
•  It is useful to have arrays of scatter plots can compactly
summarize the relationships of several pairs of attributes
•  Examples: http://www.statmethods.net/graphs/scatterplot.html
61
Prof. Pier Luca Lanzi
Scatter Plots in R
# set working directory
setwd("~/Dropbox/Documents/Online/Corsi/DMTM/data")
# load data
iris = read.arff("iris.arff")
# attach iris to the path
attach(iris)
# plot scatter plot
plot(petallength,sepallength,
xlab="Petal Length",
ylab="Sepal Length", pch=19)
# linear model
abline(lm(sepallength~petallength),
col="red") # regression line (y~x)
# local linear model
lines(lowess(petallength, sepallength),
col="blue") # lowess line (x,y)
62
Prof. Pier Luca Lanzi
Scatter Plots in R
library(car)
scatterplot(sepallength~petallength | class, data=iris, xlab="Petal Length”,
ylab="Sepal Length", main="Enhanced Scatter Plot", labels=row.names(iris))
63
Prof. Pier Luca Lanzi
Scatter Plot Array for Iris 64
Prof. Pier Luca Lanzi
Scatter Matrix Plots in R
# paired
library(car)
scatterplot(sepallength~petallength | class, data=iris,
xlab="Petal Length", ylab="Sepal Length",
main="Enhanced Scatter Plot",
labels=row.names(iris))
png("~/Downloads/scatter1.png")
# scatter plot matrix
pairs(~petallength+petalwidth+sepallength+sepalwidth,data=iris, main="Simple
Scatterplot Matrix")
dev.off()
library(car)
png("~/Downloads/scatter2.png")
# scatter plot matrix
scatterplotMatrix(~petallength+petalwidth+sepallength+sepalwidth|class,
data=iris, main="Scatter Plots vs Class")
dev.off()
65
Prof. Pier Luca Lanzi
Scatter Plot Combined with Box Plots 66
Prof. Pier Luca Lanzi
Scatter Plots with Box Plots
# Add boxplots to a scatterplot
par(fig=c(0,0.8,0,0.8), new=TRUE)
plot(mtcars$wt, mtcars$mpg, xlab="Miles Per Gallon",
ylab="Car Weight")
par(fig=c(0,0.8,0.55,1), new=TRUE)
boxplot(mtcars$wt, horizontal=TRUE, axes=FALSE)
par(fig=c(0.65,1,0,0.8),new=TRUE)
boxplot(mtcars$mpg, axes=FALSE)
mtext("Enhanced Scatterplot", side=3, outer=TRUE, line=-3)
67
Prof. Pier Luca Lanzi
Contour Plots
•  Useful for continuous attributes measured on a spatial grid
•  They partition the plane into regions of similar values
•  The contour lines that form the boundaries of these regions
connect points with equal values
•  The most common example is contour maps of elevation
•  Can also display temperature, rainfall, air pressure, etc.
68
Prof. Pier Luca Lanzi
Celsius
Prof. Pier Luca Lanzi
Matrix Plots
•  Can plot the data matrix
•  This can be useful when objects are sorted according to class
•  Typically, the attributes are normalized to prevent one attribute
from dominating the plot
•  Plots of similarity or distance matrices can also be useful for
visualizing the relationships between objects
70
Prof. Pier Luca Lanzi
Heatmaps 71
dm <- data.matrix(iris[,1:4])
heatmap(dm)
Prof. Pier Luca Lanzi
additional examples
http://onepager.togaware.com/PlotsO.pdf
Prof. Pier Luca Lanzi
Other Visualization Techniques
•  Star Plots
! Similar approach to parallel coordinates, !
but axes radiate from a central point
! The line connecting the values of an object is a polygon
•  Chernoff Faces
! Approach created by Herman Chernoff
! This approach associates each attribute with a characteristic of
a face
! The values of each attribute determine the appearance of the
corresponding facial characteristic
! Each object becomes a separate face
! Relies on human’s ability to distinguish faces
73
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Chernoff Faces
•  More dimensions are plotted using several features of human faces
76
Prof. Pier Luca Lanzi
http://cartastrophe.files.wordpress.com/2010/06/spinelli.png
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Chernoff Faces & Star/Radar Plots
# http://cran.r-project.org/web/packages/aplpack/aplpack.pdf
library(foreign)
library(aplpack)
# set working directory
setwd("~/Dropbox/Documents/Online/Corsi/DMTM/data")
# load data
iris = read.arff("iris.arff")
# attach iris to the path
attach(iris)
# Chernoff faces
faces(iris[1:16,1:4])
79
Prof. Pier Luca Lanzi
Chernoff Faces & Star/Radar Plots
require(grDevices)
stars(mtcars[, 1:7], key.loc = c(14, 2), main = "Motor Trend Cars : stars(*,
full = F)", full = FALSE)
# full stars
stars(mtcars[, 1:7], key.loc = c(14, 1.5), main = "Motor Trend Cars : full
stars()", flip.labels = FALSE)
# spider radar plot
stars(mtcars[, 1:7], locations = c(0, 0), radius = FALSE, key.loc = c(0, 0),
main = "Motor Trend Cars", lty = 2)
# adding colors
palette(rainbow(12, s = 0.6, v = 0.75))
stars(mtcars[, 1:7], len = 0.8, key.loc = c(12, 1.5), main = "Motor Trend
Cars", draw.segments = TRUE)
# positioning
stars(mtcars[, 1:7], len = 0.6, key.loc = c(1.5, 0), main = "Motor Trend
Cars", draw.segments = TRUE, nrow = 6, cex = .7)
dev.off()
faces(mtcars[,1:7])
80
Prof. Pier Luca Lanzi
examples
Prof. Pier Luca Lanzi
do we read the articles we share?
does my banner work?
Prof. Pier Luca Lanzi
“When we combined attention and traffic to find the story that had
the largest volume of total engaged time, we found that it had fewer
than 100 likes and fewer than 50 tweets. Conversely, the story with
the largest number of tweets got about 20% of the total engaged
time that the most engaging story received.”
Prof. Pier Luca Lanzi
“Here’s the skinny, 66% of attention on a normal media page is spent
below the fold.That leaderboard at the top of the page? People
scroll right past that and spend their time where the content not the
cruft is. .”
Prof. Pier Luca Lanzi
http://time.com/12933/what-you-think-you-know-about-the-web-is-wrong/?iid=biz-category-mostpop2
Prof. Pier Luca Lanzi
http://apps.startribune.com/news/20140313-beer-me-minnesota/
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi
Prof. Pier Luca Lanzi

More Related Content

What's hot

What's hot (20)

DMTM Lecture 13 Representative based clustering
DMTM Lecture 13 Representative based clusteringDMTM Lecture 13 Representative based clustering
DMTM Lecture 13 Representative based clustering
 
DMTM 2015 - 07 Hierarchical Clustering
DMTM 2015 - 07 Hierarchical ClusteringDMTM 2015 - 07 Hierarchical Clustering
DMTM 2015 - 07 Hierarchical Clustering
 
DMTM 2015 - 16 Data Preparation
DMTM 2015 - 16 Data PreparationDMTM 2015 - 16 Data Preparation
DMTM 2015 - 16 Data Preparation
 
DMTM Lecture 18 Graph mining
DMTM Lecture 18 Graph miningDMTM Lecture 18 Graph mining
DMTM Lecture 18 Graph mining
 
DMTM Lecture 09 Other classificationmethods
DMTM Lecture 09 Other classificationmethodsDMTM Lecture 09 Other classificationmethods
DMTM Lecture 09 Other classificationmethods
 
DMTM Lecture 04 Classification
DMTM Lecture 04 ClassificationDMTM Lecture 04 Classification
DMTM Lecture 04 Classification
 
DMTM Lecture 15 Clustering evaluation
DMTM Lecture 15 Clustering evaluationDMTM Lecture 15 Clustering evaluation
DMTM Lecture 15 Clustering evaluation
 
DMTM Lecture 03 Regression
DMTM Lecture 03 RegressionDMTM Lecture 03 Regression
DMTM Lecture 03 Regression
 
DMTM 2015 - 13 Naive bayes, Nearest Neighbours and Other Methods
DMTM 2015 - 13 Naive bayes, Nearest Neighbours and Other MethodsDMTM 2015 - 13 Naive bayes, Nearest Neighbours and Other Methods
DMTM 2015 - 13 Naive bayes, Nearest Neighbours and Other Methods
 
DMTM Lecture 10 Classification ensembles
DMTM Lecture 10 Classification ensemblesDMTM Lecture 10 Classification ensembles
DMTM Lecture 10 Classification ensembles
 
DMTM 2015 - 15 Classification Ensembles
DMTM 2015 - 15 Classification EnsemblesDMTM 2015 - 15 Classification Ensembles
DMTM 2015 - 15 Classification Ensembles
 
DMTM Lecture 12 Hierarchical clustering
DMTM Lecture 12 Hierarchical clusteringDMTM Lecture 12 Hierarchical clustering
DMTM Lecture 12 Hierarchical clustering
 
DMTM Lecture 05 Data representation
DMTM Lecture 05 Data representationDMTM Lecture 05 Data representation
DMTM Lecture 05 Data representation
 
DMTM Lecture 19 Data exploration
DMTM Lecture 19 Data explorationDMTM Lecture 19 Data exploration
DMTM Lecture 19 Data exploration
 
DMTM Lecture 16 Association rules
DMTM Lecture 16 Association rulesDMTM Lecture 16 Association rules
DMTM Lecture 16 Association rules
 
DMTM 2015 - 08 Representative-Based Clustering
DMTM 2015 - 08 Representative-Based ClusteringDMTM 2015 - 08 Representative-Based Clustering
DMTM 2015 - 08 Representative-Based Clustering
 
DMTM 2015 - 14 Evaluation of Classification Models
DMTM 2015 - 14 Evaluation of Classification ModelsDMTM 2015 - 14 Evaluation of Classification Models
DMTM 2015 - 14 Evaluation of Classification Models
 
DMTM Lecture 06 Classification evaluation
DMTM Lecture 06 Classification evaluationDMTM Lecture 06 Classification evaluation
DMTM Lecture 06 Classification evaluation
 
DMTM Lecture 08 Classification rules
DMTM Lecture 08 Classification rulesDMTM Lecture 08 Classification rules
DMTM Lecture 08 Classification rules
 
DMTM 2015 - 12 Classification Rules
DMTM 2015 - 12 Classification RulesDMTM 2015 - 12 Classification Rules
DMTM 2015 - 12 Classification Rules
 

Viewers also liked

Data Exploration, Validation and Sanitization
Data Exploration, Validation and SanitizationData Exploration, Validation and Sanitization
Data Exploration, Validation and Sanitization
Venkata Reddy Konasani
 
Data Mining with Splunk
Data Mining with SplunkData Mining with Splunk
Data Mining with Splunk
David Carasso
 

Viewers also liked (18)

DMTM 2015 - 01 Course Introduction
DMTM 2015 - 01 Course IntroductionDMTM 2015 - 01 Course Introduction
DMTM 2015 - 01 Course Introduction
 
DMTM 2015 - 02 Data Mining
DMTM 2015 - 02 Data MiningDMTM 2015 - 02 Data Mining
DMTM 2015 - 02 Data Mining
 
Machine Learning and Data Mining: 15 Data Exploration and Preparation
Machine Learning and Data Mining: 15 Data Exploration and PreparationMachine Learning and Data Mining: 15 Data Exploration and Preparation
Machine Learning and Data Mining: 15 Data Exploration and Preparation
 
DMTM 2015 - 05 Association Rules
DMTM 2015 - 05 Association RulesDMTM 2015 - 05 Association Rules
DMTM 2015 - 05 Association Rules
 
DMTM 2015 - 11 Decision Trees
DMTM 2015 - 11 Decision TreesDMTM 2015 - 11 Decision Trees
DMTM 2015 - 11 Decision Trees
 
Course Introduction
Course IntroductionCourse Introduction
Course Introduction
 
DMTM 2015 - 19 Graph Mining
DMTM 2015 - 19 Graph MiningDMTM 2015 - 19 Graph Mining
DMTM 2015 - 19 Graph Mining
 
Focus Junior - 14 Maggio 2016
Focus Junior - 14 Maggio 2016Focus Junior - 14 Maggio 2016
Focus Junior - 14 Maggio 2016
 
Machine Learning and Data Mining: 12 Classification Rules
Machine Learning and Data Mining: 12 Classification RulesMachine Learning and Data Mining: 12 Classification Rules
Machine Learning and Data Mining: 12 Classification Rules
 
Data Exploration, Validation and Sanitization
Data Exploration, Validation and SanitizationData Exploration, Validation and Sanitization
Data Exploration, Validation and Sanitization
 
Lecture 9: Machine Learning in Practice (2)
Lecture 9: Machine Learning in Practice (2)Lecture 9: Machine Learning in Practice (2)
Lecture 9: Machine Learning in Practice (2)
 
Fitness Inheritance in Evolutionary and
Fitness Inheritance in Evolutionary andFitness Inheritance in Evolutionary and
Fitness Inheritance in Evolutionary and
 
Videogame Design and Programming: Conferenza d'Ateneo 18 Maggio 2011
Videogame Design and Programming: Conferenza d'Ateneo 18 Maggio 2011Videogame Design and Programming: Conferenza d'Ateneo 18 Maggio 2011
Videogame Design and Programming: Conferenza d'Ateneo 18 Maggio 2011
 
GECCO-2014 Learning Classifier Systems: A Gentle Introduction
GECCO-2014 Learning Classifier Systems: A Gentle IntroductionGECCO-2014 Learning Classifier Systems: A Gentle Introduction
GECCO-2014 Learning Classifier Systems: A Gentle Introduction
 
Lecture 02 Machine Learning For Data Mining
Lecture 02 Machine Learning For Data MiningLecture 02 Machine Learning For Data Mining
Lecture 02 Machine Learning For Data Mining
 
Evolving Rules to Solve Problems: The Learning Classifier Systems Way
Evolving Rules to Solve Problems: The Learning Classifier Systems WayEvolving Rules to Solve Problems: The Learning Classifier Systems Way
Evolving Rules to Solve Problems: The Learning Classifier Systems Way
 
Lecture 04 Association Rules Basics
Lecture 04 Association Rules BasicsLecture 04 Association Rules Basics
Lecture 04 Association Rules Basics
 
Data Mining with Splunk
Data Mining with SplunkData Mining with Splunk
Data Mining with Splunk
 

Similar to DMTM 2015 - 04 Data Exploration

From Research Objects to Reproducible Science Tales
From Research Objects to Reproducible Science TalesFrom Research Objects to Reproducible Science Tales
From Research Objects to Reproducible Science Tales
Bertram Ludäscher
 
Towards Open Methods: Using Scientific Workflows in Linguistics
Towards Open Methods: Using Scientific Workflows in LinguisticsTowards Open Methods: Using Scientific Workflows in Linguistics
Towards Open Methods: Using Scientific Workflows in Linguistics
Richard Littauer
 

Similar to DMTM 2015 - 04 Data Exploration (20)

From Research Objects to Reproducible Science Tales
From Research Objects to Reproducible Science TalesFrom Research Objects to Reproducible Science Tales
From Research Objects to Reproducible Science Tales
 
Some Information Retrieval Models and Our Experiments for TREC KBA
Some Information Retrieval Models and Our Experiments for TREC KBASome Information Retrieval Models and Our Experiments for TREC KBA
Some Information Retrieval Models and Our Experiments for TREC KBA
 
From Workflows to Transparent Research Objects and Reproducible Science Tales
From Workflows to Transparent Research Objects and Reproducible Science TalesFrom Workflows to Transparent Research Objects and Reproducible Science Tales
From Workflows to Transparent Research Objects and Reproducible Science Tales
 
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
ARTIFICIAL INTELLIGENCE---UNIT 4.pptxARTIFICIAL INTELLIGENCE---UNIT 4.pptx
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
 
The Web of Data: do we actually understand what we built?
The Web of Data: do we actually understand what we built?The Web of Data: do we actually understand what we built?
The Web of Data: do we actually understand what we built?
 
Knowledge base system appl. p 1,2-ver1
Knowledge base system appl.  p 1,2-ver1Knowledge base system appl.  p 1,2-ver1
Knowledge base system appl. p 1,2-ver1
 
Finding and Exploring Commonalities between Researchers Using the ResXplorer
Finding and Exploring Commonalities between Researchers Using the ResXplorerFinding and Exploring Commonalities between Researchers Using the ResXplorer
Finding and Exploring Commonalities between Researchers Using the ResXplorer
 
MLPI Lecture 1: Maths for Machine Learning
MLPI Lecture 1: Maths for Machine LearningMLPI Lecture 1: Maths for Machine Learning
MLPI Lecture 1: Maths for Machine Learning
 
Our World is Socio-technical
Our World is Socio-technicalOur World is Socio-technical
Our World is Socio-technical
 
Data Communities - reusable data in and outside your organization.
Data Communities - reusable data in and outside your organization.Data Communities - reusable data in and outside your organization.
Data Communities - reusable data in and outside your organization.
 
Deep learning and the systemic challenges of data science initiatives
Deep learning and the systemic challenges of data science initiativesDeep learning and the systemic challenges of data science initiatives
Deep learning and the systemic challenges of data science initiatives
 
Deep Learning for Information Retrieval
Deep Learning for Information RetrievalDeep Learning for Information Retrieval
Deep Learning for Information Retrieval
 
Towards Computational Research Objects
Towards Computational Research ObjectsTowards Computational Research Objects
Towards Computational Research Objects
 
Interpretation, Context, and Metadata: Examples from Open Context
Interpretation, Context, and Metadata: Examples from Open ContextInterpretation, Context, and Metadata: Examples from Open Context
Interpretation, Context, and Metadata: Examples from Open Context
 
Introduction to data science
Introduction to data scienceIntroduction to data science
Introduction to data science
 
Chris Brew - TR Discover: A Natural Language Interface for Exploring Linked D...
Chris Brew - TR Discover: A Natural Language Interface for Exploring Linked D...Chris Brew - TR Discover: A Natural Language Interface for Exploring Linked D...
Chris Brew - TR Discover: A Natural Language Interface for Exploring Linked D...
 
Towards Open Methods: Using Scientific Workflows in Linguistics
Towards Open Methods: Using Scientific Workflows in LinguisticsTowards Open Methods: Using Scientific Workflows in Linguistics
Towards Open Methods: Using Scientific Workflows in Linguistics
 
Ethics reproducibility and data stewardship
Ethics reproducibility and data stewardshipEthics reproducibility and data stewardship
Ethics reproducibility and data stewardship
 
DMTM 2015 - 18 Text Mining Part 2
DMTM 2015 - 18 Text Mining Part 2DMTM 2015 - 18 Text Mining Part 2
DMTM 2015 - 18 Text Mining Part 2
 
Works 2015-provenance-mileage
Works 2015-provenance-mileageWorks 2015-provenance-mileage
Works 2015-provenance-mileage
 

More from Pier Luca Lanzi

More from Pier Luca Lanzi (14)

11 Settembre 2021 - Giocare con i Videogiochi
11 Settembre 2021 - Giocare con i Videogiochi11 Settembre 2021 - Giocare con i Videogiochi
11 Settembre 2021 - Giocare con i Videogiochi
 
Breve Viaggio al Centro dei Videogiochi
Breve Viaggio al Centro dei VideogiochiBreve Viaggio al Centro dei Videogiochi
Breve Viaggio al Centro dei Videogiochi
 
Global Game Jam 19 @ POLIMI - Morning Welcome
Global Game Jam 19 @ POLIMI - Morning WelcomeGlobal Game Jam 19 @ POLIMI - Morning Welcome
Global Game Jam 19 @ POLIMI - Morning Welcome
 
Data Driven Game Design @ Campus Party 2018
Data Driven Game Design @ Campus Party 2018Data Driven Game Design @ Campus Party 2018
Data Driven Game Design @ Campus Party 2018
 
GGJ18 al Politecnico di Milano - Presentazione che precede la presentazione d...
GGJ18 al Politecnico di Milano - Presentazione che precede la presentazione d...GGJ18 al Politecnico di Milano - Presentazione che precede la presentazione d...
GGJ18 al Politecnico di Milano - Presentazione che precede la presentazione d...
 
GGJ18 al Politecnico di Milano - Presentazione di apertura
GGJ18 al Politecnico di Milano - Presentazione di aperturaGGJ18 al Politecnico di Milano - Presentazione di apertura
GGJ18 al Politecnico di Milano - Presentazione di apertura
 
Presentation for UNITECH event - January 8, 2018
Presentation for UNITECH event - January 8, 2018Presentation for UNITECH event - January 8, 2018
Presentation for UNITECH event - January 8, 2018
 
DMTM Lecture 14 Density based clustering
DMTM Lecture 14 Density based clusteringDMTM Lecture 14 Density based clustering
DMTM Lecture 14 Density based clustering
 
DMTM Lecture 07 Decision trees
DMTM Lecture 07 Decision treesDMTM Lecture 07 Decision trees
DMTM Lecture 07 Decision trees
 
DMTM Lecture 01 Introduction
DMTM Lecture 01 IntroductionDMTM Lecture 01 Introduction
DMTM Lecture 01 Introduction
 
DMTM Lecture 02 Data mining
DMTM Lecture 02 Data miningDMTM Lecture 02 Data mining
DMTM Lecture 02 Data mining
 
VDP2016 - Lecture 16 Rendering pipeline
VDP2016 - Lecture 16 Rendering pipelineVDP2016 - Lecture 16 Rendering pipeline
VDP2016 - Lecture 16 Rendering pipeline
 
VDP2016 - Lecture 15 PCG with Unity
VDP2016 - Lecture 15 PCG with UnityVDP2016 - Lecture 15 PCG with Unity
VDP2016 - Lecture 15 PCG with Unity
 
VDP2016 - Lecture 14 Procedural content generation
VDP2016 - Lecture 14 Procedural content generationVDP2016 - Lecture 14 Procedural content generation
VDP2016 - Lecture 14 Procedural content generation
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 

DMTM 2015 - 04 Data Exploration

  • 1. Prof. Pier Luca Lanzi Data Exploration! Data Mining andText Mining (UIC 583 @ Politecnico di Milano)
  • 2. Prof. Pier Luca Lanzi Readings •  “Data Mining and Analysis” – Chapter 2 & 3 •  Loading Data and Basic Formatting in R! http://flowingdata.com/2015/02/18/loading-data-and-basic-formatting-in-r/ 2
  • 3. Prof. Pier Luca Lanzi before trying anything, you should know your data!
  • 4. Prof. Pier Luca Lanzi What is Data Exploration? •  It is the preliminary exploration of the data aimed at identifying their most relevant characteristics •  What the key motivations? ! Helping to select the right tool for preprocessing and data mining ! Exploiting humans’ abilities to recognize patterns! not captured by automatic tools •  Related to Exploratory Data Analysis (EDA), created by statistician John Tukey 4
  • 5. Prof. Pier Luca Lanzi Exploratory Data Analysis •  “An approach of analyzing data to summarize their main characteristics without using a statistical model or having formulated a prior hypothesis.” •  “Exploratory data analysis was promoted by John Tukey to encourage statisticians to explore the data, and possibly formulate hypotheses that could lead to new data collection and experiments.”! •  Seminal book is “Exploratory Data Analysis” by Tukey •  Nice online introduction in Chapter 1 of the NIST Engineering Statistics Handbook ! http://www.itl.nist.gov/div898/handbook/index.htm •  http://en.wikipedia.org/wiki/Exploratory_data_analysis! 5
  • 6. Prof. Pier Luca Lanzi http://vis.stanford.edu/files/2012-EnterpriseAnalysisInterviews-VAST.pdf
  • 7. Prof. Pier Luca Lanzi What Data Exploration Techniques? •  Exploratory Data Analysis (as originally defined by Tukey),! was mainly focused on ! Visualization ! Clustering and anomaly detection! (viewed as exploratory techniques) ! In data mining, clustering and anomaly detection are major areas of interest, and not thought of as just exploratory •  In this section, we focus on data exploration using ! Summary statistics ! Visualization •  We will come back later to data exploration when discussing clustering 7
  • 8. Prof. Pier Luca Lanzi numerical attributes
  • 18. Prof. Pier Luca Lanzi Geometric Interpretation of Correlation •  The correlation coefficient is simply the cosine of the angle between the two centered attribute vectors 20
  • 19. Prof. Pier Luca Lanzi normalization
  • 22. Prof. Pier Luca Lanzi Summary Statistics •  They are numbers that summarize properties of the data •  Summarized properties include location, mean, spread, skewness, standard deviation •  Most summary statistics can be calculated in a single pass 37
  • 23. Prof. Pier Luca Lanzi Frequency and Mode •  The frequency of an attribute value is the percentage of time the value occurs in the data set •  For example, given the attribute ‘gender’ and a representative population of people, the gender ‘female’ occurs about 50% of the time. •  The mode of an attribute is the most frequent attribute value •  The notions of frequency and mode are typically used with categorical data 38
  • 24. Prof. Pier Luca Lanzi Measures of Location:! Mean and Median •  The mean is the most common measure of the location of a set of points •  However, the mean is very sensitive to outliers •  Thus, the median or a trimmed mean is also commonly used 39
  • 25. Prof. Pier Luca Lanzi Measures of Spread: ! Range and Variance •  Range is the difference between the max and min •  The variance or standard deviation is the most common measure of the spread of a set of points •  However, this is also sensitive to outliers, so that other measures are often used 40
  • 26. Prof. Pier Luca Lanzi Percentiles •  For continuous data, the notion of a percentile is veryuseful •  Given an ordinal or continuous attribute x and a number p between 0 and 100, the p-th percentile is a value xp of x such that p% of the observed values of x are less than xp •  For instance, the 50th percentile is the value x50% such that 50% of all values of x are less than x50% 41
  • 27. Prof. Pier Luca Lanzi Summary Statistics in R # stringr is also needed to be installed # required libraries library(foreign) library(rattle) library(plyr) # set working directory setwd("~/Dropbox/Documents/Online/Corsi/DMTM/data") # load data wnum = read.arff("weather.numeric.arff") # check the structure str(wnum) # names of the attributes names(wnum) # rename the attributes to normalize them in lowercase names <- normVarNames(names(wnum)) 42
  • 28. Prof. Pier Luca Lanzi Summary Statistics in R # summary statistics summary(wnum) mean(wnum$humidity) sd(wnum$humidity) var(wnum$humidity) median(wnum$humidity) max(wnum$humidity) min(wnum$humidity) # first ten rows head(wnum,10) # first 5 rows columns 1 & 3 head(wnum[c(1,3)],5) # naming the columns head(wnum[c("humidity", "temperature")]) 43
  • 29. Prof. Pier Luca Lanzi Summary Statistics in R # sampling ten rows head(wnum[sample(nrow(wnum), 10),c("humidity", "temperature")]) # selecting the rows based an attribute properties wnum[wnum$outlook=="sunny",] # exploring data with sorted attributes wnum[order(wnum$temperature),] ### ### grouping and summarizing data ### ddply(snum,"outlook",summarize, max=max(temperature, na.rm=TRUE)) 44
  • 30. Prof. Pier Luca Lanzi Visualization •  Visualization is the conversion of data into a visual or tabular format so that the characteristics of the data and the relationships among data items or attributes can be analyzed or reported •  Data visualization is one of the most powerful and appealing techniques for data exploration ! Humans have a well developed ability to analyze large amounts of information that is presented visually ! Can detect general patterns and trends ! Can detect outliers and unusual patterns 45
  • 31. Prof. Pier Luca Lanzi Barplots •  They use horizontal or vertical bars to compare categories. •  One axis shows the compared categories, the other axis represents a discrete value •  Some bar graphs present bars clustered in groups of more than one (grouped bar graphs), and others show the bars divided into subparts to show cumulate effect (stacked bar graphs) 46
  • 32. Prof. Pier Luca Lanzi Barplot using R # barplot barplot(wnum$outlook) ### ### distribution of outlook values ### splitted according to attribute windy ### counts <- table(wnum$windy,wnum$outlook) barplot(counts,col=c("darkblue","red")) # horizontal barplot(counts,col=c("darkblue","red"), horiz=TRUE) # grouped barplot(counts,col=c("darkblue","red"), horiz=TRUE, beside=TRUE) 47
  • 33. Prof. Pier Luca Lanzi Histograms •  They are a graphical representation of the distribution of data ! introduced by Karl Pearson in 1895 •  They estimate the probability distribution of a continuous variables •  They are representations of tabulated frequencies depicted as adjacent rectangles, erected over discrete intervals (bins). Their areas are proportional to the frequency of the observations in the interval. 48
  • 34. Prof. Pier Luca Lanzi Histograms •  The height of each bar indicates the number of objects •  Shape of histogram depends on the number of bins 49 Example: Petal Width (10 and 20 bins, respectively)
  • 35. Prof. Pier Luca Lanzi Histograms in R # distribution of temperature values hist(wnum$temperature, xlab="Temperature", main="Temperature Distribution", col="blue") # fewer bins hist(wnum$temperature, breaks=2, xlab="Temperature", main="Temperature Distribution", col="blue") # fit the distribution d <- density(wnum$temperature) plot(d, main="Temperature Distribution", xlab="Temperature") polygon(d, col="red", border="blue") # difference in bins the distribution hist(iris$petalwidth, col="blue", breaks=10, xlab="Petal Width", main="") hist(iris$petalwidth, col="blue", breaks=20, xlab="Petal Width", main="") d <- density(iris$petalwidth) plot(d, main="Petal Width Distribution", xlab="Petal Width") polygon(d, col="red", border="blue") 50
  • 36. Prof. Pier Luca Lanzi Maps •  Maps are a very effective communications tool that can visualize thousands of data points in just one figure 51
  • 37. Prof. Pier Luca Lanzi Mapping Data with R # http://togaware.com/onepager/MapsO.pdf # required packages install.packages("maps") install.packages("ggmap") install.packages("oz") library(maps) library(ggmap) library(oz) library(ggplot2) library(scales) ds <- map_data("world") p <- ggplot(ds, aes(x=long, y=lat, group=group, fill=region)) p <- p + geom_polygon() p <- p + theme(legend.position = "none”) 52
  • 38. Prof. Pier Luca Lanzi Mapping Data with R # World map p <- ggplot(ds, aes(x=long, y=lat, group=group, fill=region)) p <- p + geom_polygon() p <- p + theme(legend.position = "none") p # Map of Europe map <- get_map(location="Europe", zoom=4) p <- ggmap(map) p # Google Map map <- get_map(location="Sydney", zoom=14, maptype="roadmap", source="google") p <- ggmap(map) p 53
  • 39. Prof. Pier Luca Lanzi Mapping Data with R # Mapping arrests arrests <- USArrests names(arrests) <- tolower(names(arrests)) arrests$region <- tolower(rownames(USArrests)) head(arrests) # maps the attribute state in their long/lat coordinates states <- map_data("state") # join the database of state information with the arrests information using region ds <- merge(states, arrests, sort=FALSE, by="region") # reorder the points for plotting otherwise the borders are plotted incorrectly ds <- ds[order(ds$order), ] g <- ggplot(ds, aes(long, lat, group=group, fill=ds$assault/ds$murder)) g <- g + geom_polygon() print(g) 54
  • 40. Prof. Pier Luca Lanzi Mapping Data for Visualization •  Data objects, their attributes, and the relationships among data objects are translated into graphical elements such as points, lines, shapes, and colors •  Objects are often represented as points •  Their attribute values can be represented as the position of the points or the characteristics of the points, e.g., color, size, and shape •  If position is used, then the relationships of points, i.e., whether they form groups or a point is an outlier, is easily perceived. 55
  • 41. Prof. Pier Luca Lanzi Data Arrangement •  Is the placement of visual elements within a display •  Influence on how easy it is to understand the data 56
  • 42. Prof. Pier Luca Lanzi Selection •  Is the elimination or the de-emphasis of ! certain objects and attributes •  Selection may involve choosing a subset of attributes ! Dimensionality reduction is often used to reduce the number of dimensions to two or three ! Alternatively, pairs of attributes can be considered •  Selection may also involve choosing a subset of objects ! A region of the screen can only show so many points ! Can sample, but want to preserve points in sparse areas 57
  • 43. Prof. Pier Luca Lanzi Box Plots •  Box Plots (invented by Tukey) •  Another way of displaying the distribution of data •  Following figure shows ! the basic part of a box plot •  IQR is the interquartile range ! or Q3-Q1 58 outlier Min (> Q1 -1.5 IQR) 1st quartile (Q1) 3rd quartile (Q3) 2nd quartile (Q2) Max ( < Q3 +1.5 IQR)
  • 44. Prof. Pier Luca Lanzi Box Plot Example 59
  • 45. Prof. Pier Luca Lanzi Boxplots in R # set working directory setwd("~/Dropbox/Documents/Online/Corsi/DMTM/data") # load data iris = read.arff("iris.arff") boxplot(iris[,1:4], ylab="values (cm)", main="iris dataset") boxplot(iris[,1:4], ylab="values (cm)", main="iris dataset", las=2, names=c("sep len", "sep wid", "pet len", "pet wid"), col=c("lightblue","lightblue","pink","pink"), at=c(1,2,5,6)) boxplot(iris[,1:4], ylab="values (cm)", main="iris dataset", las=2, names=c("sep len", "sep wid", "pet len", "pet wid"), border=c("blue","blue","green","green"), at=c(1,2,5,6)) # more examples # http://www.r-bloggers.com/box-plot-with-r-tutorial/ 60
  • 46. Prof. Pier Luca Lanzi Scatter Plots •  Attributes values determine the position •  Two-dimensional scatter plots most common, but can have three-dimensional scatter plots •  Often additional attributes can be displayed by using the size, shape, and color of the markers that represent the objects •  It is useful to have arrays of scatter plots can compactly summarize the relationships of several pairs of attributes •  Examples: http://www.statmethods.net/graphs/scatterplot.html 61
  • 47. Prof. Pier Luca Lanzi Scatter Plots in R # set working directory setwd("~/Dropbox/Documents/Online/Corsi/DMTM/data") # load data iris = read.arff("iris.arff") # attach iris to the path attach(iris) # plot scatter plot plot(petallength,sepallength, xlab="Petal Length", ylab="Sepal Length", pch=19) # linear model abline(lm(sepallength~petallength), col="red") # regression line (y~x) # local linear model lines(lowess(petallength, sepallength), col="blue") # lowess line (x,y) 62
  • 48. Prof. Pier Luca Lanzi Scatter Plots in R library(car) scatterplot(sepallength~petallength | class, data=iris, xlab="Petal Length”, ylab="Sepal Length", main="Enhanced Scatter Plot", labels=row.names(iris)) 63
  • 49. Prof. Pier Luca Lanzi Scatter Plot Array for Iris 64
  • 50. Prof. Pier Luca Lanzi Scatter Matrix Plots in R # paired library(car) scatterplot(sepallength~petallength | class, data=iris, xlab="Petal Length", ylab="Sepal Length", main="Enhanced Scatter Plot", labels=row.names(iris)) png("~/Downloads/scatter1.png") # scatter plot matrix pairs(~petallength+petalwidth+sepallength+sepalwidth,data=iris, main="Simple Scatterplot Matrix") dev.off() library(car) png("~/Downloads/scatter2.png") # scatter plot matrix scatterplotMatrix(~petallength+petalwidth+sepallength+sepalwidth|class, data=iris, main="Scatter Plots vs Class") dev.off() 65
  • 51. Prof. Pier Luca Lanzi Scatter Plot Combined with Box Plots 66
  • 52. Prof. Pier Luca Lanzi Scatter Plots with Box Plots # Add boxplots to a scatterplot par(fig=c(0,0.8,0,0.8), new=TRUE) plot(mtcars$wt, mtcars$mpg, xlab="Miles Per Gallon", ylab="Car Weight") par(fig=c(0,0.8,0.55,1), new=TRUE) boxplot(mtcars$wt, horizontal=TRUE, axes=FALSE) par(fig=c(0.65,1,0,0.8),new=TRUE) boxplot(mtcars$mpg, axes=FALSE) mtext("Enhanced Scatterplot", side=3, outer=TRUE, line=-3) 67
  • 53. Prof. Pier Luca Lanzi Contour Plots •  Useful for continuous attributes measured on a spatial grid •  They partition the plane into regions of similar values •  The contour lines that form the boundaries of these regions connect points with equal values •  The most common example is contour maps of elevation •  Can also display temperature, rainfall, air pressure, etc. 68
  • 54. Prof. Pier Luca Lanzi Celsius
  • 55. Prof. Pier Luca Lanzi Matrix Plots •  Can plot the data matrix •  This can be useful when objects are sorted according to class •  Typically, the attributes are normalized to prevent one attribute from dominating the plot •  Plots of similarity or distance matrices can also be useful for visualizing the relationships between objects 70
  • 56. Prof. Pier Luca Lanzi Heatmaps 71 dm <- data.matrix(iris[,1:4]) heatmap(dm)
  • 57. Prof. Pier Luca Lanzi additional examples http://onepager.togaware.com/PlotsO.pdf
  • 58. Prof. Pier Luca Lanzi Other Visualization Techniques •  Star Plots ! Similar approach to parallel coordinates, ! but axes radiate from a central point ! The line connecting the values of an object is a polygon •  Chernoff Faces ! Approach created by Herman Chernoff ! This approach associates each attribute with a characteristic of a face ! The values of each attribute determine the appearance of the corresponding facial characteristic ! Each object becomes a separate face ! Relies on human’s ability to distinguish faces 73
  • 61. Prof. Pier Luca Lanzi Chernoff Faces •  More dimensions are plotted using several features of human faces 76
  • 62. Prof. Pier Luca Lanzi http://cartastrophe.files.wordpress.com/2010/06/spinelli.png
  • 64. Prof. Pier Luca Lanzi Chernoff Faces & Star/Radar Plots # http://cran.r-project.org/web/packages/aplpack/aplpack.pdf library(foreign) library(aplpack) # set working directory setwd("~/Dropbox/Documents/Online/Corsi/DMTM/data") # load data iris = read.arff("iris.arff") # attach iris to the path attach(iris) # Chernoff faces faces(iris[1:16,1:4]) 79
  • 65. Prof. Pier Luca Lanzi Chernoff Faces & Star/Radar Plots require(grDevices) stars(mtcars[, 1:7], key.loc = c(14, 2), main = "Motor Trend Cars : stars(*, full = F)", full = FALSE) # full stars stars(mtcars[, 1:7], key.loc = c(14, 1.5), main = "Motor Trend Cars : full stars()", flip.labels = FALSE) # spider radar plot stars(mtcars[, 1:7], locations = c(0, 0), radius = FALSE, key.loc = c(0, 0), main = "Motor Trend Cars", lty = 2) # adding colors palette(rainbow(12, s = 0.6, v = 0.75)) stars(mtcars[, 1:7], len = 0.8, key.loc = c(12, 1.5), main = "Motor Trend Cars", draw.segments = TRUE) # positioning stars(mtcars[, 1:7], len = 0.6, key.loc = c(1.5, 0), main = "Motor Trend Cars", draw.segments = TRUE, nrow = 6, cex = .7) dev.off() faces(mtcars[,1:7]) 80
  • 66. Prof. Pier Luca Lanzi examples
  • 67. Prof. Pier Luca Lanzi do we read the articles we share? does my banner work?
  • 68. Prof. Pier Luca Lanzi “When we combined attention and traffic to find the story that had the largest volume of total engaged time, we found that it had fewer than 100 likes and fewer than 50 tweets. Conversely, the story with the largest number of tweets got about 20% of the total engaged time that the most engaging story received.”
  • 69. Prof. Pier Luca Lanzi “Here’s the skinny, 66% of attention on a normal media page is spent below the fold.That leaderboard at the top of the page? People scroll right past that and spend their time where the content not the cruft is. .”
  • 70. Prof. Pier Luca Lanzi http://time.com/12933/what-you-think-you-know-about-the-web-is-wrong/?iid=biz-category-mostpop2
  • 71. Prof. Pier Luca Lanzi http://apps.startribune.com/news/20140313-beer-me-minnesota/