การสุ่มตัวอย่างใหม่: SMOTE และการลดตัวอย่าง
ปรับสมดุลชุดข้อมูลฝึก
การสุ่มตัวอย่างใหม่: SMOTE และการลดตัวอย่าง เป็นบทเรียน Data Science Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Data Science Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Rebalance the Training Set
One way to help a model see the rare class is to resample: change how many examples of each class it trains on.
Two Directions to Balance
You can add more of the minority (oversample) or trim the majority (undersample). Both aim to even out the class counts.
Naive Oversampling
The simplest oversample just copies minority rows until counts match. It works, but those exact duplicates can make a model memorize them.
Enter SMOTE
SMOTE creates synthetic minority examples instead of copies. It invents new, plausible points between real minority neighbors.
How SMOTE Builds Points
SMOTE picks a minority row, finds a nearby minority neighbor, and places a fresh point somewhere on the line between them.
SMOTE in Code
The imbalanced-learn library makes SMOTE a two-line affair on your training features and labels.
from imblearn.over_sampling import SMOTE
X_res, y_res = SMOTE().fit_resample(X_train, y_train)Undersampling the Majority
Undersampling drops majority rows until balance returns. It trains faster but throws away data, which can cost real signal.
When to Pick Which
Oversample when data is scarce and every row matters. Undersample when the majority is huge and you can spare some rows for speed.
The Cardinal Rule
Resample only the training set. Touch the test set and your scores become fantasy, since real data is never rebalanced for you.
Fit on Train Only
SMOTE must learn from training rows alone. Leaking test rows into resampling inflates results and quietly causes data leakage. ⚠️
Resampling Is Not a Cure-All
Balanced counts help, but they are not magic. Pair resampling with the right metrics and sometimes class weights for the best results.
Quick Check
What makes SMOTE different from plain oversampling?
Recap
Resampling balances the training set by oversampling (SMOTE makes synthetic rows) or undersampling. Never resample the test set. 🎯
คำถามที่พบบ่อย
บทเรียน “การสุ่มตัวอย่างใหม่: SMOTE และการลดตัวอย่าง” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การสุ่มตัวอย่างใหม่: SMOTE และการลดตัวอย่าง” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Data Science Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การสุ่มตัวอย่างใหม่: SMOTE และการลดตัวอย่าง”
ปรับสมดุลชุดข้อมูลฝึก คุณปฏิบัติ Data Science Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Data Science Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Data Science Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “การสุ่มตัวอย่างใหม่: SMOTE และการลดตัวอย่าง” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Data Science Academy นี้ได้ไหม
ได้ บทเรียน Data Science Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- เหตุใดความแม่นยำจึงหลอกเราเมื่อข้อมูลไม่สมดุล
- การสุ่มตัวอย่างใหม่: SMOTE และการลดตัวอย่าง
- น้ำหนักคลาสและค่าเกณฑ์
- เลือกตัวชี้วัดสำหรับเหตุการณ์ที่พบได้น้อย