0Pricing
Data Science Academy · درس

أوزان الفئات والعتبات

ضبط النموذج لصالح الفئة الأقلية

أوزان الفئات والعتبات درس مجاني في Data Science Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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/7) وفتح باقي دورة Data Science Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Data Science Academy 4 دروس في المجموع.

ماذا ستتعلم في «أوزان الفئات والعتبات»؟

ضبط النموذج لصالح الفئة الأقلية تتمرن على Data Science Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Data Science Academy؟

لا تُشترط خبرة سابقة. Data Science Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «أوزان الفئات والعتبات»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Data Science Academy هذا؟

نعم. كل درس في Data Science Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. لماذا تكذب الدقة عند عدم التوازن
  2. إعادة أخذ العينات: SMOTE وتقليل العينات
  3. أوزان الفئات والعتبات
  4. اختيار مقاييس للأحداث النادرة
← العودة إلى Data Science Academy