←
PDF 409 / 520 ggplot(diamonds2, aes(lcarat, lresid2)) + geom\hex(bins = 50)
→
English · PDF 409
Original PDF page 409
中文 · PDF 409

ggplot(diamonds2, aes(lcarat, lresid2)) + geom_hex(bins = 50)

这张图表明有一些残差相当大的钻石——请记住,残差为 2 表示该钻石的价格是我们预期价格的 4 倍。逐个查看异常值通常很有用:

diamonds2 %>% filter(abs(lresid2) > 1) %>% add_predictions(mod_diamond2) %>% mutate(pred = round(2 ^ pred)) %>% select(price, pred, carat:table, x:z) %>% arrange(price) #> # A tibble: 16 × 11 #> price pred carat cut color clarity depth table x #> #> 1 1013 264 0.25 Fair F SI2 54.4 64 4.30 #> 2 1186 284 0.25 Premium G SI2 59.0 60 5.33 #> 3 1186 284 0.25 Premium G SI2 58.8 60 5.33 #> 4 1262 2644 1.03 Fair E I1 78.2 54 5.72 #> 5 1415 639 0.35 Fair G VS2 65.9 54 5.57 #> 6 1415 639 0.35 Fair G VS2 65.9 54 5.57 #> # ... 还有 10 行,以及 2 个更多变量:y , #> # z

这里没有什么特别显眼的地方,但值得花时间思考一下:这是否表明我们的模型存在问题,或者数据中存在错误。如果数据中有错误,这可能是一个以被错误标低的低价购买钻石的机会。