←
PDF 404 / 520 the diamond. The weight of the diamond is the single most impor‐ tant factor for determining the
→
English · PDF 404
Original PDF page 404
中文 · PDF 404

钻石。钻石的重量是决定钻石价格的最重要因素,而质量较低的钻石往往更大:

ggplot(diamonds, aes(carat, price)) + geom_hex(bins = 50)

我们可以通过拟合一个模型来分离出克拉的影响,从而更容易看出钻石的其他属性如何影响其相对价格。但首先,让我们对 diamonds 数据集做一些小调整,使其更易于处理:

    1. 只关注小于 2.5 克拉的钻石(占数据的 99.7%)。
    1. 对 carat 和 price 变量进行对数变换:

diamonds2 <- diamonds %>% filter(carat <= 2.5) %>% mutate(lprice = log2(price), lcarat = log2(carat))

这些改动合在一起,使我们更容易看出克拉与价格之间的关系:

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