# following https://rpubs.com/ID_Tech/S1
set.seed(137)
dat <- data.frame(
PeriodEnd =
c("1/31/2017", "1/31/2018", "10/31/2017", "12/31/2017", "6/30/2019", "7/31/2018", "11/30/2019", "7/31/2017", "11/30/2017", "3/31/2017", "9/30/2017", "8/31/2017", "5/31/2018", "0/31/2018"),
HomesSold =
c(62, 60, 84, 97, 51, 85, 55, 74, 76, 62, 67, 78, 76, 75),
Inventory =
c(458, 432, 425, 422, 444, 472, 394, 438, 418, 490, 428, 431, 487, 492),
MedianDom =
c(99, 55, 73, 53, 118, 37, 110, 155, 89, 43, 58, 95, 62, 76),
MedianListPpsf =
c(178, 191, 177, 179, 185, 188, 202, 191, 175, 175, 180, 186, 185, 195),
MedianListPrice =
c(369900, 339900, 334100, 354400, 400520, 372355, 379000, 372800, 369700, 358943, 379500, 356300, 353615, 373645),
MedianPpsf =
c(180, 189, 191, 191, 193, 185, 195, 179, 183, 178, 178, 178, 190, 185),
MedianSalePrice =
c(367912, 398040, 389118, 411088, 390000, 379900, 409900, 348710, 359752, 384591, 348069, 364315, 438845, 375819),
NewListings =
c(76, 94, 112, 83, 83, 77, 67, 69, 96, 98, 110, 118, 111, 124),
PermitBldgs =
c(73, 65, 110, 90, 85, 121, 108, 112, 103, 78, 141, 132, 170, 130),
PermitValue =
c(18924074, 18275062, 26795999, 24514262, 23513520, 34700456, 30880359, 29117986, 27644803, 21168124, 35000701, 32577586, 43139495, 36139075)
)
to_take <- floor(0.75 * nrow(dat))
to_take
#> [1] 10
train_idx <- sample(seq_len(nrow(dat)), size = to_take)
train <- dat[train_idx, ]
test <- dat[-train_idx, ]
train
#> PeriodEnd HomesSold Inventory MedianDom MedianListPpsf MedianListPrice
#> 11 9/30/2017 67 428 58 180 379500
#> 2 1/31/2018 60 432 55 191 339900
#> 8 7/31/2017 74 438 155 191 372800
#> 6 7/31/2018 85 472 37 188 372355
#> 7 11/30/2019 55 394 110 202 379000
#> 3 10/31/2017 84 425 73 177 334100
#> 4 12/31/2017 97 422 53 179 354400
#> 13 5/31/2018 76 487 62 185 353615
#> 1 1/31/2017 62 458 99 178 369900
#> 12 8/31/2017 78 431 95 186 356300
#> MedianPpsf MedianSalePrice NewListings PermitBldgs PermitValue
#> 11 178 348069 110 141 35000701
#> 2 189 398040 94 65 18275062
#> 8 179 348710 69 112 29117986
#> 6 185 379900 77 121 34700456
#> 7 195 409900 67 108 30880359
#> 3 191 389118 112 110 26795999
#> 4 191 411088 83 90 24514262
#> 13 190 438845 111 170 43139495
#> 1 180 367912 76 73 18924074
#> 12 178 364315 118 132 32577586
test
#> PeriodEnd HomesSold Inventory MedianDom MedianListPpsf MedianListPrice
#> 5 6/30/2019 51 444 118 185 400520
#> 9 11/30/2017 76 418 89 175 369700
#> 10 3/31/2017 62 490 43 175 358943
#> 14 0/31/2018 75 492 76 195 373645
#> MedianPpsf MedianSalePrice NewListings PermitBldgs PermitValue
#> 5 193 390000 83 85 23513520
#> 9 183 359752 96 103 27644803
#> 10 178 384591 98 78 21168124
#> 14 185 375819 124 130 36139075