0Pricing
Data Science Academy · บทเรียน

ปรับแต่งด้วย GridSearchCV

ค้นหาพารามิเตอร์ระดับสูงอย่างปลอดภัย

ปรับแต่งด้วย GridSearchCV เป็นบทเรียน Data Science Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Data Science Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ปรับแต่งด้วย GridSearchCV”

ค้นหาพารามิเตอร์ระดับสูงอย่างปลอดภัย คุณปฏิบัติ Data Science Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Data Science Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Data Science Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “ปรับแต่งด้วย GridSearchCV” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Data Science Academy นี้ได้ไหม

ได้ บทเรียน Data Science Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. เหตุใดไปป์ไลน์จึงดีกว่าขั้นตอนทำเอง
  2. ColumnTransformer สำหรับชนิดข้อมูลผสม
  3. ปรับแต่งด้วย GridSearchCV
  4. บันทึกและโหลดไปป์ไลน์ที่ฝึกแล้ว
← กลับไปที่ Data Science Academy