SlideShare a Scribd company logo
1 of 60
สอนโดย
ดร.หทัยรัตน์ เกตุมณีชัยรัตน์
ภาควิชาการจัดการเทคโนโลยีการผลิตและสารสนเทศ
บทที่ 3: การเตรียมข้อมูลสาหรับการทาเหมือง
(Data Preprocessing)
336331 การทาเหมืองข้อมูล (Data Ming)
การเตรียมข้อมูลคืออะไร
 เป็นขั้นตอนในตอนแรกก่อนการทาเหมืองข้อมูล ที่จะสามารถ
ปรับปรุงคุณภาพโดยรวมของรูปแบบที่จากการทาเหมือง หรือก่อน
ถึงเวลาที่จะทาเหมืองจริง
ทาไมต้องมีการเตรียมข้อมูล
 เนื่องจากข้อมูลในความเป็นจริงมีความสกปรก คือ
- ข้อมูลไม่สมบูรณ์ (Incomplete data) เช่น ค่าของคุณลักษณะขาดหาย (Missing
value) ขาดคุณลักษณะที่น่าสนใจ หรือ ทา N/A ไว้ขาดรายละเอียดของข้อมูล
- ข้อมูลรบกวน (Noisy data) เช่น ข้อมูลมีค่าผิดพลาด (Error) หรือมีค่าผิดปกติ
(Outliers)
- ข้อมูลไม่สอดคล้อง (Inconsistent data) เช่น ข้อมูลเดียวกัน แต่ตั้งชื่อต่างกัน หรือ
ใช้ค่าแทนข้อมูลที่ต่างกัน
ทาไมต้องมีการเตรียมข้อมูล (ต่อ)
Cust_ID Name Income Age Birthday
001 A n/a 200 12/10/79
002 - $2000 25 27 Dec 81
003 C -10000 27 18 Feb 20
เทคนิคการเตรียมข้อมูล
1) Data Cleaning คือ การทาความสะอาดข้อมูล จัดการข้อมูลรบกวน
2) Data Integration คือ การผสานข้อมูล
3) Data Transformationคือ การแปลงข้อมูล
4) Data Reduction คือ การลดรูปข้อมูล
Data cleaning
Data integration
Data transformation
Data reduction
-2, 32, 100,59, 48 -0.02, 0.32, 1.00, 0.59, 0.48
transaction
transaction
attribute
attribute
A1 A2 A3 ………… A126
A1 A2 …… A115
T1
T2
…
T2000
เทคนิคการเตรียมข้อมูล
1) Data Cleaning (การทาความสะอาดข้อมูล)
 เนื่องจากข้อมูลจริงไม่สมบูรณ์อาจจะมีค่าที่ขาดหายไป (Missing
Value) ดังนั้นควรปรับข้อมูลให้มีความ smooth มากขึ้น
การจัดการข้อมูลค่าที่ขาดหาย (Missing value)
 ถ้านักศึกษา เป็นผู้จัดการของบริษัทแห่งหนึ่ง และต้องการวิเคราะห์
ข้อมูล
“การขายสินค้า และข้อมูลของลูกค้า”
 นักศึกษา พบว่า มีหลายๆรายการ ไม่มีการบันทึกค่าในแต่ละฟิลด์ หรือ
แอททริบิวต์เช่น ไม่มีการบันทึกข้อมูลรายได้ของลูกค้า
 คาถาม ???
นักศึกษาจะมีวิธีการจัดการค่าที่ขาดหายเหล่านี้ได้อย่างไร
การจัดการค่าข้อมูลที่ขาดหาย (Missing value)
1. Ignore the tuple
2. Fill in the missing value manually
3. Use a global constant to fill in the missing value
4. Use the attribute mean to fill in the missing value
5. Use the attribute mean for all samples belonging to the same
class as the given tuple
6. Use the most propable value to fill in the missing value
Ignore the tuple
 ตัดทิ้งรายการที่มีข้อมูลสูญหาย นิยมใช้กับการทาเหมืองข้อมูลแบบจาแนกประเภท
(Classification) ในกรณีที่ค่าคุณลักษณะขาดหายไปเป็นจานวนมาก
Fill in the missing value manually
 เติมค่าที่ขาดหายด้วยมือ วิธีนี้ไม่เหมาะสมกรณีที่ชุดข้อมูลมีขนาดใหญ่ และมีข้อมูล
ขาดหายจานวนมาก
Use a global constant to fill in the missing value
 เติมค่าคุณลักษณะของข้อมูลที่ขาดหายทุกค่า ด้วยค่าคงที่ค่าหนึ่ง เช่น ไม่รู้ค่า
หรือ unknown
Use the attribute mean to fill in the missing value
 ใช้ค่าเฉลี่ยของคุณลักษณะ เติมค่าข้อมูลที่ขาดหาย เช่น ถ้าทราบว่าลูกค้าที่รายได้
เฉลี่ยเดือนละ 12000 บาท จะใช้ค่านี้แทนค่ารายได้ของลูกค้าที่ขาดหาย
Use the attribute mean for all samples belonging to the
same class as the given tuple
 ใช้ค่าเฉลี่ยคุณลักษณะของตัวอย่างที่จัดอยู่ในประเภทเดียวกัน เพื่อเติมค่าข้อมูลที่
ขาดหาย เช่น เติมค่ารายได้ของลูกค้าที่ขาดหาย ด้วยค่าเฉลี่ยของลูกค้าที่อยู่ในกลุ่ม
อาชีพ เดียวกัน
Use the most propable value to fill in the missing value
 ใช้ค่าที่เป็นไปได้มากที่สุด เติมแทนค่าข้อมูลที่ขาดหาย เช่น ค่าที่ได้จาก
สมการความถดถอย (Regression) ค่าที่ได้จากการอนุมาน โดยใช้สูตรของเบย์
(Bayesian formula) หรือต้นไม้ตัดสินใจ (Decision tree) เช่น
ใช้ข้อมูลลูกค้า มาสร้างต้นไม้ตัดสินใจ เพื่อทานายรายได้ของลูกค้า แล้วนาไป
แทนค่าที่ขาดหาย
 วิธีนี้นิยมกันแพร่หลาย เนื่องจากทานายค่าข้อมูลที่ขาดหาย โดยพิจารณาจาก
ค่าของข้อมูลชุดปัจจุบัน และความสัมพันธ์ระหว่างคุณลักษณะในชุดข้อมูล
ข้อมูลรบกวน (Noisy data)
 ข้อมูลรบกวน เป็นข้อมูลที่มีความผิดพลาดแบบสุ่ม หรือคลาดเคลื่อนจากการ
วัด สาเหตุของความผิดพลาด อาจสืบเนื่องมาจาก
- อุปกรณ์เก็บรวบรวมข้อมูลทาหน้าที่ผิดพลาด
- ปัญหาการบันทึกหรือป้อนค่าข้อมูล
- ปัญหาการส่งข้อมูล (Data Transmission) ผิดพลาด
- ข้อจากัดทางเทคโนโลยี เช่น ข้อจากัดของขนาดบัฟเฟอร์
การจัดการข้อมูลรบกวน (Noisy data)
ทาได้หลายวิธี เช่น
 Binning Methods
 Regression
 Clustering
Binning Methods
 การปรับข้อมูลให้เรียบด้วยวิธีการแบบ binning ทาโดย
เรียงลาดับข้อมูล แล้วใช้หลักการตัดแบ่ง (Partition) แบ่งข้อมูลออกเป็นส่วนแต่
ละส่วนเรียกว่า bin แล้วทาการปรับเรียบข้อมูลในแต่ละ bin โดยใช้การปรับ
เรียบข้อมูลแบบท้องถิ่น (Local Smoothing) โดยใช้ค่าที่ได้จากเพื่อนบ้าน
ใกล้เคียง (Neighborhood) ใน bin หรือ bucket เดียวกันเช่น ค่าเฉลี่ยของ bin
(Bin Means) ค่ากลางของ bin (Bin Medians) หรือค่าขอบของ bin (Bin
Boundaries)
Binning Methods
 Binning Method
 Example:
Sorted data for price (in dollars):4, 8, 15, 21, 21, 24, 25, 28, 34
(N = 3)
 Partition into (equi-depth)bins:
Bin 1: 4, 8, 15
Bin 2: 21, 21, 24
Bin 3: 25, 28, 34
 Smoothing by bin means:
Bin 1: 9, 9, 9
Bin 2: 22, 22, 22
Bin 3: 29, 29, 29
 Smoothing by bin boundaries:
Bin 1: 4, 4, 15
Bin 2: 21, 21, 24
Bin 3: 25, 25, 34
Regression
Smooth by fitting the data into regression functions
Linear Regression
Y =α +βX
Multiple Linear Regression
Y =b0 +b1 X1 +b2 X2 +...+bmXm
Regression
 วิธีความถดถอย ใช้การทานายค่าของตัวแปรจากสมการความถดถอยที่หาได้ ด้วย
วิธีความผิดพลาดน้อยที่สุด (Least-square error) จากชุดตัวอย่างตัวแปร
x
y = x+1
y’ = x+1
X1
Y1
Y1’
Clustering
 การวิเคราะห์การจัดกลุ่ม จะช่วยตรวจหา และกาจัดค่าที่ผิดปกติ เช่น ค่าที่สูงหรือต่ากว่า
ปกติ จะไม่สามารถจัดอยู่ในกลุ่มใดๆ และตกอยู่นอกกลุ่ม
OutlierCluster
2) Data Transformation (การแปลงข้อมูล)
 การแปลงข้อมูลที่พบบ่อยในการทาเหมืองข้อมูลคือ การทานอร์มอลไลซ์
(Normalization) โดยแปลงค่าข้อมูลให้อยู่ในช่วงสั้นๆ ที่อัลกอริทึมการทาเหมือง
ข้อมูลสามารถนาไปใช้ประมวลผลได้
 วิธีการทานอร์มอลไลซ์ข้อมูลได้แก่
 min-max normalization
 z-score normalization
 normalization by decimal scaling
 Sigmoidal
Min-Max Nornalization
 การแปลงข้อมูลให้อยู่ในช่วงใหม่ [new_minA, new_maxA]
ตัวอย่าง เช่น
ข้อมูลคอลัมน์รายได้ (income) มีค่าต่าสุด 12,000 บาท (min) และมีค่ามาก
ที่สุด 98,000 บาท (max) ซึ่งข้อมูลที่ต้องการแปลงคือ 73,600 บาท ต้องการ
แปลงให้ข้อมูลนี้อยู่ในช่วงใหม่ คือ [0,1] เพราะฉะนั้น 73,600 บาท จะมีค่า
ใหม่เป็นเท่าใด
AAA
AA
A
minnewminnewmaxnew
minmax
minv
v _)__(' 



716.00)00.1(
000,12000,98
000,12600,73



Z-Score
 เป็นการปรับการกระจายของข้อมูลให้มีค่าเท่ากับ 0 และค่าเบี่ยงเบนมาตรฐานเท่ากับ 1
 หาได้จากสูตร
ตัวอย่างเช่น
ข้อมูลคอลัมภ์รายได้ (income) มีค่าเฉลี่ย 54,000 บาท (mean) และมีค่าเบี่ยงเบน
มาตรฐาน 16,000 บาท (stand_dev) ต้องการแปลงค่ารายได้73,600 บาท เป็นค่าใหม่
ตามวิธี Z-Score
A
A
devstand_
meanv
v

'
225.1
000,16
000,54600,73


Decimal scaling
 เป็นการแปลงค่าข้อมูลเดิมให้เป็นเลขทศนิยม ตาแหน่งทศนิยมกาหนดโดยค่า
สัมบูรณ์ที่มีค่ามากที่สุด
 ตัวอย่างเช่น
ค่าที่เป็นไปได้ของคุณลักษณะ A อยู่ในช่วงระหว่าง -986 ถึง 917 จะได้ว่าค่า
สัมบูรณ์ที่มากที่สุดคือ |-986| = 986 ดังนั้นเราจะหารข้อมูลแต่ละค่าด้วย 1000 โดย
ที่ j=3 ผลลัพธ์คือค่า -986 จะถูกแปลงเป็น -0.986
j
v
v
10
'
986.0
10
986
3


Sigmoidal
 Normalize input into [-1, 1]







e
e
y
1
1
'
std
meany 

-1
1
x
y
3) การผสานข้อมูล (Data Integration)
 เป็นการรวบรวมข้อมูลจากแหล่งที่เก็บต่างๆ มาไว้ที่เดียวกัน การผสาน
ข้อมูลจากแหล่งต่างๆ เพื่อช่วย
1. ลดหรือหลีกเลี่ยงความซ้าซ้อนของข้อมูล (Data Redundancies) ซึ่งจะ
นาไปสู่ปัญหาความไม่สอดคล้องกันของข้อมูล (Data Inconsistencies)
2. เพิ่มความเร็วและคุณภาพในการทาเหมืองข้อมูล
งานที่ต้องทาในการผสานข้อมูล
 การผสานโครงสร้างการเก็บข้อมูล (Schema Integration) โดยใช้ Metadata ช่วยใน
การบ่งชี้ entities ในแหล่งเก็บข้อมูลต่างๆ เช่น คุณลักษณะ Cusid ในแหล่งข้อมูล
A เป็นคุณลักษณะเดียวกับ CustNumber ในแหล่งข้อมูล B หรือไม่
 ตรวจหาและแก้ไข ค่าข้อมูลที่ขัดแย้ง เช่น ค่าคุณลักษณะเดียวกัน แต่ใช้หน่วยวัด
ต่างๆ กัน ในแต่ละแหล่งข้อมูล
 การกาจัดค่าข้อมูลซ้าซ้อน เช่น ค่าคุณลักษณะในแหล่งข้อมูลหนึ่ง อาจเป็นค่าที่ได้
จากการคานวณในอีกแหล่งข้อมูลหนึ่ง อาทิ ค่ารายได้รายปี
“Data Warehousing”
Data Integration
 Data integration:
 combines data from multiple sources into a
coherent store
 Schema integration
 integrate metadata from different sources
 Entity identification problem: identify real world
entities from multiple data sources, e.g., A.cust-id 
B.cust-#
 Detecting and resolving data value conflicts
 for the same real world entity, attribute values from
different sources are different
 possible reasons: different representations, different
scales, e.g., metric vs. British units
Data Integration (Cont.)
 Redundant data occur often when integration of
multiple databases
 The same attribute may have different names
in different databases
 One attribute may be a “derived” attribute in
another table, e.g., annual revenue
 Redundant data may be able to be detected by
correlation analysis
 Careful integration of the data from multiple
sources may help reduce/avoid redundancies
and inconsistencies and improve mining speed
and quality
Data Integration : Correlation analysis
 The correlation between attribute A and B can be
measured by
 If rA,B greater than 0, then A and B are positively
correlated, meaning that the value of A increase
as the values of B increase
 The mean of A is
 The standard deviation of A is
BA
BA
n
BBAA
r
)1(
))((
,




n
A
A

1
)( 2




n
AA
A
4) การลดรูปข้อมูล (Data Reduction)
• คลังข้อมูลเก็บข้อมูลจานวนมาก ขนาดเป็น เทราไบต์ ดังนั้นการ
วิเคราะห์ หรือการทาเหมืองข้อมูลที่ซับซ้อน ต้องใช้เวลานานในการ
ประมวลผลข้อมูลปริมาณมากๆ
• การลดรูป เป็นการกระทาเพื่อแทนข้อมูล ด้วยรูปแบบกะทัดรัด กินเนื้อ
ที่น้อยกว่า แต่สามารถนาไปใช้วิเคราะห์ แล้วเกิดผลลัพธ์ที่เท่ากันหรือ
เทียบเท่ากัน กับการวิเคราะห์จากข้อมูลทั้งหมด
4) การลดรูปข้อมูล (Data Reduction) (cont.)
 Data reduction strategies
Data cube aggregation
Dimensionality reduction — remove unimportant attributes
Data Compression
Numerosity reduction — fit data into models
Discretization and concept hierarchy generation
Data Reduction: Data cube aggregation
 The data can be aggregated that the resulting data summarize
 Ex. The data consist of the ALLElectronics sales per quarter,
for the year 2002 to 2004.
 aggregated in data summarize the total sales per year instead of
per quarter, without loss of information necessary of the
analysis task
Data Reduction: Data cube aggregation
 Concept hierarchies may exist for each
attribute, allowing the analysis of data at
multiple levels of abstraction
Data cube Lattice of cuboids
Data Reduction: Dimensionality reduction
 Feature selection (i.e., attribute subset
selection):
 Select a minimum set of features such that the
probability distribution of different classes
given the values for those features is as close
as possible to the original distribution given the
values of all features
 reduce # of patterns in the patterns, easier to
understand
 Heuristic methods:
 step-wise forward selection
 step-wise backward elimination
 combining forward selection and backward
elimination
Data Reduction: Dimensionality reduction
 Step-wise forward selection
Start with an empty of attributes called the reduced set
The best of the original attributes is determined and added to the reduced set
At each subsequent iteration, the best of the remaining original attributes
is added to the reduced set Initial attribute set:
{A1, A2, A3, A4, A5, A6}
Initial reduced set:
{}
{A1}
{A1, A4}
Reduced attribute set:
{A1, A4, A6}
Data Reduction: Dimensionality reduction
 Step-wise backward elimination
 Start with the full set of attributes
 At each step, removes the worst attribute
remaining in the set
Initial attribute set:
{A1, A2, A3, A4, A5, A6}
Initial reduced set:
{A1, A3, A4, A5, A6}
{A1, A4, A5, A6}
Reduced attribute set:
{A1, A4, A6}
Data Reduction: Dimensionality reduction
 Combining forward selection and backward
elimination
At each step, selects the best attribute
and removes the worst from among the
remaining attributes
Data Reduction: Dimensionality reduction
 Decision-tree induction
Initial attribute set:
{A1, A2, A3, A4, A5, A6}
A4 ?
A1? A6?
Class 1 Class 2 Class 1 Class 2
> Reduced attribute set: {A1, A4, A6}
Data Reduction: Data Compression
 String compression
There are extensive theories and well-tuned algorithms
Typicallylossless
But only limited manipulation is possible without expansion
 Audio/video compression
Typically lossy compression, with progressive refinement
Sometimes small fragments of signal can be reconstructed
without reconstructing the whole
 Time sequence is not audio
Typicallyshort and vary slowly with time
Data Reduction: Numerosity reduction
 Reduce data volume by choosing alternative, smaller forms of data representation
 Type of Numerosity reduction:
 Parametric methods
 Assume the data fits some model, estimate model parameters, store only the
parameters, and discard the data (except possible outliers)
 Example: Regression
 Non-parametric methods
 Do not assume models
 Major families: histograms, clustering, sampling
Data Reduction: Numerosity reduction
 Histograms
 A popular data reduction technique
 Divide data into buckets and store average (sum) for each bucket
 Can be constructedoptimally in one dimension using dynamic programming
 Related to quantization problems.
0
5
10
15
20
25
30
35
40
10000 20000 30000 40000 50000 60000 70000 80000 90000 100000
Data Reduction: Numerosity reduction
 Clustering
Partition data set into clusters, and one
can store cluster representation only
Can be very effective if data is clustered
but not if data is “smeared”
Can have hierarchical clustering and be
stored in multi-dimensional index tree
structures
There are many choices of clustering
definitions and clustering algorithms
Data Reduction: Numerosity reduction
 Sampling
 obtaining a small sample s to represent the whole
data set N
 Simple Random Sample Without Replacement
(SRSWOR)
 The probability of drawing any tuple in D is 1/N
 Simple Random Sample With Replacement (SRSWR)
 Cluster /Stratified sampling
 Approximate the percentage of each class (or
subpopulation of interest) in the overall database
Data Reduction: Numerosity reduction
Raw Data
Data Reduction: Numerosity reduction
Raw Data Cluster/Stratified Sample
Data Reduction: Numerosity reduction
Examples:
Data Reduction: Numerosity reduction
 Hierarchical Reduction
 reduce the data by collecting and replacing low
level concepts (such as numeric values for the
attribute age) by higher level concepts (such as
young, middle-aged, or senior)
 Ex. Suppose that the tree contain 10,000 tuples with key
ranging form 1 to 6 buckets for the key. Each bucket contains
roughly 10,000/6 items. Therefore, each bucket has pointers
to the data keys 986, 3396, 5411, 8392 and 9544, respectively.
 The use of multidimensional index trees as a form of data
reduction relies on an ordering of the attribute values in each
dimension.
Data Reduction: Discretization
 Three types of attributes:
 Nominal — values from an unordered set
 Ordinal — values from an ordered set
 Continuous — real numbers
 Discretization:
 divide the range of a continuous attribute into
intervals
 Some classification algorithms only accept
categorical attributes.
 Reduce data size by discretization
 Prepare for further analysis
Data Reduction: Discretization
 Typical methods: All the methods can be
applied recursively
 Binning
 Histogram analysis
 Clustering analysis
 Entropy-based discretization
 Segmentation by natural partitioning
Data Reduction: Discretization
 Entropy-based discretization
 Example: Coin Flip
 AX = {heads, tails}
 P(heads) = P(tails) = ½
 ½ log2(½) = ½ * - 1
 H(X) = 1
 What about a two-headed coin?
 Conditional Entropy:
2( ) ( )log ( )
Xx A
H X P x P x

 
( | ) ( ) ( | )
Yy A
H X Y P y H X y

 
Data Reduction: Discretization
 Given a set of samples S, if S is partitioned into two
intervals S1 and S2 using boundary T, the entropy
after partitioning is
 The boundary that minimizes the entropy function
over all possible boundaries is selected as a binary
discretization.
 The process is recursively applied to partitions
obtained until some stopping criterion is met, e.g.,
 Experiments show that it may reduce data size and
improve classification accuracy
1 2
1 2
| | | |
( , ) ( ) ( )
| | | |
H S T H H
S S
S S
S S 
( ) ( , )H S H T S  
Data Reduction: Discretization
 Segmentation by natural partitioning
 A simply 3-4-5 rule can be used to segment numeric
data into relatively uniform, “natural” intervals
distinct values at
the most
significant digit
Natural interval
(equi-width)
3, 6, 9 3
7 3 (2-3-2)
2, 4, 8 4
1, 5, 10 5
Data Reduction: Discretization
 Segmentation by natural partitioning
Data Reduction: Concept Hierarchy
 Specification of a partial ordering of attributes
explicitly at the schema level by users or experts
 street<city<state<country
 Specification of a portion of a hierarchy by
explicit data grouping
 {Urbana, Champaign, Chicago}<Illinois
 Specification of a set of attributes.
 System automatically generates partial ordering by
analysis of the number of distinct values
 E.g., street < city <state < country
 Specification of only a partial set of attributes
 E.g., only street < city, not others
Data Reduction: Concept Hierarchy
 Automatic Concept Hierarchy Generation
Some concept hierarchies can be automatically generated based on
the analysis of the number of distinct values per attribute in the
given data set
The attribute with the most distinct values is placed at the lowest
level of the hierarchy
Note: Exception—weekday, month, quarter, year
Data Reduction: Concept Hierarchy
 Automatic Concept Hierarchy Generation
country
province or_ state
city
street
15 distinct values
65 distinct values
3567 distinct values
674,339 distinct values
HW#3
1. What is Data preprocessing?
2. Why Preprocess the Data?
3. What is Major Tasks in Data Preprocessing?
4. What is Data cleaning task?
5. How to Handle Missing Data?
6. What is Normalization Method?
HW#3
7. Attribute income are $50,000 (min) and $ 150,000 (max). A
value of $ 100,000 for income would like to map to the new
range in [3,5]. Please calculate the income is transformed
?
8. Attribute income are $76,000 (mean) and $ 12,500 (std). A
value of $ 95,000 for income would like to map to the new
range. Please calculate the income is transformed ?
9. Attribute A range -650 to 999 normalized to decimal value
of -650 to decimal scaling therefore, j = 2?
10. What is Task in Data Integration?
11. What is Data reduction strategy?
LAB 3
 ให้ Download ไฟล์ bank-data-missvalue.csv มาไว้ที่เครื่อง
 กด Open file และกดดู attribute ของ income ถามว่า มี missing value กี่ % ถ้ามอง
หน้าจอให้หาคาว่า missing value บริเวณด้านขวา
 จากนั้นให้กด choose ด้านบน Filter และกด +filter และกด + unsupervised และ +
attribute และกดเลือก ReplaceMissingValues กด OK และ กด Apply
 กดปุ่ม Save..และบันทึกเป็นชื่อ bank-data-missvalue-R1.csv และกดดูว่าโปรแกรม
แทนค่าที่ขาดหายไปเติมค่าเท่ากับเท่าใด

More Related Content

What's hot

บทที่ 2 ทฤษฎีพื้นฐานของการจัดเก็บและค้นคืนสารสนทศ
บทที่ 2 ทฤษฎีพื้นฐานของการจัดเก็บและค้นคืนสารสนทศบทที่ 2 ทฤษฎีพื้นฐานของการจัดเก็บและค้นคืนสารสนทศ
บทที่ 2 ทฤษฎีพื้นฐานของการจัดเก็บและค้นคืนสารสนทศSrion Janeprapapong
 
พจนานุกรมข้อมูล
พจนานุกรมข้อมูลพจนานุกรมข้อมูล
พจนานุกรมข้อมูลtumetr
 
การเขียนบทที่ 1 บทนำของปริญญานิพนธ์ วิทยานิพนธ์ และงานวิจัย (Introduction)
การเขียนบทที่ 1 บทนำของปริญญานิพนธ์ วิทยานิพนธ์ และงานวิจัย (Introduction)การเขียนบทที่ 1 บทนำของปริญญานิพนธ์ วิทยานิพนธ์ และงานวิจัย (Introduction)
การเขียนบทที่ 1 บทนำของปริญญานิพนธ์ วิทยานิพนธ์ และงานวิจัย (Introduction)Dr.Kridsanapong Lertbumroongchai
 
คู่มือ practical data mining with rapid miner studio7
คู่มือ practical data mining with rapid miner studio7คู่มือ practical data mining with rapid miner studio7
คู่มือ practical data mining with rapid miner studio7Pitchayanida Khumwichai
 
บทที่ 9 รายได้ประชาชาติ การบริโภค การออม และการลงทุน
บทที่ 9 รายได้ประชาชาติ การบริโภค การออม และการลงทุนบทที่ 9 รายได้ประชาชาติ การบริโภค การออม และการลงทุน
บทที่ 9 รายได้ประชาชาติ การบริโภค การออม และการลงทุนOrnkapat Bualom
 
การจัดการข้อมูลด้วยระบบการจัดการฐานข้อมูล
การจัดการข้อมูลด้วยระบบการจัดการฐานข้อมูลการจัดการข้อมูลด้วยระบบการจัดการฐานข้อมูล
การจัดการข้อมูลด้วยระบบการจัดการฐานข้อมูลchanoot29
 
บทที่ 1 บทนำ (การจัดเก็บและค้นคืนสารสนเทศ)
บทที่ 1  บทนำ (การจัดเก็บและค้นคืนสารสนเทศ)บทที่ 1  บทนำ (การจัดเก็บและค้นคืนสารสนเทศ)
บทที่ 1 บทนำ (การจัดเก็บและค้นคืนสารสนเทศ)Srion Janeprapapong
 
สถิติเพื่อการวิจัย
สถิติเพื่อการวิจัยสถิติเพื่อการวิจัย
สถิติเพื่อการวิจัยNU
 
บทที่ 4 การพยากรณ์
บทที่ 4 การพยากรณ์บทที่ 4 การพยากรณ์
บทที่ 4 การพยากรณ์Dr.Krisada [Hua] RMUTT
 
ประชากรและกลุ่มตัวอย่าง
ประชากรและกลุ่มตัวอย่างประชากรและกลุ่มตัวอย่าง
ประชากรและกลุ่มตัวอย่าง0804900158
 
การวิจัยเชิงสำรวจ
การวิจัยเชิงสำรวจการวิจัยเชิงสำรวจ
การวิจัยเชิงสำรวจkhuwawa2513
 

What's hot (20)

บทที่ 2 ทฤษฎีพื้นฐานของการจัดเก็บและค้นคืนสารสนทศ
บทที่ 2 ทฤษฎีพื้นฐานของการจัดเก็บและค้นคืนสารสนทศบทที่ 2 ทฤษฎีพื้นฐานของการจัดเก็บและค้นคืนสารสนทศ
บทที่ 2 ทฤษฎีพื้นฐานของการจัดเก็บและค้นคืนสารสนทศ
 
Practical Data Mining: FP-Growth
Practical Data Mining: FP-GrowthPractical Data Mining: FP-Growth
Practical Data Mining: FP-Growth
 
พจนานุกรมข้อมูล
พจนานุกรมข้อมูลพจนานุกรมข้อมูล
พจนานุกรมข้อมูล
 
Practical Data Mining with RapidMiner Studio 7 : A Basic and Intermediate
Practical Data Mining with RapidMiner Studio 7 : A Basic and IntermediatePractical Data Mining with RapidMiner Studio 7 : A Basic and Intermediate
Practical Data Mining with RapidMiner Studio 7 : A Basic and Intermediate
 
การเขียนบทที่ 1 บทนำของปริญญานิพนธ์ วิทยานิพนธ์ และงานวิจัย (Introduction)
การเขียนบทที่ 1 บทนำของปริญญานิพนธ์ วิทยานิพนธ์ และงานวิจัย (Introduction)การเขียนบทที่ 1 บทนำของปริญญานิพนธ์ วิทยานิพนธ์ และงานวิจัย (Introduction)
การเขียนบทที่ 1 บทนำของปริญญานิพนธ์ วิทยานิพนธ์ และงานวิจัย (Introduction)
 
คู่มือ practical data mining with rapid miner studio7
คู่มือ practical data mining with rapid miner studio7คู่มือ practical data mining with rapid miner studio7
คู่มือ practical data mining with rapid miner studio7
 
Weka dataprepocessing
Weka dataprepocessingWeka dataprepocessing
Weka dataprepocessing
 
บทที่ 9 รายได้ประชาชาติ การบริโภค การออม และการลงทุน
บทที่ 9 รายได้ประชาชาติ การบริโภค การออม และการลงทุนบทที่ 9 รายได้ประชาชาติ การบริโภค การออม และการลงทุน
บทที่ 9 รายได้ประชาชาติ การบริโภค การออม และการลงทุน
 
การจัดการข้อมูลด้วยระบบการจัดการฐานข้อมูล
การจัดการข้อมูลด้วยระบบการจัดการฐานข้อมูลการจัดการข้อมูลด้วยระบบการจัดการฐานข้อมูล
การจัดการข้อมูลด้วยระบบการจัดการฐานข้อมูล
 
บทที่ 1 บทนำ (การจัดเก็บและค้นคืนสารสนเทศ)
บทที่ 1  บทนำ (การจัดเก็บและค้นคืนสารสนเทศ)บทที่ 1  บทนำ (การจัดเก็บและค้นคืนสารสนเทศ)
บทที่ 1 บทนำ (การจัดเก็บและค้นคืนสารสนเทศ)
 
Introduction to Data Analytics with RapidMiner Studio 6 (ภาษาไทย)
Introduction to Data Analytics with RapidMiner Studio 6 (ภาษาไทย)Introduction to Data Analytics with RapidMiner Studio 6 (ภาษาไทย)
Introduction to Data Analytics with RapidMiner Studio 6 (ภาษาไทย)
 
บทที่ 5 การแปลง er diagram ให้เป็น table
บทที่ 5 การแปลง er diagram ให้เป็น tableบทที่ 5 การแปลง er diagram ให้เป็น table
บทที่ 5 การแปลง er diagram ให้เป็น table
 
สถิติเพื่อการวิจัย
สถิติเพื่อการวิจัยสถิติเพื่อการวิจัย
สถิติเพื่อการวิจัย
 
Introduction to Weka: Application approach
Introduction to Weka: Application approachIntroduction to Weka: Application approach
Introduction to Weka: Application approach
 
บทที่ 4 การพยากรณ์
บทที่ 4 การพยากรณ์บทที่ 4 การพยากรณ์
บทที่ 4 การพยากรณ์
 
การหาค่ากลางทั้ง3แบบ
การหาค่ากลางทั้ง3แบบการหาค่ากลางทั้ง3แบบ
การหาค่ากลางทั้ง3แบบ
 
09 anomaly detection
09 anomaly detection09 anomaly detection
09 anomaly detection
 
cluster analysis
cluster analysis cluster analysis
cluster analysis
 
ประชากรและกลุ่มตัวอย่าง
ประชากรและกลุ่มตัวอย่างประชากรและกลุ่มตัวอย่าง
ประชากรและกลุ่มตัวอย่าง
 
การวิจัยเชิงสำรวจ
การวิจัยเชิงสำรวจการวิจัยเชิงสำรวจ
การวิจัยเชิงสำรวจ
 

Similar to 03 data preprocessing

การวิเคราะห์ข้อมูลเชิงปริมาณ
การวิเคราะห์ข้อมูลเชิงปริมาณการวิเคราะห์ข้อมูลเชิงปริมาณ
การวิเคราะห์ข้อมูลเชิงปริมาณtanongsak
 
หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา ปาโจด ม.5
หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา  ปาโจด ม.5หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา  ปาโจด ม.5
หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา ปาโจด ม.5สิรินยา ปาโจด
 
หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา ปาโจด ม.5
หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา  ปาโจด ม.5หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา  ปาโจด ม.5
หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา ปาโจด ม.5สิรินยา ปาโจด
 
หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์ น่านกร ม.5
หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์  น่านกร ม.5หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์  น่านกร ม.5
หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์ น่านกร ม.5palmyZommanow
 
หน่วยที่ 1
หน่วยที่ 1หน่วยที่ 1
หน่วยที่ 1palmyZommanow
 
ความรู้เบื้องต้นเกี่ยวกับฐานข้อมูล
ความรู้เบื้องต้นเกี่ยวกับฐานข้อมูลความรู้เบื้องต้นเกี่ยวกับฐานข้อมูล
ความรู้เบื้องต้นเกี่ยวกับฐานข้อมูลพัน พัน
 
Data processing
Data processingData processing
Data processingchukiat008
 
สถิติ ม.6 เรื่องการวิเคราะห์ข้อมูลเบื้องต้น
สถิติ ม.6 เรื่องการวิเคราะห์ข้อมูลเบื้องต้นสถิติ ม.6 เรื่องการวิเคราะห์ข้อมูลเบื้องต้น
สถิติ ม.6 เรื่องการวิเคราะห์ข้อมูลเบื้องต้นParn Parai
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to DatabaseOpas Kaewtai
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to DatabaseOpas Kaewtai
 
Bacic MySql & script Sql for jhcis
Bacic MySql & script Sql for jhcisBacic MySql & script Sql for jhcis
Bacic MySql & script Sql for jhcisSakarin Habusaya
 
บทที่6
บทที่6 บทที่6
บทที่6 Jaohjaaee
 
บทที่6 1 17_36_ห้อง62
บทที่6 1 17_36_ห้อง62บทที่6 1 17_36_ห้อง62
บทที่6 1 17_36_ห้อง62galswen
 

Similar to 03 data preprocessing (20)

Weka introducing
Weka introducingWeka introducing
Weka introducing
 
Unit3
Unit3Unit3
Unit3
 
Ch5 database system
Ch5 database systemCh5 database system
Ch5 database system
 
Data Mining
Data MiningData Mining
Data Mining
 
Static excel
Static excelStatic excel
Static excel
 
การวิเคราะห์ข้อมูลเชิงปริมาณ
การวิเคราะห์ข้อมูลเชิงปริมาณการวิเคราะห์ข้อมูลเชิงปริมาณ
การวิเคราะห์ข้อมูลเชิงปริมาณ
 
หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา ปาโจด ม.5
หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา  ปาโจด ม.5หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา  ปาโจด ม.5
หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา ปาโจด ม.5
 
หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา ปาโจด ม.5
หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา  ปาโจด ม.5หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา  ปาโจด ม.5
หน่วยที่1 เรื่อง เทคโนโลยีการสื่อสาร นางสาว สิรินยา ปาโจด ม.5
 
Db1
Db1Db1
Db1
 
หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์ น่านกร ม.5
หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์  น่านกร ม.5หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์  น่านกร ม.5
หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์ น่านกร ม.5
 
หน่วยที่ 1
หน่วยที่ 1หน่วยที่ 1
หน่วยที่ 1
 
ความรู้เบื้องต้นเกี่ยวกับฐานข้อมูล
ความรู้เบื้องต้นเกี่ยวกับฐานข้อมูลความรู้เบื้องต้นเกี่ยวกับฐานข้อมูล
ความรู้เบื้องต้นเกี่ยวกับฐานข้อมูล
 
Data processing
Data processingData processing
Data processing
 
Big Data 101 : Chapter 8 Module 1
Big Data 101 : Chapter 8 Module 1Big Data 101 : Chapter 8 Module 1
Big Data 101 : Chapter 8 Module 1
 
สถิติ ม.6 เรื่องการวิเคราะห์ข้อมูลเบื้องต้น
สถิติ ม.6 เรื่องการวิเคราะห์ข้อมูลเบื้องต้นสถิติ ม.6 เรื่องการวิเคราะห์ข้อมูลเบื้องต้น
สถิติ ม.6 เรื่องการวิเคราะห์ข้อมูลเบื้องต้น
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
 
Bacic MySql & script Sql for jhcis
Bacic MySql & script Sql for jhcisBacic MySql & script Sql for jhcis
Bacic MySql & script Sql for jhcis
 
บทที่6
บทที่6 บทที่6
บทที่6
 
บทที่6 1 17_36_ห้อง62
บทที่6 1 17_36_ห้อง62บทที่6 1 17_36_ห้อง62
บทที่6 1 17_36_ห้อง62
 

More from นนทวัฒน์ บุญบา (6)

K means cluster in weka
K means cluster in wekaK means cluster in weka
K means cluster in weka
 
Note
NoteNote
Note
 
Weka association
Weka associationWeka association
Weka association
 
08 clustering
08 clustering08 clustering
08 clustering
 
07 classification 3 neural network
07 classification 3 neural network07 classification 3 neural network
07 classification 3 neural network
 
02 data werehouse
02 data werehouse02 data werehouse
02 data werehouse
 

03 data preprocessing

  • 1. สอนโดย ดร.หทัยรัตน์ เกตุมณีชัยรัตน์ ภาควิชาการจัดการเทคโนโลยีการผลิตและสารสนเทศ บทที่ 3: การเตรียมข้อมูลสาหรับการทาเหมือง (Data Preprocessing) 336331 การทาเหมืองข้อมูล (Data Ming)
  • 3. ทาไมต้องมีการเตรียมข้อมูล  เนื่องจากข้อมูลในความเป็นจริงมีความสกปรก คือ - ข้อมูลไม่สมบูรณ์ (Incomplete data) เช่น ค่าของคุณลักษณะขาดหาย (Missing value) ขาดคุณลักษณะที่น่าสนใจ หรือ ทา N/A ไว้ขาดรายละเอียดของข้อมูล - ข้อมูลรบกวน (Noisy data) เช่น ข้อมูลมีค่าผิดพลาด (Error) หรือมีค่าผิดปกติ (Outliers) - ข้อมูลไม่สอดคล้อง (Inconsistent data) เช่น ข้อมูลเดียวกัน แต่ตั้งชื่อต่างกัน หรือ ใช้ค่าแทนข้อมูลที่ต่างกัน
  • 4. ทาไมต้องมีการเตรียมข้อมูล (ต่อ) Cust_ID Name Income Age Birthday 001 A n/a 200 12/10/79 002 - $2000 25 27 Dec 81 003 C -10000 27 18 Feb 20
  • 5. เทคนิคการเตรียมข้อมูล 1) Data Cleaning คือ การทาความสะอาดข้อมูล จัดการข้อมูลรบกวน 2) Data Integration คือ การผสานข้อมูล 3) Data Transformationคือ การแปลงข้อมูล 4) Data Reduction คือ การลดรูปข้อมูล
  • 6. Data cleaning Data integration Data transformation Data reduction -2, 32, 100,59, 48 -0.02, 0.32, 1.00, 0.59, 0.48 transaction transaction attribute attribute A1 A2 A3 ………… A126 A1 A2 …… A115 T1 T2 … T2000 เทคนิคการเตรียมข้อมูล
  • 7. 1) Data Cleaning (การทาความสะอาดข้อมูล)  เนื่องจากข้อมูลจริงไม่สมบูรณ์อาจจะมีค่าที่ขาดหายไป (Missing Value) ดังนั้นควรปรับข้อมูลให้มีความ smooth มากขึ้น
  • 8. การจัดการข้อมูลค่าที่ขาดหาย (Missing value)  ถ้านักศึกษา เป็นผู้จัดการของบริษัทแห่งหนึ่ง และต้องการวิเคราะห์ ข้อมูล “การขายสินค้า และข้อมูลของลูกค้า”  นักศึกษา พบว่า มีหลายๆรายการ ไม่มีการบันทึกค่าในแต่ละฟิลด์ หรือ แอททริบิวต์เช่น ไม่มีการบันทึกข้อมูลรายได้ของลูกค้า  คาถาม ??? นักศึกษาจะมีวิธีการจัดการค่าที่ขาดหายเหล่านี้ได้อย่างไร
  • 9. การจัดการค่าข้อมูลที่ขาดหาย (Missing value) 1. Ignore the tuple 2. Fill in the missing value manually 3. Use a global constant to fill in the missing value 4. Use the attribute mean to fill in the missing value 5. Use the attribute mean for all samples belonging to the same class as the given tuple 6. Use the most propable value to fill in the missing value
  • 10. Ignore the tuple  ตัดทิ้งรายการที่มีข้อมูลสูญหาย นิยมใช้กับการทาเหมืองข้อมูลแบบจาแนกประเภท (Classification) ในกรณีที่ค่าคุณลักษณะขาดหายไปเป็นจานวนมาก Fill in the missing value manually  เติมค่าที่ขาดหายด้วยมือ วิธีนี้ไม่เหมาะสมกรณีที่ชุดข้อมูลมีขนาดใหญ่ และมีข้อมูล ขาดหายจานวนมาก Use a global constant to fill in the missing value  เติมค่าคุณลักษณะของข้อมูลที่ขาดหายทุกค่า ด้วยค่าคงที่ค่าหนึ่ง เช่น ไม่รู้ค่า หรือ unknown
  • 11. Use the attribute mean to fill in the missing value  ใช้ค่าเฉลี่ยของคุณลักษณะ เติมค่าข้อมูลที่ขาดหาย เช่น ถ้าทราบว่าลูกค้าที่รายได้ เฉลี่ยเดือนละ 12000 บาท จะใช้ค่านี้แทนค่ารายได้ของลูกค้าที่ขาดหาย Use the attribute mean for all samples belonging to the same class as the given tuple  ใช้ค่าเฉลี่ยคุณลักษณะของตัวอย่างที่จัดอยู่ในประเภทเดียวกัน เพื่อเติมค่าข้อมูลที่ ขาดหาย เช่น เติมค่ารายได้ของลูกค้าที่ขาดหาย ด้วยค่าเฉลี่ยของลูกค้าที่อยู่ในกลุ่ม อาชีพ เดียวกัน
  • 12. Use the most propable value to fill in the missing value  ใช้ค่าที่เป็นไปได้มากที่สุด เติมแทนค่าข้อมูลที่ขาดหาย เช่น ค่าที่ได้จาก สมการความถดถอย (Regression) ค่าที่ได้จากการอนุมาน โดยใช้สูตรของเบย์ (Bayesian formula) หรือต้นไม้ตัดสินใจ (Decision tree) เช่น ใช้ข้อมูลลูกค้า มาสร้างต้นไม้ตัดสินใจ เพื่อทานายรายได้ของลูกค้า แล้วนาไป แทนค่าที่ขาดหาย  วิธีนี้นิยมกันแพร่หลาย เนื่องจากทานายค่าข้อมูลที่ขาดหาย โดยพิจารณาจาก ค่าของข้อมูลชุดปัจจุบัน และความสัมพันธ์ระหว่างคุณลักษณะในชุดข้อมูล
  • 13. ข้อมูลรบกวน (Noisy data)  ข้อมูลรบกวน เป็นข้อมูลที่มีความผิดพลาดแบบสุ่ม หรือคลาดเคลื่อนจากการ วัด สาเหตุของความผิดพลาด อาจสืบเนื่องมาจาก - อุปกรณ์เก็บรวบรวมข้อมูลทาหน้าที่ผิดพลาด - ปัญหาการบันทึกหรือป้อนค่าข้อมูล - ปัญหาการส่งข้อมูล (Data Transmission) ผิดพลาด - ข้อจากัดทางเทคโนโลยี เช่น ข้อจากัดของขนาดบัฟเฟอร์
  • 15. Binning Methods  การปรับข้อมูลให้เรียบด้วยวิธีการแบบ binning ทาโดย เรียงลาดับข้อมูล แล้วใช้หลักการตัดแบ่ง (Partition) แบ่งข้อมูลออกเป็นส่วนแต่ ละส่วนเรียกว่า bin แล้วทาการปรับเรียบข้อมูลในแต่ละ bin โดยใช้การปรับ เรียบข้อมูลแบบท้องถิ่น (Local Smoothing) โดยใช้ค่าที่ได้จากเพื่อนบ้าน ใกล้เคียง (Neighborhood) ใน bin หรือ bucket เดียวกันเช่น ค่าเฉลี่ยของ bin (Bin Means) ค่ากลางของ bin (Bin Medians) หรือค่าขอบของ bin (Bin Boundaries)
  • 16. Binning Methods  Binning Method  Example: Sorted data for price (in dollars):4, 8, 15, 21, 21, 24, 25, 28, 34 (N = 3)  Partition into (equi-depth)bins: Bin 1: 4, 8, 15 Bin 2: 21, 21, 24 Bin 3: 25, 28, 34  Smoothing by bin means: Bin 1: 9, 9, 9 Bin 2: 22, 22, 22 Bin 3: 29, 29, 29  Smoothing by bin boundaries: Bin 1: 4, 4, 15 Bin 2: 21, 21, 24 Bin 3: 25, 25, 34
  • 17. Regression Smooth by fitting the data into regression functions Linear Regression Y =α +βX Multiple Linear Regression Y =b0 +b1 X1 +b2 X2 +...+bmXm
  • 18. Regression  วิธีความถดถอย ใช้การทานายค่าของตัวแปรจากสมการความถดถอยที่หาได้ ด้วย วิธีความผิดพลาดน้อยที่สุด (Least-square error) จากชุดตัวอย่างตัวแปร x y = x+1 y’ = x+1 X1 Y1 Y1’
  • 19. Clustering  การวิเคราะห์การจัดกลุ่ม จะช่วยตรวจหา และกาจัดค่าที่ผิดปกติ เช่น ค่าที่สูงหรือต่ากว่า ปกติ จะไม่สามารถจัดอยู่ในกลุ่มใดๆ และตกอยู่นอกกลุ่ม OutlierCluster
  • 20. 2) Data Transformation (การแปลงข้อมูล)  การแปลงข้อมูลที่พบบ่อยในการทาเหมืองข้อมูลคือ การทานอร์มอลไลซ์ (Normalization) โดยแปลงค่าข้อมูลให้อยู่ในช่วงสั้นๆ ที่อัลกอริทึมการทาเหมือง ข้อมูลสามารถนาไปใช้ประมวลผลได้  วิธีการทานอร์มอลไลซ์ข้อมูลได้แก่  min-max normalization  z-score normalization  normalization by decimal scaling  Sigmoidal
  • 21. Min-Max Nornalization  การแปลงข้อมูลให้อยู่ในช่วงใหม่ [new_minA, new_maxA] ตัวอย่าง เช่น ข้อมูลคอลัมน์รายได้ (income) มีค่าต่าสุด 12,000 บาท (min) และมีค่ามาก ที่สุด 98,000 บาท (max) ซึ่งข้อมูลที่ต้องการแปลงคือ 73,600 บาท ต้องการ แปลงให้ข้อมูลนี้อยู่ในช่วงใหม่ คือ [0,1] เพราะฉะนั้น 73,600 บาท จะมีค่า ใหม่เป็นเท่าใด AAA AA A minnewminnewmaxnew minmax minv v _)__('     716.00)00.1( 000,12000,98 000,12600,73   
  • 22. Z-Score  เป็นการปรับการกระจายของข้อมูลให้มีค่าเท่ากับ 0 และค่าเบี่ยงเบนมาตรฐานเท่ากับ 1  หาได้จากสูตร ตัวอย่างเช่น ข้อมูลคอลัมภ์รายได้ (income) มีค่าเฉลี่ย 54,000 บาท (mean) และมีค่าเบี่ยงเบน มาตรฐาน 16,000 บาท (stand_dev) ต้องการแปลงค่ารายได้73,600 บาท เป็นค่าใหม่ ตามวิธี Z-Score A A devstand_ meanv v  ' 225.1 000,16 000,54600,73  
  • 23. Decimal scaling  เป็นการแปลงค่าข้อมูลเดิมให้เป็นเลขทศนิยม ตาแหน่งทศนิยมกาหนดโดยค่า สัมบูรณ์ที่มีค่ามากที่สุด  ตัวอย่างเช่น ค่าที่เป็นไปได้ของคุณลักษณะ A อยู่ในช่วงระหว่าง -986 ถึง 917 จะได้ว่าค่า สัมบูรณ์ที่มากที่สุดคือ |-986| = 986 ดังนั้นเราจะหารข้อมูลแต่ละค่าด้วย 1000 โดย ที่ j=3 ผลลัพธ์คือค่า -986 จะถูกแปลงเป็น -0.986 j v v 10 ' 986.0 10 986 3  
  • 24. Sigmoidal  Normalize input into [-1, 1]        e e y 1 1 ' std meany   -1 1 x y
  • 25. 3) การผสานข้อมูล (Data Integration)  เป็นการรวบรวมข้อมูลจากแหล่งที่เก็บต่างๆ มาไว้ที่เดียวกัน การผสาน ข้อมูลจากแหล่งต่างๆ เพื่อช่วย 1. ลดหรือหลีกเลี่ยงความซ้าซ้อนของข้อมูล (Data Redundancies) ซึ่งจะ นาไปสู่ปัญหาความไม่สอดคล้องกันของข้อมูล (Data Inconsistencies) 2. เพิ่มความเร็วและคุณภาพในการทาเหมืองข้อมูล
  • 26. งานที่ต้องทาในการผสานข้อมูล  การผสานโครงสร้างการเก็บข้อมูล (Schema Integration) โดยใช้ Metadata ช่วยใน การบ่งชี้ entities ในแหล่งเก็บข้อมูลต่างๆ เช่น คุณลักษณะ Cusid ในแหล่งข้อมูล A เป็นคุณลักษณะเดียวกับ CustNumber ในแหล่งข้อมูล B หรือไม่  ตรวจหาและแก้ไข ค่าข้อมูลที่ขัดแย้ง เช่น ค่าคุณลักษณะเดียวกัน แต่ใช้หน่วยวัด ต่างๆ กัน ในแต่ละแหล่งข้อมูล  การกาจัดค่าข้อมูลซ้าซ้อน เช่น ค่าคุณลักษณะในแหล่งข้อมูลหนึ่ง อาจเป็นค่าที่ได้ จากการคานวณในอีกแหล่งข้อมูลหนึ่ง อาทิ ค่ารายได้รายปี “Data Warehousing”
  • 27. Data Integration  Data integration:  combines data from multiple sources into a coherent store  Schema integration  integrate metadata from different sources  Entity identification problem: identify real world entities from multiple data sources, e.g., A.cust-id  B.cust-#  Detecting and resolving data value conflicts  for the same real world entity, attribute values from different sources are different  possible reasons: different representations, different scales, e.g., metric vs. British units
  • 28. Data Integration (Cont.)  Redundant data occur often when integration of multiple databases  The same attribute may have different names in different databases  One attribute may be a “derived” attribute in another table, e.g., annual revenue  Redundant data may be able to be detected by correlation analysis  Careful integration of the data from multiple sources may help reduce/avoid redundancies and inconsistencies and improve mining speed and quality
  • 29. Data Integration : Correlation analysis  The correlation between attribute A and B can be measured by  If rA,B greater than 0, then A and B are positively correlated, meaning that the value of A increase as the values of B increase  The mean of A is  The standard deviation of A is BA BA n BBAA r )1( ))(( ,     n A A  1 )( 2     n AA A
  • 30. 4) การลดรูปข้อมูล (Data Reduction) • คลังข้อมูลเก็บข้อมูลจานวนมาก ขนาดเป็น เทราไบต์ ดังนั้นการ วิเคราะห์ หรือการทาเหมืองข้อมูลที่ซับซ้อน ต้องใช้เวลานานในการ ประมวลผลข้อมูลปริมาณมากๆ • การลดรูป เป็นการกระทาเพื่อแทนข้อมูล ด้วยรูปแบบกะทัดรัด กินเนื้อ ที่น้อยกว่า แต่สามารถนาไปใช้วิเคราะห์ แล้วเกิดผลลัพธ์ที่เท่ากันหรือ เทียบเท่ากัน กับการวิเคราะห์จากข้อมูลทั้งหมด
  • 31. 4) การลดรูปข้อมูล (Data Reduction) (cont.)  Data reduction strategies Data cube aggregation Dimensionality reduction — remove unimportant attributes Data Compression Numerosity reduction — fit data into models Discretization and concept hierarchy generation
  • 32. Data Reduction: Data cube aggregation  The data can be aggregated that the resulting data summarize  Ex. The data consist of the ALLElectronics sales per quarter, for the year 2002 to 2004.  aggregated in data summarize the total sales per year instead of per quarter, without loss of information necessary of the analysis task
  • 33. Data Reduction: Data cube aggregation  Concept hierarchies may exist for each attribute, allowing the analysis of data at multiple levels of abstraction Data cube Lattice of cuboids
  • 34. Data Reduction: Dimensionality reduction  Feature selection (i.e., attribute subset selection):  Select a minimum set of features such that the probability distribution of different classes given the values for those features is as close as possible to the original distribution given the values of all features  reduce # of patterns in the patterns, easier to understand  Heuristic methods:  step-wise forward selection  step-wise backward elimination  combining forward selection and backward elimination
  • 35. Data Reduction: Dimensionality reduction  Step-wise forward selection Start with an empty of attributes called the reduced set The best of the original attributes is determined and added to the reduced set At each subsequent iteration, the best of the remaining original attributes is added to the reduced set Initial attribute set: {A1, A2, A3, A4, A5, A6} Initial reduced set: {} {A1} {A1, A4} Reduced attribute set: {A1, A4, A6}
  • 36. Data Reduction: Dimensionality reduction  Step-wise backward elimination  Start with the full set of attributes  At each step, removes the worst attribute remaining in the set Initial attribute set: {A1, A2, A3, A4, A5, A6} Initial reduced set: {A1, A3, A4, A5, A6} {A1, A4, A5, A6} Reduced attribute set: {A1, A4, A6}
  • 37. Data Reduction: Dimensionality reduction  Combining forward selection and backward elimination At each step, selects the best attribute and removes the worst from among the remaining attributes
  • 38. Data Reduction: Dimensionality reduction  Decision-tree induction Initial attribute set: {A1, A2, A3, A4, A5, A6} A4 ? A1? A6? Class 1 Class 2 Class 1 Class 2 > Reduced attribute set: {A1, A4, A6}
  • 39. Data Reduction: Data Compression  String compression There are extensive theories and well-tuned algorithms Typicallylossless But only limited manipulation is possible without expansion  Audio/video compression Typically lossy compression, with progressive refinement Sometimes small fragments of signal can be reconstructed without reconstructing the whole  Time sequence is not audio Typicallyshort and vary slowly with time
  • 40. Data Reduction: Numerosity reduction  Reduce data volume by choosing alternative, smaller forms of data representation  Type of Numerosity reduction:  Parametric methods  Assume the data fits some model, estimate model parameters, store only the parameters, and discard the data (except possible outliers)  Example: Regression  Non-parametric methods  Do not assume models  Major families: histograms, clustering, sampling
  • 41. Data Reduction: Numerosity reduction  Histograms  A popular data reduction technique  Divide data into buckets and store average (sum) for each bucket  Can be constructedoptimally in one dimension using dynamic programming  Related to quantization problems. 0 5 10 15 20 25 30 35 40 10000 20000 30000 40000 50000 60000 70000 80000 90000 100000
  • 42. Data Reduction: Numerosity reduction  Clustering Partition data set into clusters, and one can store cluster representation only Can be very effective if data is clustered but not if data is “smeared” Can have hierarchical clustering and be stored in multi-dimensional index tree structures There are many choices of clustering definitions and clustering algorithms
  • 43. Data Reduction: Numerosity reduction  Sampling  obtaining a small sample s to represent the whole data set N  Simple Random Sample Without Replacement (SRSWOR)  The probability of drawing any tuple in D is 1/N  Simple Random Sample With Replacement (SRSWR)  Cluster /Stratified sampling  Approximate the percentage of each class (or subpopulation of interest) in the overall database
  • 44. Data Reduction: Numerosity reduction Raw Data
  • 45. Data Reduction: Numerosity reduction Raw Data Cluster/Stratified Sample
  • 46. Data Reduction: Numerosity reduction Examples:
  • 47. Data Reduction: Numerosity reduction  Hierarchical Reduction  reduce the data by collecting and replacing low level concepts (such as numeric values for the attribute age) by higher level concepts (such as young, middle-aged, or senior)  Ex. Suppose that the tree contain 10,000 tuples with key ranging form 1 to 6 buckets for the key. Each bucket contains roughly 10,000/6 items. Therefore, each bucket has pointers to the data keys 986, 3396, 5411, 8392 and 9544, respectively.  The use of multidimensional index trees as a form of data reduction relies on an ordering of the attribute values in each dimension.
  • 48. Data Reduction: Discretization  Three types of attributes:  Nominal — values from an unordered set  Ordinal — values from an ordered set  Continuous — real numbers  Discretization:  divide the range of a continuous attribute into intervals  Some classification algorithms only accept categorical attributes.  Reduce data size by discretization  Prepare for further analysis
  • 49. Data Reduction: Discretization  Typical methods: All the methods can be applied recursively  Binning  Histogram analysis  Clustering analysis  Entropy-based discretization  Segmentation by natural partitioning
  • 50. Data Reduction: Discretization  Entropy-based discretization  Example: Coin Flip  AX = {heads, tails}  P(heads) = P(tails) = ½  ½ log2(½) = ½ * - 1  H(X) = 1  What about a two-headed coin?  Conditional Entropy: 2( ) ( )log ( ) Xx A H X P x P x    ( | ) ( ) ( | ) Yy A H X Y P y H X y   
  • 51. Data Reduction: Discretization  Given a set of samples S, if S is partitioned into two intervals S1 and S2 using boundary T, the entropy after partitioning is  The boundary that minimizes the entropy function over all possible boundaries is selected as a binary discretization.  The process is recursively applied to partitions obtained until some stopping criterion is met, e.g.,  Experiments show that it may reduce data size and improve classification accuracy 1 2 1 2 | | | | ( , ) ( ) ( ) | | | | H S T H H S S S S S S  ( ) ( , )H S H T S  
  • 52. Data Reduction: Discretization  Segmentation by natural partitioning  A simply 3-4-5 rule can be used to segment numeric data into relatively uniform, “natural” intervals distinct values at the most significant digit Natural interval (equi-width) 3, 6, 9 3 7 3 (2-3-2) 2, 4, 8 4 1, 5, 10 5
  • 53. Data Reduction: Discretization  Segmentation by natural partitioning
  • 54. Data Reduction: Concept Hierarchy  Specification of a partial ordering of attributes explicitly at the schema level by users or experts  street<city<state<country  Specification of a portion of a hierarchy by explicit data grouping  {Urbana, Champaign, Chicago}<Illinois  Specification of a set of attributes.  System automatically generates partial ordering by analysis of the number of distinct values  E.g., street < city <state < country  Specification of only a partial set of attributes  E.g., only street < city, not others
  • 55. Data Reduction: Concept Hierarchy  Automatic Concept Hierarchy Generation Some concept hierarchies can be automatically generated based on the analysis of the number of distinct values per attribute in the given data set The attribute with the most distinct values is placed at the lowest level of the hierarchy Note: Exception—weekday, month, quarter, year
  • 56. Data Reduction: Concept Hierarchy  Automatic Concept Hierarchy Generation country province or_ state city street 15 distinct values 65 distinct values 3567 distinct values 674,339 distinct values
  • 57.
  • 58. HW#3 1. What is Data preprocessing? 2. Why Preprocess the Data? 3. What is Major Tasks in Data Preprocessing? 4. What is Data cleaning task? 5. How to Handle Missing Data? 6. What is Normalization Method?
  • 59. HW#3 7. Attribute income are $50,000 (min) and $ 150,000 (max). A value of $ 100,000 for income would like to map to the new range in [3,5]. Please calculate the income is transformed ? 8. Attribute income are $76,000 (mean) and $ 12,500 (std). A value of $ 95,000 for income would like to map to the new range. Please calculate the income is transformed ? 9. Attribute A range -650 to 999 normalized to decimal value of -650 to decimal scaling therefore, j = 2? 10. What is Task in Data Integration? 11. What is Data reduction strategy?
  • 60. LAB 3  ให้ Download ไฟล์ bank-data-missvalue.csv มาไว้ที่เครื่อง  กด Open file และกดดู attribute ของ income ถามว่า มี missing value กี่ % ถ้ามอง หน้าจอให้หาคาว่า missing value บริเวณด้านขวา  จากนั้นให้กด choose ด้านบน Filter และกด +filter และกด + unsupervised และ + attribute และกดเลือก ReplaceMissingValues กด OK และ กด Apply  กดปุ่ม Save..และบันทึกเป็นชื่อ bank-data-missvalue-R1.csv และกดดูว่าโปรแกรม แทนค่าที่ขาดหายไปเติมค่าเท่ากับเท่าใด