格式化預測的後驗分佈
現在來繪製一些新的預測。這個練習中,我們要預測一首剛發行、song_age 為 0 的歌曲會有多受歡迎。我們仍然用 song_age 和 artist_name 來預測 popularity。new_predictions 物件已經建立好,包含對於新歌(Adele、Taylor Swift、Beyoncé)預測分數的機率分佈。
本練習屬於課程
使用 rstanarm 的貝葉斯迴歸建模
練習說明
- 列印
new_predictions前 10 次反覆運算的預測分數。 - 將
new_predictions轉換為資料框,並將資料框的欄名命名為 「Adele」、「Taylor Swift」 和 「Beyoncé」。 - 將資料整理為長格式,只保留兩欄:
artist_name與predict。 - 列印新整理好的
plot_posterior資料框的前六列。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# View new data predictions
___[___:___, ]
# Convert to data frame and rename variables
new_predictions <- ___(new_predictions)
___(___) <- c("___", "___", "___")
# Create tidy data structure
plot_posterior <- ___(new_predictions, key = "artist_name", value = "predict")
# Print formated data
___(plot_posterior)