0Pricing
Data Science Academy · レッスン

GridSearchCVでチューニングする

ハイパーパラメーターを安全に探索する

「GridSearchCVでチューニングする」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。

「GridSearchCVでチューニングする」で何を学びますか?

ハイパーパラメーターを安全に探索する ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Data Science Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「GridSearchCVでチューニングする」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このData Science Academyレッスンでコードを書いて実行できますか?

はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 手作業の手順よりパイプラインを使う理由
  2. 異なる型にColumnTransformerを使う
  3. GridSearchCVでチューニングする
  4. 学習済みパイプラインを保存して再読み込みする
← Data Science Academyに戻る