クラスの重みとしきい値
少数クラスを重視するようモデルを調整する
「クラスの重みとしきい値」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはData Science Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Data Science Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Fix It Without Resampling
You can fight imbalance without touching the data at all. Two model-side levers help: class weights and the decision threshold.
What Class Weights Do
Class weights tell the model that mistakes on the rare class hurt more. It pays a bigger penalty for missing minority rows.
The Easy Default
Many scikit-learn models accept class_weight set to balanced. It auto-weights each class inversely to how often it appears.
model = LogisticRegression(class_weight='balanced')
model.fit(X_train, y_train)Weights vs Resampling
Class weights reshape the loss instead of the dataset. No rows are added or dropped, so you keep all your original data.
The Hidden 0.5 Cutoff
Most classifiers predict a probability, then label it positive if it tops 0.5. That default cutoff is a choice, not a law.
Move the Threshold
Lower the threshold and the model flags positives more eagerly. That catches more rare cases, at the price of more false alarms.
Predict Probabilities First
To tune a threshold, ask the model for probabilities, not hard labels. Then apply your own cutoff to those scores.
proba = model.predict_proba(X_test)[:, 1]
preds = (proba >= 0.30).astype(int)The Core Trade-Off
A lower threshold lifts recall but drops precision. Raising it does the reverse. The right point depends on which mistake costs more.
Let Cost Drive the Cutoff
If a missed fraud is far worse than a false alarm, lean toward a lower threshold so the rare class is rarely missed.
Combine the Levers
Class weights and threshold tuning stack nicely. Weight the rare class during training, then pick a cutoff that matches your real costs.
Tune, Then Lock It In
Choose the threshold using validation data, never the test set. Then apply that same fixed cutoff for an honest final score.
Quick Check
What happens when you lower the decision threshold?
Recap
Without resampling, class weights penalize rare-class errors and a tuned threshold trades recall against precision to fit your costs. 🎯
よくある質問
「クラスの重みとしきい値」レッスンは無料ですか?
はい。「クラスの重みとしきい値」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。
「クラスの重みとしきい値」で何を学びますか?
少数クラスを重視するようモデルを調整する ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Data Science Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「クラスの重みとしきい値」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このData Science Academyレッスンでコードを書いて実行できますか?
はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。