การตรวจสอบไขว้แบบ K-Fold
หาค่าเฉลี่ยคะแนนจากแต่ละส่วน
การตรวจสอบไขว้แบบ K-Fold เป็นบทเรียน Data Science Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Data Science Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
One Split, One Worry
A single train/test split gives just one score. If that split was lucky or unlucky, your estimate could be misleading.
The Big Idea
Cross-validation reuses your data many times, testing on a different slice each round, then averages the scores for a steadier estimate.
Cut Into Folds
You chop the data into k equal parts called folds. A common choice is five folds, giving five separate test rounds.
Rotate the Test Fold
Each round, one fold becomes the test set and the other k minus one folds train the model. Then the test fold rotates to the next one.
Everyone Gets a Turn
Over k rounds, every row is tested on exactly once and trained on the rest of the time. No data is wasted. 🔄
Average the Scores
You end with k scores, one per fold. Their average is your headline estimate, and their spread shows how stable the model is.
The Quick Way
scikit-learn does the looping for you. The helper cross_val_score returns one score per fold in a single line.
from sklearn.model_selection import cross_val_score
scores = cross_val_score(model, X, y, cv=5)Read the Result
The returned array holds each fold's score. Take its mean for the headline and its standard deviation to gauge reliability.
print(scores.mean(), scores.std())Choosing k
Five or ten folds are typical. More folds train on more data per round but cost more compute, so it is a speed-versus-stability trade.
Keep Classes Balanced
For classification, use StratifiedKFold so each fold mirrors the overall class balance. scikit-learn applies it automatically for classifiers.
Hold Out a Final Test
Cross-validation guides model choice during development. Still keep one untouched test set aside for a single honest score at the very end.
Quick Check
In 5-fold cross-validation, how often is each row tested?
Recap
Split into k folds, rotate the test fold, and average the scores for a robust estimate. Use cross_val_score, then a final hold-out. 🔄
คำถามที่พบบ่อย
บทเรียน “การตรวจสอบไขว้แบบ K-Fold” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การตรวจสอบไขว้แบบ K-Fold” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Data Science Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การตรวจสอบไขว้แบบ K-Fold”
หาค่าเฉลี่ยคะแนนจากแต่ละส่วน คุณปฏิบัติ Data Science Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Data Science Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Data Science Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “การตรวจสอบไขว้แบบ K-Fold” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Data Science Academy นี้ได้ไหม
ได้ บทเรียน Data Science Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- เหตุใดจึงต้องกันชุดทดสอบไว้
- ใช้ train_test_split ให้ถูกต้อง
- การตรวจสอบไขว้แบบ K-Fold
- หยุดการรั่วไหลของข้อมูลตั้งแต่เริ่มต้น