開始使用免費開始

看看集成模型的表現

來檢查我們集成後模型的表現,看看目前狀況如何。你應該會看到 R\(^2\) 分數大約是先前各模型的平均,散佈圖的型態也會混合了之前模型的預測。使用自訂損失函式模型所產生的領結形狀應該仍隱約可見,但在 x=0 附近的邊緣會更平滑。

本練習屬於課程

Python 金融 Machine Learning

檢視課程

練習說明

  • 在訓練集與測試集上評估 R\(^2\) 分數。使用 sklearnr2_score() 函式(已為你匯入),並搭配上一個練習中的 train_targetstrain_preds
  • 使用 plt.scatter() 繪製訓練與測試預測值相對於實際值的散佈圖。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

from sklearn.metrics import r2_score

# Evaluate the R^2 scores
print(r2_score(____, ____))
print(r2_score(test_targets, test_preds))

# Scatter the predictions vs actual -- this one is interesting!
plt.scatter(____, ____, ____)
plt.scatter(test_preds, test_targets, label='test')
plt.legend(); plt.show()
編輯並執行程式碼