SlideShare a Scribd company logo
1 of 20
K-means
Clustering
K-means Clustering
◍K-means การจัดกลุ่มแบบ K-means หรือเรียกอีกอย่างหนึ่งว่า การวิเคราะห์กลุ่มแบบไม่เป็น ขั้นตอน
(Nonhierarchical Cluster Analysis) หรือ การแบ่งส่วน (Partioning)
◍K-means เป็นอัลกอริทึมเทคนิคการเรียนรู้โดยไม่มีผู้สอนที่ง่ายที่สุด เพราะเป็น การแก้ปัญหาการจัดกลุ่มที่รู้จัก
กันทั่วไป โดยอัลกอริทึม K-Means จะตัดแบ่ง (Partition) วัตถุออกเป็น K กลุ่ม และแทนค่าแต่ละ
กลุ่มด้วยค่าเฉลี่ยของกลุ่ม ซึ่งใช้เป็นจุดศูนย์กลาง (centroid) ของกลุ่มในการวัดระยะห่างของข้อมูลในกลุ่ม
เดียวกัน
“
วิธีการ
1.กำหนดหรือสุ่มค่ำเริ่มต ้น จำนวน k ค่ำ(กลุ่ม) และกำหนดจุด ศูนย์กลำงเริ่มต ้น k จุด
เรียกว่ำ cluster centers หรือ(centroid)
2. นำวัตถุทั้งหมดจัดเข ้ำกลุ่ม โดยทำกำรหำค่ำระยะห่ำงระหว่ำงข ้อมูล กับจุดศูนย์กลำง
หำกข ้อมูลไหนใกล ้ค่ำจุดศูนย์กลำงตัวไหนที่สุดอยู่ กลุ่มนั้น
3. หำค่ำเฉลี่ย แต่ละกลุ่ม ให ้เป็นค่ำจุดศูนย์กลำงใหม่
4. ทำซ้ำข ้อ 2 จนกระทั่งค่ำเฉลี่ยหรือจุดศูนย์กลำงในแต่ละกลุ่มจะไม่ เปลี่ยนแปลงจึง
หยุดทำ
วิธีการทา K-Mean Clustering
ตัวอย่างการทา K-Mean Clustering
ตัวอย่างการทา K-Mean Clustering
◍สุ่มค่าเริ่มต้น จานวน k ค่า เรียกว่า cluster centers (centroid)
◍สมมติ k =3 แสดงว่า c1,c2และc3 เป็น centroidที่เราสุ่มขึ้นมาc1(2, 10),c2(5,8)
และ c3(1,2)
ตัวอย่างการทา K-Mean Clustering
ขั้นตอนที่ 1
◍หาความห่างกันระหว่างข้อมูล 2 ข้อมูล คือ หาความห่างจากข้อมูลA=(x1,y1)และcentroid =(x2,y2)
โดยใช้สูตรEuclidean ดังนี้
◍และนาไปใส่ในตาราง
หรือ
ตัวอย่างการทา K-Mean Clustering
ขั้นตอนที่ 2
หาระยะห่างระหว่างข้อมูลกับจุดศูนย์กลาง (ตัวอย่างบางชุดข้อมูล)
ตัวอย่างการทา K-Mean Clustering
เมื่อใส่ข้อมูลในตารางจะได้การจัดกลุ่มข้อมูลดังต่อไปนี้ และนาไปสร้างกลุ่มใหม่
Point c1(2,10) c2(5,8) c3(1,2) Cluster
A1 (2,10) 0.00 3.61 8.06 1
A2 (2,5) 5.00 4.24 3.16 3
A3 (8,4) 8.49 5.00 7.29 2
A4 (5,8) 3.61 0.00 7.21 2
A5 (7,5) 7.07 3.60 6.71 2
A6 (6,4) 7.21 4.12 5.39 2
A7 (1,2) 8.06 7.21 0.00 3
A8 (4,9) 2.24 1.41 7.62 2
ตัวอย่างการทา K-Mean Clustering
◍นามาสร้างกลุ่มใหม่
◍จะได้การจัดกลุ่มใหม่ดังภาพ
Custer 1
A1 (2,10)
Custer 2
A3(8,4)
A4(5,8)
A5(7,5)
A6(6,4)
Custer 3
A2(2,5)
A8(1,2)
ตัวอย่างการทา K-Mean Clustering
ขั้นตอนที่ 3
หาค่าเฉลี่ยแต่ละกลุ่มให้เป็น ค่าจุดศูนย์กลางใหม่
สาหรับCluster 1 มีจุดเดียวคือ A1(2, 10) แสดงว่า C1(2,10) ยังคงเดิม
สาหรับ Cluster 2 มี 5 จุดอยู่กลุ่มเดียวกัน เพราะฉะนั้นหา C2 ใหม่ ( (8+5+7+6+4)/5, (4+8+5+4+9)/5 ) = C2(6,6)
สาหรับ Cluster 3 มี 2 จุดอยู่กลุ่มเดียวกัน ( (2+1)/2, (5+2)/2 ) =C3(1.5,3.5)
ตัวอย่างการทา K-Mean Clustering
รอบที่ 2 ทาตามวิธีที่ 1-4 จะได้ผลลัพธ์ดังนี้
Point c1(2,10) c2(6,6) c3(1.5,3.5) Cluster
A1 (2,10) 0.00 5.66 6.52 1
A2 (2,5) 5.00 4.12 1.58 3
A3 (8,4) 8.49 2.83 6.52 2
A4 (5,8) 3.60 2.24 5.70 2
A5 (7,5) 7.07 1.41 5.70 2
A6 (6,4) 7.21 2.00 4.53 2
A7 (1,2) 8.06 6.40 1.58 3
A8 (4,9) 2.24 3.61 6.04 1
ตัวอย่างการทา K-Mean Clustering
รอบที่ 2 Custer 1
A1(2,10)
A8(4,9)
Custer 2
A3(8,4)
A4(5,8)
A5(7,5)
A6(6,4)
Custer 3
A2(2,5)
A7(1,2)
สร้างกลุ่มใหม่
หาจุดศูนย์กลางใหม่จะได้
C1=(2+4/2,10+9/2)=(3,9.5)
C2=(6.5,5.25)
C3=(1.5,3.5)
ตัวอย่างการทา K-Mean Clustering
รอบที่ 3
Point c1(3,9.5) c2(6.5,5.25) c3(1.5,3.5) Clust
er
A1 (2,10) 1.11 6.54 6.52 1
A2 (2,5) 4.61 4.50 1.58 3
A3 (8,4) 7.43 1.96 6.52 2
A4 (5,8) 2.50 3.13 5.70 1
A5 (7,5) 6.02 0.56 5.70 2
A6 (6,4) 6.26 1.35 4.53 2
A7 (1,2) 7.76 6.39 1.58 3
A8 (4,9) 1.12 4.50 6.04 1
ตัวอย่างการทา K-Mean Clustering
รอบที่ 3 สร้างกลุ่มใหม่
หาจุดศูนย์กลางใหม่จะได้
C1=(3.67,9)
C2=(7,4.33)
C3=(1.5,3.5)
Custer 1
A1(2,10)
A8(4,9)
A4(5,8)
Custer 2
A3(8,4)
A4(5,8)
A6(6,4)
Custer 3
A2(2,5)
A7(1,2)
ตัวอย่างการทา K-Mean Clustering
รอบที่ 4
Point c1(3.67,9) c2(7,4.33) c3(1.5,3.5) Cluster
A1 (2,10) 1.94 7.56 6.52 1
A2 (2,5) 4.33 5.04 1.58 3
A3 (8,4) 6.62 1.05 6.52 2
A4 (5,8) 1.67 4.18 5.70 1
A5 (7,5) 5.21 0.67 5.70 2
A6 (6,4) 5.52 1.05 4.53 2
A7 (1,2) 7.49 6.44 1.58 3
A8 (4,9) 0.33 5.55 6.04 1
ตัวอย่างการทา K-Mean Clustering
รอบที่ 4 Custer 1
A1(2,10)
A8(4,9)
A4(5,8)
Custer 2
A3(8,4)
A4(5,8)
A6(6,4)
Custer 3
A2(2,5)
A7(1,2)
Stop
**เมื่อไม่มีการเปลี่ยนแปลงให้หยุดการทางาน**
สร้างกลุ่มใหม่
หาจุดศูนย์กลางใหม่จะได้
C1=(3.67,9)
C2=(7,4.33)
C3=(1.5,3.5)
ตัวอย่างการทา K-Mean Clustering
ผลลัพธ์ จะได้ผลลัพธ์ดังภาพ
ก่อน ผลลัพธ ์
“
1.เมื่อจำนวนข ้อมูลมีจำนวนมำก และมีจำนวนกลุ่มน้อย กำรหำ ค่ำเฉลี่ยแบบ K-
means อำจจะคำนวณได ้เร็วกว่ำ กำรจัดกลุ่ม แบบอื่น ๆ (Hierarchical)
2.ขั้นตอนกำรหำค่ำเฉลี่ยแบบ K-means อำจจะได ้สมำชิก ภำยในกลุ่ม หนำแน่น
กว่ำกำรจัดกลุ่มแบบ Hierarchical โดยเฉพำะถ ้ำกลุ่มเป็นวงกลม
ข้อดีของการทา K-Mean Clustering
“
1. กำรหำค่ำ K ที่เหมำะสมคำดเดำได ้ยำก
2. ทำงำนได ้ไม่ดีถ ้ำกลุ่มข ้อมูลไม่เป็นรูปวงกลม
3. มีข ้อจำกัดในเรื่องของขนำด ควำมหนำแน่น และรูปร่ำง
ข้อด้อยของการทา K-Mean Clustering
สมาชิก
◍1.นำงสำวภัทรพรแสงสัมพันธ์ รหัสนิสิต 57160198
◍2.นำงสำวชำลินีศิลำรัตน์ รหัสนิสิต 57160406
◍3.นำงสำวณิชำนันทน์แดงมำ รหัสนิสิต 57160410
◍4.นำงสำวชลิดำพงศ์จริยำ รหัสนิสิต 57160566
◍5.นำงสำวเบญจมำศแควภูเขียว รหัสนิสิต 57160580
◍6.นำงสำวปภัสวรรณคำทูม รหัสนิสิต 57160583

More Related Content

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

K-means_AI.pptx