開始使用免費開始

以圖形方式評估失業率模型

在這個練習中,你會以圖形方式評估先前章節以 unemployment 資料擬合出的失業率模型 unemployment_model。回想一下,這個模型用 male_unemployment 預測 female_unemployment

你會先將模型的預測值與實際的 female_unemployment 繪圖比較;指令的形式如下:

ggplot(dframe, aes(x = pred, y = outcome)) + 
       geom_point() +  
       geom_abline()

接著你會計算殘差:

residuals <- actual outcome - predicted outcome

並將預測值與殘差作圖。殘差圖的形式會稍有不同:這次是把殘差和水平線 \(y=0\) 比較(使用 geom_hline()),而不是與 \(x=y\) 的對角線比較。指令會提供給你。

資料框 unemployment 與模型 unemployment_model 已預先載入。

本練習屬於課程

R 中的監督式學習:回歸

檢視課程

動手互動練習

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

# unemployment and unemployment_model are available
summary(unemployment)
summary(unemployment_model)

# Make predictions from the model
unemployment$predictions <- ___

# Fill in the blanks to plot predictions (on x-axis) versus the female_unemployment rates
___(___, aes(x = ___, y = ___)) + 
  geom_point() + 
  geom_abline()
編輯並執行程式碼