Học có giám sát với R: Hồi quy
Nina Zumel and John Mount
Win-Vector, LLC
model.matrix()xgboost() thì khôngÝ tưởng chính:
designTreatmentsZ() để thiết kế treatment plan từ dữ liệu huấn luyện, rồiprepare() để tạo dữ liệu "sạch"prepare() với treatment plan cho mọi dữ liệu về sauDữ liệu huấn luyện
| x | u | y |
|---|---|---|
| one | 44 | 0.4855671 |
| two | 24 | 1.3683726 |
| three | 66 | 2.0352837 |
| two | 22 | 1.6396267 |
Dữ liệu kiểm tra
| x | u | y |
|---|---|---|
| one | 5 | 2.6488148 |
| three | 12 | 1.5012938 |
| one | 56 | 0.1993731 |
| two | 28 | 1.2778516 |
vars <- c("x", "u")
treatplan <- designTreatmentsZ(dframe, varslist, verbose = FALSE)
Đầu vào của designTreatmentsZ()
dframe: dữ liệu huấn luyệnvarlist: danh sách tên biến đầu vàoscoreFrame mô tả ánh xạ biến và kiểu
(scoreFrame <- treatplan$scoreFrame %>%
select(varName, origName, code))
varName origName code
1 x_lev_x.one x lev
2 x_lev_x.three x lev
3 x_lev_x.two x lev
4 x_catP x catP
5 u_clean u clean
Lấy tên các biến lev và clean mới
(newvars <- scoreFrame %>%
filter(code %in% c("clean", "lev")) %>%
use_series(varName))
"x_lev_x.one" "x_lev_x.three" "x_lev_x.two" "u_clean"
training.treat <- prepare(treatmentplan, dframe, varRestriction = newvars)
Đầu vào của prepare():
treatmentplan: treatment plandframe: data framevarRestriction: danh sách biến cần chuẩn bị (tùy chọn)Dữ liệu huấn luyện
| x | u | y |
|---|---|---|
| one | 44 | 0.4855671 |
| two | 24 | 1.3683726 |
| three | 66 | 2.0352837 |
| two | 22 | 1.6396267 |
Dữ liệu huấn luyện đã xử lý
| x_lev _x. one | x_lev _x. three | x_lev _x. two | u_clean |
|---|---|---|---|
| 1 | 0 | 0 | 44 |
| 0 | 0 | 1 | 24 |
| 0 | 1 | 0 | 66 |
| 0 | 0 | 1 | 22 |
(test.treat <- prepare(treatplan, test, varRestriction = newvars))
x_lev_x.one x_lev_x.three x_lev_x.two u_clean
1 1 0 0 5
2 0 1 0 12
3 1 0 0 56
4 0 0 1 28
Mức x chưa từng thấy trước đây: four
| x | u | y |
|---|---|---|
| one | 4 | 0.2331301 |
| two | 14 | 1.9331760 |
| three | 66 | 3.1251029 |
| four | 25 | 4.0332491 |
four được mã hóa thành (0, 0, 0)
prepare(treatplan, toomany, ...)
| x_lev _x. one | x_lev _x. three | x_lev _x. two | u_clean |
|---|---|---|---|
| 1 | 0 | 0 | 4 |
| 0 | 0 | 1 | 14 |
| 0 | 1 | 0 | 66 |
| 0 | 0 | 0 | 25 |
Học có giám sát với R: Hồi quy