0Pricing
Data Science Academy · บทเรียน

k-Means และการเลือกค่า k

วิธีข้อศอกและวิธี silhouette

k-Means และการเลือกค่า k เป็นบทเรียน Data Science Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Data Science Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

The Go-To Clusterer

k-Means is the most popular clustering algorithm: it splits your data into k groups by grouping points around central anchors. 🎯

Centroids Are Anchors

Each cluster has a centroid, the mean position of its members. Points join the cluster whose centroid sits closest to them.

The Repeating Dance

k-Means alternates two steps: assign every point to its nearest centroid, then recompute each centroid from its new members.

It Settles Down

Those steps repeat until assignments stop changing. The algorithm has converged, and the clusters are final.

You Choose k First

k-Means cannot invent the number of groups. You must pick k up front, and the right value is rarely obvious.

Run It in One Line

scikit-learn makes fitting easy. Set n_clusters to your chosen k and call fit on your scaled data.

from sklearn.cluster import KMeans
model = KMeans(n_clusters=3).fit(X)

Inertia Measures Tightness

After fitting, inertia reports the total squared distance from points to their centroids. Lower means tighter clusters.

model.inertia_

The Elbow Method

Plot inertia for many k values. Where the curve bends sharply, the elbow, often marks a good number of clusters.

Diminishing Returns

Past the elbow, adding clusters barely lowers inertia. That flattening signals you are just splitting groups that already fit well.

The Silhouette Score

A second guide is the silhouette score: it rewards points that sit close to their own cluster and far from others.

from sklearn.metrics import silhouette_score

Start Smarter

Random starts can land badly, so scikit-learn defaults to k-means++, which spreads initial centroids out for steadier results.

Quick Check

Let us check how you would pick a sensible k.

Recap

k-Means groups points around centroids for a chosen k; the elbow and silhouette help you pick that k well. 🎯

คำถามที่พบบ่อย

บทเรียน “k-Means และการเลือกค่า k” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “k-Means และการเลือกค่า k” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Data Science Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “k-Means และการเลือกค่า k”

วิธีข้อศอกและวิธี silhouette คุณปฏิบัติ Data Science Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Data Science Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Data Science Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “k-Means และการเลือกค่า k” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Data Science Academy นี้ได้ไหม

ได้ บทเรียน Data Science Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. แบบมีผู้สอนกับแบบไม่มีผู้สอน
  2. k-Means และการเลือกค่า k
  3. แบบลำดับชั้นและ DBSCAN
  4. สำรวจและตั้งชื่อกลุ่มข้อมูล
← กลับไปที่ Data Science Academy