您的訂閱是我製作影片的動力
訂閱點這裡~
若內容有誤,還請留言指正,謝謝您的指教
#影片程式碼
#GB
library(gbm)
set.seed(123)
model <- gbm(formula = Sepal.Length ~ .,distribution = "gaussian",
data = iris,n.trees = 479,
interaction.depth = 1,
shrinkage = 0.1,n.minobsinnode = 15,
bag.fraction = 1,
train.fraction = 0.5,cv.folds = 10)
#分類用 bernoulli 迴歸用gaussian(RMSE)
#XGB
data("iris")
par(mfrow=c(1,4))
boxplot(iris$Sepal.Length)$out
boxplot(iris$Sepal.Width)$out
boxplot(iris$Petal.Length)$out
boxplot(iris$Petal.Width)$out
#離群值不多先不轉
n <- nrow(iris)
set.seed(1117)
subiris <- sample(seq_len(n), size = round(0.7 * n))
traindata <- iris[subiris,]
testdata <- iris[ - subiris,]
features <- setdiff(names(iris), "Sepal.Length")
library(vtreat)#單熱
library(dplyr)
onehot <- vtreat::designTreatmentsZ(iris, features, verbose = FALSE)
單熱 <- onehot %>%
magrittr::use_series(scoreFrame) %>%
dplyr::filter(code %in% c("clean", "lev")) %>%
magrittr::use_series(varName)
trainx <- vtreat::prepare(onehot, traindata, varRestriction = 單熱) %>% as.matrix()
trainy <- traindata$Sepal.Length
testx <- vtreat::prepare(onehot, testdata, varRestriction = 單熱) %>% as.matrix()
testy <- testdata$Sepal.Length
library(xgboost)
set.seed(123)
model <- xgboost(data = trainx,
label = trainy,
nrounds = 531,eta=0.1,
min_child_weight=3,max_depth=1,
subsample=1,colsample_bytree=0.9,
objective = "reg:squarederror",verbose = 0)