使用 TPOT 進行遺傳式超參數調校
你將要實作一個遺傳式超參數調校的簡單範例。TPOT 是功能非常強大的函式庫,內含許多特性。本課只是淺嚐即止,但非常鼓勵你在課後自行探索。
這只是個很小的例子。在實務上,TPOT 通常會執行許多小時來找出最佳模型。你會使用更大的族群與子代大小,並進行數百個世代,來尋找表現良好的模型。
你將建立一個 estimator,將其擬合到訓練資料,然後在測試資料上進行評分。
在這個例子中我們要使用:
- 3 個世代(generations)
- 族群大小為 4(population size 4)
- 每個世代有 3 個子代(offspring 3)
- 以 accuracy 作為評分指標(scoring)
為了結果的一致性,random_state 已設為 2。
本練習屬於課程
Python 超參數調校
練習說明
- 將情境說明中的數值指定到
tpot_clf的各個輸入參數。 - 以正確的輸入參數建立
tpot_clf分類器。 - 將分類器擬合到訓練資料(工作區已提供
X_train與y_train)。 - 使用已擬合的分類器在測試集上進行評分(工作區已提供
X_test與y_test)。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Assign the values outlined to the inputs
number_generations = ____
population_size = ____
offspring_size = ____
scoring_function = ____
# Create the tpot classifier
tpot_clf = TPOTClassifier(generations=____, population_size=____,
offspring_size=____, scoring=____,
verbosity=2, random_state=2, cv=2)
# Fit the classifier to the training data
____.____(____, ____)
# Score on the test set
print(____.____(____, ____))