リサンプリング:SMOTEとアンダーサンプリング
学習セットのバランスを取り直す
「リサンプリング:SMOTEとアンダーサンプリング」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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とアンダーサンプリング」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。
「リサンプリング:SMOTEとアンダーサンプリング」で何を学びますか?
学習セットのバランスを取り直す ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Data Science Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「リサンプリング:SMOTEとアンダーサンプリング」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このData Science Academyレッスンでコードを書いて実行できますか?
はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 不均衡データでは正解率にだまされる理由
- リサンプリング:SMOTEとアンダーサンプリング
- クラスの重みとしきい値
- まれな事象に合う指標を選ぶ