Docsity

CS 245: Data Analysis Notes - Decision Trees, Clustering, Association Rules, Slides of Principles of Database Management

Toggle sidebar
bg1
1
Data Warehousing Overview
CS245 Notes 11
Hector Garcia-Molina
Stanford University
CS 245 1
Notes11 CS 245 Notes11 2
Outline
What is a data warehouse?
Why a warehouse?
Models & operations
Implementing a warehouse
CS 245 Notes11 3
What is a Warehouse?
Collection of diverse data
subject oriented
aimed at executive, decision maker
often a copy of operational data
with value-added data (e.g., summaries, history)
integrated
time-varying
non-volatile
more
CS 245 Notes11 4
What is a Warehouse?
Collection of tools
gathering data
cleansing, integrating, ...
querying, reporting, analysis
data mining
monitoring, administering warehouse
CS 245 Notes11 5
Warehouse Architecture
Client Client
Warehouse
Source Source Source
Query & Analysis
Integration
Metadata
CS 245 Notes11 6
Motivating Examples
Forecasting
Comparing performance of units
Monitoring, detecting fraud
Visualization
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download CS 245: Data Analysis Notes - Decision Trees, Clustering, Association Rules and more Slides Principles of Database Management in PDF only on Docsity!

Data Warehousing Overview

CS245 Notes 11

Hector Garcia-Molina

Stanford University

CS 245 1 Notes11 CS 245 Notes 2

Outline

 What is a data warehouse?

 Why a warehouse?

 Models & operations

 Implementing a warehouse

CS 245 Notes11 (^3)

What is a Warehouse?

 Collection of diverse data

subject oriented

aimed at executive, decision maker

often a copy of operational data

with value-added data (e.g., summaries, history)

integrated

time-varying

non-volatile

more

CS 245 Notes11 (^4)

What is a Warehouse?

 Collection of tools

gathering data

cleansing, integrating, ...

querying, reporting, analysis

data mining

monitoring, administering warehouse

CS 245 Notes 5

Warehouse Architecture

Client

Client

Warehouse

Source Source Source

Query & Analysis

Integration

Metadata

CS 245 Notes 6

Motivating Examples

 Forecasting

 Comparing performance of units

 Monitoring, detecting fraud

 Visualization

CS 245 Notes 7

Alternative to Warehousing

 Two Approaches:

Query-Driven (Lazy)

Warehouse (Eager)

Source Source

CS 245 Notes 8

Query-Driven Approach

Client Client

Wrapper Wrapper Wrapper

Mediator

Source Source Source

CS 245 Notes11 (^9)

Advantages of Warehousing

 High query performance

 Queries not visible outside warehouse

 Local processing at sources unaffected

 Can operate when sources unavailable

 Can query data not stored in a DBMS

 Extra information at warehouse

Modify, summarize (store aggregates)

Add historical information

CS 245 Notes11 (^10)

Advantages of Query-Driven

 No need to copy data

less storage

no need to purchase data

 More up-to-date data

 Query needs can be unknown

 Only query interface needed at sources

 May be less draining on sources

CS 245 Notes 11

Warehouse Models & Operators

 Data Models

relational

cubes

 Operators

CS 245 Notes 12

Star

customer custId name address city 53 joe 10 main sfo 81 fred 12 main sfo 111 sally 80 willow la

product prodId name price p1 bolt 10 p2 nut 5

store storeId city c1 nyc c2 sfo c3 la

sale oderId date custId prodId storeId qty amt o100 1/7/97 53 p1 c1 1 12 o102 2/7/97 53 p2 c1 2 11 105 3/8/97 111 p1 c3 5 50

CS 245 Notes 19

Aggregates

sale prodId storeId date amt p1 c1 1 12 p2 c1 1 11 p1 c3 1 50 p2 c2 1 8 p1 c1 2 44 p1 c2 2 4

• Add up amounts for day 1

• In SQL: SELECT sum(amt) FROM SALE

WHERE date = 1

CS 245 Notes 20

Aggregates

sale prodId storeId date amt p1 c1 1 12 p2 c1 1 11 p1 c3 1 50 p2 c2 1 8 p1 c1 2 44 p1 c2 2 4

• Add up amounts by day

• In SQL: SELECT date, sum(amt) FROM SALE

GROUP BY date

ans date sum 1 81 2 48

CS 245 Notes11 (^21)

Another Example

sale prodId storeId date amt p1 c1 1 12 p2 c1 1 11 p1 c3 1 50 p2 c2 1 8 p1 c1 2 44 p1 c2 2 4

• Add up amounts by day, product

• In SQL: SELECT date, sum(amt) FROM SALE

GROUP BY date, prodId

sale prodId date amt p1 1 62 p2 1 19 p1 2 48

drill-down

rollup

CS 245 Notes11 (^22)

Aggregates

 Operators: sum, count, max, min,

median, ave

 “Having” clause

 Using dimension hierarchy

average by region (within store)

maximum by month (within date)

CS 245 Notes 23

Cube Aggregation

day 2

c1 c2 c p1 44 4 p2 c1 c2 c p1 12 50 p2 11 8

day 1

c1 c2 c p1 56 4 50 p2 11 8

c1 c2 c sum 67 12 50

sum p1 110 p2 19

drill-down

rollup

Example: computing sums

CS 245 Notes 24

Cube Operators

day 2

c1 c2 c p1 44 4 p2 c1 c2 c p1 12 50 p2 11 8

day 1

c1 c2 c p1 56 4 50 p2 11 8

c1 c2 c sum 67 12 50

sum p1 110 p2 19

sale(c1,,)

sale(,,*)

sale(c2,p2,*)

CS 245 Notes 25

c1 c2 c3 *

p1 56 4 50 110

p2 11 8 19

Extended Cube

day 2 c1 c2 c3 *

p1 44 4 48

p

c1 c2 c3 *

p1 12 50 62

p2 11 8 19

day 1

sale(,p2,)

CS 245 Notes 26

Aggregation Using Hierarchies

day 2

c1 c2 c p1 44 4 p2 (^) c1 c2 c p1 12 50 p2 11 8

day 1

region A region B p1 56 54 p2 11 8

customer

region

country

(customer c1 in Region A;

customers c2, c3 in Region B)

CS 245 Notes11 (^27)

Data Analysis

 Decision Trees

 Clustering

 Association Rules

CS 245 Notes11 (^28)

Decision Trees

sale custId car age city newCar c1 taurus 27 sf yes c2 van 35 la yes c3 van 40 sf yes c4 taurus 22 sf yes c5 merc 50 la no c6 taurus 25 la no

Example:

• Conducted survey to see what customers were

interested in new model car

• Want to select customers for advertising campaign

training

set

CS 245 Notes 29

One Possibility

sale custId car age city newCar c1 taurus 27 sf yes c2 van 35 la yes c3 van 40 sf yes c4 taurus 22 sf yes c5 merc 50 la no c6 taurus 25 la no

age<

city=sf car=van

likely unlikely likely unlikely

Y Y

Y

N N

N

CS 245 Notes 30

Another Possibility

sale custId car age city newCar c1 taurus 27 sf yes c2 van 35 la yes c3 van 40 sf yes c4 taurus 22 sf yes c5 merc 50 la no c6 taurus 25 la no

car=taurus

city=sf age<

likely unlikely likely unlikely

Y Y

Y

N N

N

CS 245 Notes 37

Association Rule

 Rule: { p 1 , p 3 , p 8 }

 Support: number of baskets where these

products appear

 High-support set: support  threshold s

 Problem: find all high support sets

Implementation Issues

 ETL (Extraction, transformation, loading)

Getting data to the warehouse

Entity Resolution

 What to materialize?

 Efficient Analysis

Association rule mining

CS 245 Notes 38

CS 245 Notes11 (^39)

ETL: Monitoring Techniques

 Periodic snapshots

 Database triggers

 Log shipping

 Data shipping (replication service)

 Transaction shipping

 Polling (queries to source)

 Screen scraping

 Application level monitoring

Advantages & Disadvantages!!

CS 245 Notes11 (^40)

ETL: Data Cleaning

 Migration (e.g., yen  dollars)

 Scrubbing: use domain-specific knowledge (e.g.,

social security numbers)

 Fusion (e.g., mail list, customer merging)

 Auditing: discover rules & relationships

(like data mining)

billing DB

service DB

customer1(Joe)

customer2(Joe)

merged_customer(Joe)

41

More details: Entity Resolution

N: a A: b CC#: c Ph: e

e

N: a Exp: d Ph: e

e

42

Applications

 comparison shopping

 mailing lists

 classified ads

 customer files

 counter-terrorism

N: a A: b CC#: c Ph: e

e

N: a Exp: d Ph: e

e

Why is ER Challenging?

 Huge data sets

 No unique identifiers

 Lots of uncertainty

 Many ways to skin the cat

43

Taxonomy: Pairwise vs Global

 Decide if r, s match only by looking at r, s?

 Or need to consider more (all) records?

44

Nm: Pat Smith

Ad: 123 Main St

Ph: (650) 555-

Nm: Patrick Smith

Ad: 132 Main St

Ph: (650) 555-

Nm: Patricia Smith

Ad: 123 Main St

Ph: (650) 777-

or

Taxonomy: Pairwise vs Global

 Global matching complicates things a lot!

e.g., change decision as new records arrive

45

Nm: Pat Smith

Ad: 123 Main St

Ph: (650) 555-

Nm: Patrick Smith

Ad: 132 Main St

Ph: (650) 555-

Nm: Patricia Smith

Ad: 123 Main St

Ph: (650) 777-

or

Taxonomy: Outcome

 Partition of records

e.g., comparison shopping

 Merged records

46

Nm: Pat Smith

Ad: 123 Main St

Ph: (650) 555-

Nm: Patricia Smith

Ad: 123 Main St

Ph: (650) 555-

Hair: Black

Nm: Patricia Smith

Ad: 132 Main St

Ph: (650) 777-

Hair: Black

47

Taxonomy: Outcome

 Iterate after merging

Nm: Tom

Wk: IBM

Oc: laywer

Sal: 500K

Nm: Tom

Ad: 123 Main

BD: Jan 1, 85

Wk: IBM

Nm: Thomas

Ad: 123 Maim

Oc: lawyer

Nm: Tom

Ad: 123 Main

BD: Jan 1, 85

Wk: IBM

Oc: lawyer

Nm: Tom

Ad: 123 Main

BD: Jan 1, 85

Wk: IBM

Oc: lawyer

Sal: 500K

Taxonomy: Record Reuse

 One record related to multiple entities?

48

Nm: Pat Smith Sr.

Ph: (650) 555-

Ph: (650) 555-

Ad: 123 Main St

Nm: Pat Smith Jr.

Ph: (650) 555-

Nm: Pat Smith Sr.

Ph: (650) 555-

Ad: 123 Main St

Nm: Pat Smith Jr.

Ph: (650) 555-

Ad: 123 Main St

Implementation Issues

 ETL (Extraction, transformation, loading)

Getting data to the warehouse

Entity Resolution

 What to materialize?

 Efficient Analysis

Association rule mining

CS 245 Notes 55 CS 245 Notes 56

What to Materialize?

 Store in warehouse results useful for

common queries

 Example:

day 2 (^) p1 c1 44^ c2 4^ c p2 (^) c1 c2 c p1 12 50 p2 11 8

day 1

c1 c2 c p1 56 4 50 p2 11 8

c1 c2 c p1 67 12 50

c p1 110 p2 19

total sales

materialize

CS 245 Notes11 (^57)

Materialization Factors

 Type/frequency of queries

 Query response time

 Storage cost

 Update cost

CS 245 Notes11 (^58)

Cube Aggregates Lattice

city, product, date

city, product city, date product, date

city product date

all

day 2 (^) p1 c1 44^ c2 4^ c p2 (^) c1 c2 c p1 12 50 p2 11 8

day 1

c1 c2 c p1 56 4 50 p2 11 8

c1 c2 c p1 67 12 50

129

use greedy

algorithm to

decide what

to materialize

CS 245 Notes 59

Dimension Hierarchies

all

state

city

cities city state

c1 CA

c2 NY

CS 245 Notes 60

Dimension Hierarchies

city, product

city, product, date

city, date product, date

city product date

all

state, product, date

state, date

state, product

state

not all arcs shown...

CS 245 Notes 61

Interesting Hierarchy

all

years

quarters

months

days

weeks

time day week month quarter year 1 1 1 1 2000 2 1 1 1 2000 3 1 1 1 2000 4 1 1 1 2000 5 1 1 1 2000 6 1 1 1 2000 7 1 1 1 2000 8 2 1 1 2000

conceptual

dimension table

Implementation Issues

 ETL (Extraction, transformation, loading)

Getting data to the warehouse

Entity Resolution

 What to materialize?

 Efficient Analysis

Association rule mining

CS 245 Notes 62

CS 245 Notes11 (^63)

Finding High-Support Pairs

 Baskets(basket, item)

 SELECT I.item, J.item, COUNT(I.basket)

FROM Baskets I, Baskets J

WHERE I.basket = J.basket AND

I.item < J.item

GROUP BY I.item, J.item

HAVING COUNT(I.basket) >= s;

CS 245 Notes11 (^64)

Finding High-Support Pairs

 Baskets(basket, item)

 SELECT I.item, J.item, COUNT(I.basket)

FROM Baskets I, Baskets J

WHERE I.basket = J.basket AND

I.item < J.item

GROUP BY I.item, J.item

HAVING COUNT(I.basket) >= s;

WHY?

CS 245 Notes 65

Example

basket item t1 p t1 p t1 p t2 p t2 p t2 p ... ...

basket item1 item t1 p2 p t1 p2 p t1 p5 p t2 p5 p t2 p5 p t2 p8 p ... ... ...

CS 245 Notes 66

Example

basket item t1 p t1 p t1 p t2 p t2 p t2 p ... ...

basket item1 item t1 p2 p t1 p2 p t1 p5 p t2 p5 p t2 p5 p t2 p8 p ... ... ...

check if

count  s

CS 245 Notes 73

Algorithm for 2-Sets

 INSERT INTO okBaskets(basket, item)

SELECT basket, item

FROM Baskets

GROUP BY item

HAVING COUNT(basket) >= s;

 Perform mining on okBaskets

SELECT I.item, J.item, COUNT(I.basket)

FROM okBaskets I, okBaskets J

WHERE I.basket = J.basket AND

I.item < J.item

GROUP BY I.item, J.item

HAVING COUNT(I.basket) >= s;

CS 245 Notes 74

Counting Efficiently

 One way:

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p2 p t3 p5 p t3 p2 p ... ... ...

threshold = 3

CS 245 Notes11 (^75)

Counting Efficiently

 One way:

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p2 p t3 p5 p t3 p2 p ... ... ...

sort

basket I.item J.item t3 p2 p t3 p2 p t1 p5 p t2 p5 p t3 p5 p t2 p8 p ... ... ...

threshold = 3

CS 245 Notes11 (^76)

Counting Efficiently

 One way:

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p2 p t3 p5 p t3 p2 p ... ... ...

sort

basket I.item J.item t3 p2 p t3 p2 p t1 p5 p t2 p5 p t3 p5 p t2 p8 p ... ... ...

count &

remove count^ I.item J.item

3 p5 p 5 p12 p ... ... ...

threshold = 3

CS 245 Notes 77

Counting Efficiently

 Another way:

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p2 p t3 p5 p t3 p2 p ... ... ...

threshold = 3

CS 245 Notes 78

Counting Efficiently

 Another way:

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p2 p t3 p5 p t3 p2 p ... ... ...

scan &

count

count I.item J.item 1 p2 p 2 p2 p 3 p5 p 5 p12 p 1 p21 p 2 p21 p ... ... ...

keep counter

array in memory

threshold = 3

CS 245 Notes 79

Counting Efficiently

 Another way:

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p2 p t3 p5 p t3 p2 p ... ... ...

remove

count I.item J.item 3 p5 p 5 p12 p ... ... ...

scan &

count

count I.item J.item 1 p2 p 2 p2 p 3 p5 p 5 p12 p 1 p21 p 2 p21 p ... ... ...

keep counter

array in memory

threshold = 3

CS 245 Notes 80

Counting Efficiently

 Another way:

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p2 p t3 p5 p t3 p2 p ... ... ...

remove

count I.item J.item 3 p5 p 5 p12 p ... ... ...

scan &

count

count I.item J.item 1 p2 p 2 p2 p 3 p5 p 5 p12 p 1 p21 p 2 p21 p ... ... ...

keep counter

array in memory

threshold = 3

CS 245 Notes11 (^81)

Yet Another Way

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p2 p t3 p5 p t3 p2 p ... ... ...

scan &

hash &

count

count bucket 1 A 5 B 2 C 1 D 8 E 1 F ... ...

in-memory

hash table threshold = 3

CS 245 Notes11 (^82)

Yet Another Way

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p2 p t3 p5 p t3 p2 p ... ... ...

scan &

hash &

count

count bucket 1 A 5 B 2 C 1 D 8 E 1 F ... ...

in-memory

hash table threshold = 3

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p5 p t5 p12 p t8 p12 p ... ... ...

(2) scan &

remove

CS 245 Notes 83

Yet Another Way

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p2 p t3 p5 p t3 p2 p ... ... ...

scan &

hash &

count

count bucket 1 A 5 B 2 C 1 D 8 E 1 F ... ...

in-memory

hash table threshold = 3

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p5 p t5 p12 p t8 p12 p ... ... ...

(2) scan &

remove

false positive

CS 245 Notes 84

Yet Another Way

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p2 p t3 p5 p t3 p2 p ... ... ...

scan &

hash &

count

count bucket 1 A 5 B 2 C 1 D 8 E 1 F ... ...

in-memory

hash table threshold = 3

basket I.item J.item t1 p5 p t2 p5 p t2 p8 p t3 p5 p t5 p12 p t8 p12 p ... ... ...

(2) scan &

remove

count I.item J.item 3 p5 p 1 p8 p 5 p12 p ... ... ...

(3) scan& count

in-memory counters

false positive

Extra: Data Mining in the InfoLab

CS 245 Notes 91

quarters

Recommendations in CourseRank

user q1 q2 q3 q

u1 a: 5 b: 5 d: 5

u2 a: 1 e: 2 d: 4 f: 3

u3 g: 4 h: 2 e: 3 f: 3

u4 b: 2 g: 4 h: 4 e: 4

u a: 5 g: 4 e: 4

Recommend d (and f, h)

Sequence Mining

 Given a set of transcripts, use Pr[x|a]

to predict if x is a good recommendation

given user has taken a.

 Two issues...

CS 245 Notes 92

Pr[x|a] Not Quite Right

CS 245 Notes11 (^93)

transcript containing

2 a

3 x

4 a ‐> x

5 x ‐> a

Pr[x|a] = 2/

Pr[x|a ~x] = 1/

target user’s transcript:

[ ... a .... || unknown ]

recommend x?

User Has Taken >= 1 Course

 User has taken T= {a, b, c}

 Need Pr[x|T

~x

]

 Approximate as Pr[x|a

~x

b

~x

c

~x

]

 Expensive to compute, so...

CS 245 Notes11 (^94)

CourseRank User Study

CS 245 Notes 95

Series Series

good, expected

good, unexpected

percentage of ratings