0Pricing
Data Science Academy · درس

الضبط باستخدام GridSearchCV

البحث عن المعاملات الفائقة بأمان

الضبط باستخدام GridSearchCV درس مجاني في Data Science Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Data Science Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Data Science Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Settings You Choose

Some model settings are not learned from data; you pick them before training. These are hyperparameters, and good choices matter a lot.

Guessing Is Slow

Tweaking one value, re-running, and eyeballing the score by hand wastes time and misses better combos. Let a search do it. 🔍

Enter GridSearchCV

GridSearchCV tries every combination in a grid you define and uses cross-validation to score each one fairly.

from sklearn.model_selection import GridSearchCV

Define the Grid

You list each hyperparameter and the values to try in a dictionary. Every value pairing becomes one candidate to test.

param_grid = {'C': [0.1, 1, 10]}

Tune Inside a Pipeline

To target a pipeline step, prefix the name with the step plus a double underscore. This naming points the search at the right knob.

param_grid = {'model__C': [0.1, 1, 10]}

Run the Search

Wrap your estimator and grid, then call fit. It trains and scores every combination across the folds for you.

search = GridSearchCV(pipe, param_grid, cv=5)
search.fit(X_train, y_train)

Read the Winner

After fitting, best_params_ tells you which combination won, and best_score_ shows its average cross-validated score.

print(search.best_params_, search.best_score_)

Predict With the Best

The search refits the top combo on all training data. Just call predict on the search object to use that best_estimator.

preds = search.predict(X_test)

Pick the Right Scorer

By default it optimizes accuracy. Set scoring to f1 or roc_auc so the search chases the metric your problem cares about.

GridSearchCV(pipe, param_grid, scoring='f1', cv=5)

Mind the Cost

The grid grows fast: combinations times folds equals fits. When it explodes, try RandomizedSearchCV to sample instead.

Leak-Free by Design

Because the whole pipeline is searched, prep refits inside each fold. Tuning stays honest with zero leakage sneaking in.

Quick Check

To tune a pipeline step named model, how do you key the parameter?

Recap

You can now let GridSearchCV test parameter combos with cross-validation and hand you the best one. Next, saving your trained pipeline. 💾

الأسئلة الشائعة

هل درس «الضبط باستخدام GridSearchCV» مجاني؟

نعم — نص درس «الضبط باستخدام GridSearchCV» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Data Science Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Data Science Academy 4 دروس في المجموع.

ماذا ستتعلم في «الضبط باستخدام GridSearchCV»؟

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

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

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

كم من الوقت يستغرق درس «الضبط باستخدام GridSearchCV»؟

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

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

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

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

  1. لماذا تتفوق Pipelines على الخطوات اليدوية
  2. ColumnTransformer للأنواع المختلطة
  3. الضبط باستخدام GridSearchCV
  4. حفظ Pipeline مدرّبة وإعادة تحميلها
← العودة إلى Data Science Academy