使用迴歸模型進行預測
你已經用 California housing 資料擬合好了模型,現在來看看它在新資料上的預測結果。你可以輸入一段範圍的數值當作輸入,觀察模型對每個輸入的預測,以此探索模型找到的輸入與輸出之間的關係。
工作環境中已提供一個 1 維陣列 new_inputs,包含 100 個「新」的 "MedHouseVal"(房價中位數)數值,另外也有你在上一個練習訓練好的 model。
本練習屬於課程
Python 的時間序列資料機器學習
練習說明
- 在終端機檢視
new_inputs。 - 將
new_inputs重新塑形為適合用來產生預測的形狀。 - 執行提供的程式碼以視覺化預測結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Generate predictions with the model using those inputs
predictions = ____
# Visualize the inputs and predicted values
plt.scatter(new_inputs, predictions, color='r', s=3)
plt.xlabel('inputs')
plt.ylabel('predictions')
plt.show()