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

เพื่อนบ้านใกล้ที่สุด k ตัว

จัดประเภทตามตัวอย่างที่ใกล้ที่สุด

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

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

Judged by Your Neighbors

k-Nearest Neighbors classifies a point by looking at the examples closest to it. Birds of a feather end up in the same class. 🐦

No Real Training

kNN is a lazy learner: it just memorizes the data. The real work happens later, when a new point asks for a label.

Measure the Distance

To find who is near, the model computes a distance to every training point, most often plain straight-line distance.

Take a Vote

The closest k neighbors each cast a vote. Whichever class wins the majority becomes the prediction for the new point.

k Is the Key Choice

The letter k is how many neighbors you consult. It is the one knob that most shapes how kNN behaves.

Small k, Jumpy Borders

A tiny k, like 1, follows every wiggle in the data and reacts to noise, giving jagged, overfit boundaries.

Large k, Smoother Calls

A big k averages over many points for smoother decisions, but too large and it blurs the real differences between classes.

Scaling Is Not Optional

Distance is unfair if one feature spans thousands and another spans tenths. Always scale features so each counts equally.

Build the Classifier

Create it like any estimator and pick your n_neighbors right away. Here we consult the five closest points.

from sklearn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier(n_neighbors=5)

Fit, Then Predict

The familiar contract still applies: fit stores the data, predict finds neighbors and votes on the answer.

model.fit(X_train, y_train)
model.predict(X_test)

Watch the Cost

kNN is simple but can be slow at prediction time, since every guess compares the new point to all stored examples.

Quick Check

Let's pin down the parameter that defines kNN.

Recap

kNN predicts by letting the closest k neighbors vote. Choose k with care and scale your features, and it works well. 🎯

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

บทเรียน “เพื่อนบ้านใกล้ที่สุด k ตัว” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “เพื่อนบ้านใกล้ที่สุด k ตัว”

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

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

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

บทเรียน “เพื่อนบ้านใกล้ที่สุด k ตัว” ใช้เวลานานแค่ไหน

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

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

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

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

  1. การถดถอยลอจิสติกสำหรับใช่หรือไม่ใช่
  2. เพื่อนบ้านใกล้ที่สุด k ตัว
  3. ต้นไม้ตัดสินใจและป่าสุ่ม
  4. พื้นฐาน Gradient Boosting
← กลับไปที่ Data Science Academy