lecture notes for chapter 2 introduction to data miningpredrag/classes/2010sprin… ·  ·...

31
Data Mining: Data Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach, Kumar (modified for I211 by P. Radivojac) © Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 1

Upload: voque

Post on 21-Mar-2018

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Data Mining: Data

Lecture Notes for Chapter 2

Introduction to Data Miningby

Tan, Steinbach, Kumar

(modified for I211 by P. Radivojac)

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 1

Page 2: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

What is Data?

Collection of data objects and their attributes Attributes Class

An attribute is a property or characteristic of an object

E l l f

Tid Home Owner

Marital Status

Taxable Income Cheat

1 Yes Single 125K No– Examples: eye color of a

person, temperature, etc.– Attribute is also known as

feature variable variate

g

2 No Married 100K No

3 No Single 70K No

4 Yes Married 120K No feature, variable, variate

A collection of attributes describe a data point

5 No Divorced 95K Yes

6 No Married 60K No

7 Yes Divorced 220K No

Data points

describe a data point– data point is also known as

object, record, instance, or example

8 No Single 85K Yes

9 No Married 75K No

10 No Single 90K Yes 10

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 2

example

Page 3: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Attribute Values

Attribute values are numbers or symbols assigned to an attribute

Distinction between attributes and attribute valuesDistinction between attributes and attribute values– Same attribute can be mapped to different attribute values

Example: height can be measured in feet or meters

– Different attributes can be mapped to the same set of valuesExample: Attribute values for ID and age are integersBut properties of attribute values can be different

– ID has no limit but age has a maximum and minimum value– average age is interesting to know, but average ID is meaningless

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 3

g g g , g g

Page 4: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Measurement of Length

The way you measure an attribute is something that may not match the attributes properties.

1

2

5

7

A

B

38

C

order actual length

10 4

D

515

E

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 4

Page 5: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Types of Attributes

There are different types of attributes– NominalNominal

Examples: ID numbers, eye color, zip codes

– OrdinalExamples: rankings (e.g., taste of potato chips on a scale from 1-10), grades, height in {tall, medium, short}

– IntervalIntervalExamples: calendar dates, temperatures in Celsius or Fahrenheit.

– RatioExamples: temperature in Kelvin, length, time, counts

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 5

Page 6: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Properties of Attribute Values

The type of an attribute depends on which of the following properties it possesses:following properties it possesses:– Distinctness: = ≠– Order: < > – Addition: + -– Multiplication: * /

– Nominal attribute: distinctnessOrdinal attrib te distinctness & order– Ordinal attribute: distinctness & order

– Interval attribute: distinctness, order & addition– Ratio attribute: all 4 properties

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 6

– Ratio attribute: all 4 properties

Page 7: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Attribute Type

Description Examples Operations

Nominal The values of a nominal attribute are just different names, i.e., nominal attributes provide only enough information to distinguish one object f h ( )

zip codes, employee ID numbers, eye color, sex: {male, female}

mode, entropy, contingency correlation, χ2 test

from another. (=, ≠)

Ordinal The values of an ordinal attribute provide enough information to order objects (< >)

hardness of minerals, {good, better, best}, grades street numbers

median, percentiles, rank correlation, run tests sign testsobjects. (<, >) grades, street numbers run tests, sign tests

Interval For interval attributes, the diff b l

calendar dates, i C l i

mean, standard d i i P 'differences between values are

meaningful, i.e., a unit of measurement exists. (+, - )

temperature in Celsius or Fahrenheit

deviation, Pearson's correlation, t and Ftests

Ratio For ratio variables, both differences and ratios are meaningful. (*, /)

temperature in Kelvin, monetary quantities, counts, age, mass, length, electrical current

geometric mean, harmonic mean, percent variation

current

Page 8: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Attribute Level

Transformation Comments

Nominal Any permutation of values If all employee ID numbers were reassigned, would it make any difference?y

Ordinal An order preserving change of values i e

An attribute encompassing the notion of good, better best can values, i.e.,

new_value = f(old_value) where f is a monotonic function.

g ,be represented equally well by the values {1, 2, 3} or by { 0.5, 1, 10}.

Interval new_value =a * old_value + b where a and b are constants

Thus, the Fahrenheit and Celsius temperature scales differ in terms of where their zero value is and the size of a unit (degree).

R ti l * ld l L th b d iRatio new_value = a * old_value Length can be measured in meters or feet.

Page 9: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Discrete and Continuous Attributes

Discrete Attribute– Has only a finite or countably infinite set of values– Examples: zip codes, counts, or the set of words in a collection of

documents – Often represented as integer variables. – Note: binary attributes are a special case of discrete attributes

Continuous Attribute– Has real numbers as attribute values– Examples: temperature, height, or weight. – Practically real values can only be measured and representedPractically, real values can only be measured and represented

using a finite number of digits.– Continuous attributes are typically represented as floating-point

variables.

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 9

Page 10: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Types of data sets

Record– Data Matrix

Document Data– Document Data– Transaction Data

Graph– World Wide Web– Molecular Structures

OrderedOrdered– Spatial Data– Temporal Data

S ti l D t– Sequential Data– Genetic Sequence Data

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 10

Page 11: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Important Characteristics of Structured Data

– DimensionalityCurse of Dimensionality

⎥⎥⎤

⎢⎢⎡

1

– SparsityOnl presence co nts ⎥

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢

11

Only presence counts

– Resolution ⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

1– ResolutionPatterns depend on the scale ⎥

⎥⎥⎥

⎦⎢⎢⎢⎢

⎣ 11

– Attribute and Class Imbalancesmall number of non zero elements (related to sparsity)

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 11

Page 12: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Record Data

Data that consists of a collection of records, each of which consists of a fixed set of attributesof which consists of a fixed set of attributes

Tid Home Owner

Marital Status

Taxable Income Cheat

1 Yes Single 125K No

2 No Married 100K No

3 No Single 70K No

4 Yes Married 120K No

5 No Divorced 95K Yes

6 No Married 60K No

7 Yes Divorced 220K No

8 No Single 85K Yes

9 No Married 75K No

10 No Single 90K Yes

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 12

10 No Single 90K Yes10

Page 13: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Data Matrix

If data objects have the same fixed set of numeric attributes, then the data objects can be thought of as points in a multi-dimensional space, where each dimension represents a distinct attribute

Such data set can be represented by an m-by-n matrix, where there are m rows, one for each object, and n

l f h tt ib tcolumns, one for each attribute

Thickness LoadDistanceProjection of y load

Projection of x Load

Thickness LoadDistanceProjection of y load

Projection of x Load

1 12 216 226 2512 65

1.22.715.225.2710.23

of y loadof x Load

1 12 216 226 2512 65

1.22.715.225.2710.23

of y loadof x Load

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 13

1.12.216.226.2512.65 1.12.216.226.2512.65

Page 14: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Document Data

Each document becomes a `term' vector, – each term is a component (attribute) of the vectoreach term is a component (attribute) of the vector,– the value of each component is the number of times

the corresponding term occurs in the document.

sea

timelown

gam

scobaply

coa

tea ason

eout

ost

winme

ore

all

layach

am

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 14

Page 15: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Example

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 15

Page 16: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Matlab Code

% read from pre-prepared files and count some words

dictionary = {'gaza', 'fuel', 'the', 'patriots'};

fid = fopen('1.txt', 'rt');s = textscan(fid, '%s');fclose(fid);fclose(fid);s{1} = lower(s{1});

fid = fopen('2.txt', 'rt');t t t (fid '% ')t = textscan(fid, '%s')fclose(fid);t{1} = lower(t{1});

for i = 1 : length(dictionary)D(1, i) = length(strmatch(dictionary{i}, s{1}));D(2, i) = length(strmatch(dictionary{i}, t{1}));

end

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 16

end

Page 17: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Transaction Data

A special type of record data, where – each record (transaction) involves a set of itemseach record (transaction) involves a set of items. – For example, consider a grocery store. The set of

products purchased by a customer during one shopping trip constitute a transaction, while the individual products that were purchased are the items.

TID Items

1 Bread, Coke, Milk

2 Beer, Bread2 Beer, Bread3 Beer, Coke, Diaper, Milk

4 Beer, Bread, Diaper, Milk

5 C k Di Milk

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 17

5 Coke, Diaper, Milk

Page 18: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Machine Learning Repository at UCI

contains a number of user deposited ML problemsftp://ftp.ics.uci.edu/pub/machine-learning-databasesp p p g

Discussion:– Pima Indians diabetes example (link)– Boston housing example (link)

German credit example (link)– German credit example (link)

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 18

Page 19: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

How to load certain data formats

From web sites– use readurl function

From Excel files– use xlsread function– use xlsread function

From text files– use textscan and related functions

From CSV files– use csvread function

M fil t t d i i d d

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 19

Many files are unstructured, parsing is needed

Page 20: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Reading Custom File Types

Need standard I/O for this– use fopen fclose fgetl fget for textuse fopen, fclose, fgetl, fget for text

files– use fread, fwrite, fseek, ftell for binary

files

E lExamples– reading protein sequence data

di d iti bi d t– reading and writing binary data

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 20

Page 21: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Graph Data

Examples: Generic graph and HTML Links

2

<a href="papers/papers.html#bbbb">Data Mining </a><li><a href="papers/papers.html#aaaa">

5

2

12

Graph Partitioning </a><li><a href="papers/papers.html#aaaa">Parallel Solution of Sparse Linear System of Equations </a><li> 2

5<a href="papers/papers.html#ffff">N-Body Computation and Dense Linear System Solvers

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 21

Page 22: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Chemical Data

Benzene Molecule: C6H6

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 22

Page 23: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Ordered/Sequential Data

Sequences of transactionsIt /E tItems/Events

An element of

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 23

the sequence

Page 24: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Ordered/Sequential Data

Genomic sequence data

1 GGTTCCGCCTTCAGCCCCCCGCC 01: ...GGTTCCGCCTTCAGCCCCCCGCC... 0

2: ...GGTTCCGCGTTCAGCCCCGCGCC... 1

3: GGTTCCGCCTTCAGCCCCCCGCC 03: ...GGTTCCGCCTTCAGCCCCCCGCC... 0

4: ...GGTTCCGCCTTCAGCCCCGCGCC... 0

5: ...GGTTCCGCCTTCAGCCCCTCGCC... 05: ...GGTTCCGCCTTCAGCCCCTCGCC... 0

6: ...GGTTCCGCCTTCAGCCCCGCGCC... 0

7: ...GGTTCCGCCTTCAGCCCCTCGCC... 0

8: ...GGTTCCGCATTCAGCCCCCCGCC... 1

9: ...GGTTCCGCCTTCAGCCCCGCGCC... 0

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 24

Page 25: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Ordered Data

Spatio-Temporal Data

Average Monthly Temperature of land and ocean

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 25

Page 26: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Data Quality

What kinds of data quality problems?How can we detect problems with the data?How can we detect problems with the data? What can we do about these problems?

Examples of data quality problems: – Noise and outliers – missing values – duplicate data

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 26

Page 27: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Noise

Noise refers to modification of original values– Examples: distortion of a person’s voice when talkingExamples: distortion of a person s voice when talking

on a poor phone and “static” on television screen

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 27

Two Sine Waves Two Sine Waves + Noise

Page 28: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Outliers

Outliers are data objects with characteristics that are considerably different than most of the otherare considerably different than most of the other data objects in the data set

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 28

Page 29: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Missing Values

Reasons for missing values– Information is not collected

(e.g., people decline to give their age and weight)– Attributes may not be applicable to all cases

(e g annual income is not applicable to children)(e.g., annual income is not applicable to children)

Handling missing valuesg g– Eliminate Data Objects– Estimate Missing Values– Ignore the Missing Value During Analysis– Replace with all possible values (weighted by their

probabilities)

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 29

probabilities)

Page 30: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Duplicate Data

Data set may include data objects that are duplicates, or almost duplicates of one anotherduplicates, or almost duplicates of one another– Major issue when merging data from heterogeneous

sources

Examples:– Same person with multiple email addresses

Data cleaning– Process of dealing with noise and duplicate data

issues

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 30

issues

Page 31: Lecture Notes for Chapter 2 Introduction to Data Miningpredrag/classes/2010sprin… ·  · 2010-01-25Lecture Notes for Chapter 2 Introduction to Data Mining by Tan, Steinbach,

Understanding data collection process

Sometimes, the whole population is available for labeling (say, we can provide features and a the class with limited resources for any object in the population). In such a case we’d like to select a sample that is a good representative of the populationrepresentative of the population.

However, there are situations where we do not have control of the data at hand. It is very important to understand the mechanism how the data was generated!!!generated!!!

Example 1: Bank loan data– all people eligible to apply for a loan > all people who apply > all people who areall people eligible to apply for a loan all people who apply all people who are

accepted > all people who take the loan

– Banks can only study behavior of the people who take the loan. Banks can only make inferences about a subset of the overall population.p p

Example 2: 1936 Presidential elections in the USA (Roosevelt vs. Landon)

© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 31

Example 3: 2007 Democratic primary in New Hampshire (Obama vs. Clinton)