2. http://dataminingtrend.com http://facebook.com/datacube.th
Structured & Unstructured data
• ข้อมูลแบ่งเป็นแบบมีโครงสร้าง (structure) และไม่มีโครงสร้าง
(unstructure)
• ข้อมูลแบบมีโครงสร้าง เช่น ข้อมูลที่เก็บในรูปแบบตาราง
• ข้อมูลแบบไม่มีโครงสร้าง เช่น ข้อมูลที่เป็นข้อความ ข้อมูลที่เป็นรูปภาพ
2
ID outlook humidity windy play
1 sunny high FALSE no
2 sunny high TRUE no
3 overcast normal FALSE yes
binominalnumeric nominal
7. http://dataminingtrend.com http://facebook.com/datacube.th
Text representation
• ในการวิเคราะห์ข้อมูลข้อความต้องทำการแปลงข้อมูลให้อยู่
ในรูปแบบที่มีโครงสร้าง
7
Laying on the sand sun hitting me, this feels good :)
Smells so good I have two :)
i watched 3 movies today, reminded me of my child hood! Finding Nemo
was always my favourite, but that was when i was MUCH younger! :)
I think NYC would be amazing, I really wanna go there :)
he never care,he never look at me..:(
i am so tired!! and my feet hurt :(
positive
negative
8. http://dataminingtrend.com http://facebook.com/datacube.th
Text representation: Bag of Words
• จำนวนความถี่ของคำที่เกิดขึ้นในข้อความ
8
ID Tweet Sentiment
1
Laying on the sand sun hitting
me, this feels good. positive
2 Smells so good I have two. positive
3
i watched 3 movies today,
reminded me of my child hood!
Finding Nemo was always my
favourite, but that was when i
was MUCH younger!
positive
4
I think NYC would be amazing,
I really wanna go there.
positive
5
he never care,he never look at
me.
negative
6
i am so tired!! and my feet
hurt.
negative
Term Count
Finding 1
9. http://dataminingtrend.com http://facebook.com/datacube.th
Text representation: Bag of Words
• จำนวนความถี่ของคำที่เกิดขึ้นในข้อความ
9
ID Tweet Sentiment
1
Laying on the sand sun hitting
me, this feels good. positive
2 Smells so good I have two. positive
3
i watched 3 movies today,
reminded me of my child hood!
Finding Nemo was always my
favourite, but that was when i
was MUCH younger!
positive
4
I think NYC would be amazing,
I really wanna go there.
positive
5
he never care,he never look at
me.
negative
6
i am so tired!! and my feet
hurt.
negative
Term Count
Finding 1
I 3
10. http://dataminingtrend.com http://facebook.com/datacube.th
Text representation: Bag of Words
• จำนวนความถี่ของคำที่เกิดขึ้นในข้อความ
10
ID Tweet Sentiment
1
Laying on the sand sun hitting
me, this feels good. positive
2 Smells so good I have two. positive
3
i watched 3 movies today,
reminded me of my child hood!
Finding Nemo was always my
favourite, but that was when i
was MUCH younger!
positive
4
I think NYC would be amazing,
I really wanna go there.
positive
5
he never care,he never look at
me.
negative
6
i am so tired!! and my feet
hurt.
negative
Term Count
Finding 1
I 3
Laying 1
MUCH 1
NYC 1
Nemo 1
Smells 1
always 1
am 1
amazing 1
and 1
at 1
be 1
but 1
care 1
Term Count
child 1
favourite 1
feels 1
feet 1
go 1
good 2
have 1
he 2
hitting 1
hood 1
hurt 1
i 3
look 1
me 1
… 1
bag of words
11. http://dataminingtrend.com http://facebook.com/datacube.th
Text representation: Stemming
• แปลงคำให้เป็นรากศัพท์ (root) เช่น finding แปลงเป็น find
11
Term Count
child 1
favourite 3
feels 1
feet 1
go 1
good 2
have 1
he 2
hitting 1
hood 1
hurt 1
i 3
look 1
me 1
… 1
Term Count
child 1
favourit 1
feel 1
feet 1
go 1
good 2
have 1
he 2
hit 1
hood 1
hurt 1
i 3
look 1
me 1
… 1
Term Count
Finding 1
I 3
Laying 1
MUCH 1
NYC 1
Nemo 1
Smells 1
always 1
am 1
amazing 1
and 1
at 1
be 1
but 1
care 1
Term Count
find 1
i 6
lai 1
much 1
nyc 1
nemo 1
smell 1
alwai 1
am 1
amaz 1
and 1
at 1
be 1
but 1
care 1
bag of words bag of words
12. http://dataminingtrend.com http://facebook.com/datacube.th
Text representation: Remove stopwords
• ตัดคำที่เป็น stop word ทิ้ง
12
Term Count
find 1
i 6
lai 1
much 1
nyc 1
nemo 1
smell 1
alwai 1
am 1
amaz 1
and 1
at 1
be 1
but 1
care 1
Term Count
child 1
favourit 1
feel 1
feet 1
go 1
good 2
have 1
he 2
hit 1
hood 1
hurt 1
look 1
me 1
… 1
Term Count
find 1
i 6
lai 1
nyc 1
nemo 1
smell 1
alwai 1
amaz 1
child 1
favorit 1
feel 1
feet 1
go 1
good 2
hit 1
Term Count
hood 1
hurt 1
look 1
care 1
movi 1
reali 1
remind 1
sand 1
sun 1
thi 1
think 1
tire 1
todai 1
wa 3
watch 1
remove stopwords
13. http://dataminingtrend.com http://facebook.com/datacube.th
Convert text to structured data
• Binary occurrence ถ้ามีคำที่เกิดขึ้นในแต่ละเอกสารจะให้ค่าเป็น 1
ถ้าไม่เกิดขึ้นจะเป็น 0
13
ID find I lai nyc nemo smell alwai … Sentiment
1 0 0 1 0 0 0 0 … positive
2 0 1 0 0 0 1 0 … positive
3 1 1 0 0 1 0 1 … positive
4 0 1 0 1 0 0 0 … positive
5 0 0 0 0 0 0 0 … negative
6 0 1 0 0 0 0 0 … negative
attribute label
ID Tweet Sentiment
1
Laying on the sand sun hitting
me, this feels good. positive
2 Smells so good I have two. positive
3
i watched 3 movies today,
reminded me of my child hood!
Finding Nemo was always my
favourite, but that was when i
was MUCH younger!
positive
4
I think NYC would be amazing,
I really wanna go there.
positive
5
he never care,he never look at
me.
negative
6
i am so tired!! and my feet
hurt.
negative
training data แสดงคำที่เกิดขึ้นในเอกสารต่างๆ
14. http://dataminingtrend.com http://facebook.com/datacube.th
Convert text to structured data
• Term Frequency คือจำนวนครั้งที่คำนั้นเกิดขึ้นในเอกสารทั้งหมด
• TF = จำนวนคำที่พิจารณาในเอกสาร/จำนวนคำในเอกสาร
14
ID find I lai nyc nemo … Sentiment
1 0 0 0.17 0 0 … positive
2 0 0.17 0 0 0 … positive
3 0.17 0.33 0 0 0.17 … positive
4 0 0.33 0 0.17 0 … positive
5 0 0 0 0 0 … negative
6 0 0.17 0 0 0 … negative
attribute label
ID Tweet Sentiment
1
Laying on the sand sun hitting
me, this feels good. positive
2 Smells so good I have two. positive
3
i watched 3 movies today,
reminded me of my child hood!
Finding Nemo was always my
favourite, but that was when i
was MUCH younger!
positive
4
I think NYC would be amazing,
I really wanna go there.
positive
5
he never care,he never look at
me.
negative
6
i am so tired!! and my feet
hurt.
negative
training data แสดงคำที่เกิดขึ้นในเอกสารต่างๆ
15. http://dataminingtrend.com http://facebook.com/datacube.th
Convert text to structured data
• TF-IDF คือจำนวนครั้งของคำที่เกิดขึ้นคูณกับจำนวนคำที่เกิดเฉพาะ
เอกสารในคลาส
15
ID find I lai nyc nemo … Sentiment
1 0 0 0.40 0 0 … positive
2 0 0.19 0 0 0 … positive
3 0.22 0.10 0 0 0.22 … positive
4 0 0.20 0 0.17 0 … positive
5 0 0 0 0 0 … negative
6 0 0.13 0 0 0 … negative
attribute label
ID Tweet Sentiment
1
Laying on the sand sun hitting
me, this feels good. positive
2 Smells so good I have two. positive
3
i watched 3 movies today,
reminded me of my child hood!
Finding Nemo was always my
favourite, but that was when i
was MUCH younger!
positive
4
I think NYC would be amazing,
I really wanna go there.
positive
5
he never care,he never look at
me.
negative
6
i am so tired!! and my feet
hurt.
negative
training data แสดงคำที่เกิดขึ้นในเอกสารต่างๆ
16. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
16
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
17. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
17
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
18. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
18
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
19. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
19
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
20. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
20
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
21. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
21
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
22. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
22
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
23. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
23
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
24. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
24
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
25. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
25
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
26. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
26
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
27. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
27
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
28. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
28
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
29. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
29
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two
30. http://dataminingtrend.com http://facebook.com/datacube.th
N-Gram sequences
• จำนวนคำที่พิจารณาต่อกัน N ตัว
• unigram พิจารณาการเกิดขึ้นของแต่ละคำ
• bi-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 2 คำ เช่น so good
• tri-gram พิจารณาการเกิดขึ้นของคำที่ติดกัน 3 คำ เช่น smells so good
30
Smells so good I have two.
unigram bi-gram tri-gram
smells smells so smells so good
so so good so good I
good good I good I have
I I have I have two
have have two
two