Memuat
Memuat
XGBoost for Informatics and Information Systems
0 views
Using synthetic data as an illustration, the analysis seeks to predict used laptop price with XGBoost and assess the contribution of RAM capacity and device age. XGBoost is a gradient boosting algorithm that builds decision trees sequentially, each correcting the errors of the previous ones, with regularisation to prevent overfitting. It suits theses predicting a continuous outcome from many features with nonlinear relationships, compared against linear regression.

Using synthetic data as an illustration, the analysis seeks to predict used laptop price with XGBoost and assess the contribution of RAM capacity and device age.
| Role | Variable | Unit |
|---|---|---|
| Main | Used laptop price | IDR million |
| Supporting 1 | RAM capacity | GB |
| Supporting 2 | Device age | years |
XGBoost with 96 boosting rounds (chosen by 5-fold cross-validation) predicts Used laptop price on the test set with R2 = 0.700, RMSE = 3.697 and MAE = 2.825, outperforming linear regression (R2 = 0.641). The feature with the largest gain is Device age (45.8% of total gain).
Computed from illustrative synthetic data, not from a real study.
XGBoost is a gradient boosting algorithm that builds decision trees sequentially, each correcting the errors of the previous ones, with regularisation to prevent overfitting. It suits theses predicting a continuous outcome from many features with nonlinear relationships, compared against linear regression.
Report the test RMSE, MAE and R2 with the selected number of rounds, then compare with the linear model to show the benefit of nonlinear modelling. Explain the features with the largest gain and use the learning curve to show the model is not overfitting.
A short starting script with this project's variable names. The delivered version is adapted to your data and fully commented.
# Contoh kode R: XGBoost
suppressPackageStartupMessages({
library(ggplot2)
library(patchwork)
library(xgboost)
})
set.seed(42)
# ---- Gaya grafik ----
pal <- c("#1f6feb", "#e8590c", "#2f9e44", "#ae3ec9", "#f59f00")
warna <- list(bg = "#f4f6fa", panel = "#ffffff", teks = "#1f2933", redup = "#5f6b78", grid = "#e3e8ee", bar = "#1d3557")
tata <- 1
theme_set(theme_minimal(base_size = 11) + theme(legend.position = "bottom"))
# ---- Data sintetis: Y kontinu dengan hubungan nonlinear dan interaksi ----
n <- max(200, 300)
d <- data.frame(ram_capacity = round(rnorm(n, 50, 10), 3),
device_age = round(rnorm(n, 30, 6), 3),
fitur_3 = round(runif(n, 0, 10), 2), # fitur pendukung (pengaruh ambang)
fitur_4 = round(rnorm(n, 50, 12), 2), # fitur pendukung (pengaruh lemah)
fitur_5 = round(rnorm(n, 20, 5), 2)) # fitur pengganggu (tanpa pengaruh)
z1 <- as.numeric(scale(d$ram_capacity)); z2 <- as.numeric(scale(d$device_age))
z4 <- as.numeric(scale(d$fitur_4))
a1 <- runif(1, 0.7, 1.1); a2 <- runif(1, 0.4, 0.7) * sample(c(-1, 1), 1)
f <- a1 * tanh(1.3 * z1) + a2 * z2 + runif(1, 0.2, 0.4) * z2^2 * sign(a2) + # efek jenuh dan kuadratik
runif(1, 0.3, 0.5) * (d$fitur_3 > 6) + 0.25 * z1 * z2 + 0.15 * z4 # efek ambang dan interaksi
f <- (f - mean(f)) / sd(f)
d$used_laptop_price <- round(100 + 15 * (f * runif(1, 0.85, 0.95) + rnorm(n, 0, runif(1, 0.3, 0.45))), 3)
write.csv(d, "data_contoh.csv", row.names = FALSE)
# ---- Bagi data latih 75% dan uji 25% ----
fitur <- c("ram_capacity", "device_age", "fitur_3", "fitur_4", "fitur_5")
id_latih <- sample(n, round(0.75 * n))
latih <- d[id_latih, ]; uji <- d[-id_latih, ]
dlatih <- xgb.DMatrix(data = as.matrix(latih[, fitur]), label = latih$used_laptop_price)
duji <- xgb.DMatrix(data = as.matrix(uji[, fitur]), label = uji$used_laptop_price)
# ---- Validasi silang 5 lipatan untuk memilih jumlah iterasi (early stopping) ----
param <- list(objective = "reg:squarederror", eta = 0.05, max_depth = 4, subsample = 0.8,
colsample_bytree = 0.8, min_child_weight = 3, nthread = 1,
base_score = mean(latih$used_laptop_price)) # titik awal = rata-rata Y latih
cv <- xgb.cv(params = param, data = dlatih, nrounds = 1000, nfold = 5, early_stopping_rounds = 30,
metrics = "rmse", verbose = 0)
best <- cv$best_iteration
cat("Jumlah iterasi terbaik (CV):", best, "\n")
# ---- Model akhir dan evaluasi pada data uji ----
fit <- xgb.train(params = param, data = dlatih, nrounds = best, verbose = 0)
pred <- predict(fit, duji)
ukur <- function(y, p) c(RMSE = sqrt(mean((y - p)^2)), MAE = mean(abs(y - p)), R2 = 1 - sum((y - p)^2) / sum((y - mean(y))^2))
m_xgb <- ukur(uji$used_laptop_price, pred)
print(round(m_xgb, 4))
# ---- Pembanding: regresi linear berganda ----
fit_lm <- lm(used_laptop_price ~ ram_capacity + device_age + fitur_3 + fitur_4 + fitur_5, data = latih)
pred_lm <- predict(fit_lm, uji)
m_lm <- ukur(uji$used_laptop_price, pred_lm)
print(rbind(XGBoost = m_xgb, Linear = m_lm))
# ---- Kepentingan fitur (gain) ----
imp <- xgb.importance(feature_names = fitur, model = fit)
print(imp)
# ---- Grafik ----
dp <- rbind(data.frame(aktual = uji$used_laptop_price, prediksi = pred_lm, model = "Linear"),
data.frame(aktual = uji$used_laptop_price, prediksi = pred, model = "XGBoost"))
dp$model <- factor(dp$model, levels = c("Linear", "XGBoost"))
p1 <- ggplot(dp, aes(aktual, prediksi, colour = model)) +
geom_abline(slope = 1, intercept = 0, linetype = "dashed", colour = warna$redup) +
geom_point(alpha = 0.6, size = 1.6) +
scale_colour_manual(values = c(Linear = warna$redup, XGBoost = pal[1]), name = NULL) +
labs(title = "Predicted vs actual (test set)", x = "Actual used_laptop_price", y = "Predicted used_laptop_price") +
theme(legend.position = "bottom")
nama_tampil <- c("ram_capacity" = "ram_capacity", "device_age" = "device_age", fitur_3 = "Feature 3", fitur_4 = "Feature 4", fitur_5 = "Feature 5")
nama_tampil[] <- make.unique(nama_tampil, sep = " ") # cegah label kembar
di <- data.frame(fitur = nama_tampil[imp$Feature], gain = imp$Gain)
di$fitur <- factor(di$fitur, levels = di$fitur[order(di$gain)])
p2 <- ggplot(di, aes(gain, fitur)) +
geom_col(fill = pal[2], width = 0.65, alpha = 0.9) +
geom_text(aes(label = sprintf("%.1f%%", 100 * gain)), hjust = -0.15, colour = warna$teks, size = 3) +
scale_x_continuous(labels = function(v) paste0(100 * v, "%"), expand = expansion(mult = c(0, 0.2))) +
labs(title = "Feature importance (gain)", x = "Share of total gain", y = NULL)
ev <- as.data.frame(cv$evaluation_log)
dl <- rbind(data.frame(iter = ev$iter, rmse = ev$train_rmse_mean, sd = ev$train_rmse_std, set = "CV train"),
data.frame(iter = ev$iter, rmse = ev$test_rmse_mean, sd = ev$test_rmse_std, set = "CV validation"))
p3 <- ggplot(dl, aes(iter, rmse, colour = set, fill = set)) +
geom_ribbon(aes(ymin = rmse - sd, ymax = rmse + sd), alpha = 0.15, colour = NA) +
geom_line(linewidth = 1) +
geom_vline(xintercept = best, linetype = "dashed", colour = warna$redup) +
scale_colour_manual(values = c("CV train" = pal[3], "CV validation" = pal[4]), name = NULL) +
scale_fill_manual(values = c("CV train" = pal[3], "CV validation" = pal[4]), name = NULL) +
labs(title = sprintf("Learning curve (best = %d rounds)", best), x = "Boosting round", y = "RMSE") +
theme(legend.position = "bottom")
p_hasil <- if (tata == 1) p1 | (p2 / p3) else (p2 / p3) | p1
print(p_hasil)
The original project file is available. It is not just the picture above: you get the working R project. It can be downloaded after payment, and we send it by WhatsApp or email.
ZIP: analisis.R + data_contoh.csv + BACA-DULU.txt
Choose how much help you need. Each higher package includes everything in the lower ones. Prices exclude 11% VAT.
Package 1
US$31
excl. 11% VAT
Duration: 7 working days
Output: R files + result figures
Deliverables
Package 2 · most chosen
US$88
excl. 11% VAT
Duration: 13 working days
Output: Code + analysis + interpretation notes
Includes all of Package 1, plus
Package 3
US$194
excl. 11% VAT
Duration: 18-21 working days
Output: Code + analysis + guidance until ready to present
Includes all of Packages 1 & 2, plus
Yes. The original project file is a ZIP containing the complete analisis.R script, a data_contoh.csv sample dataset and a BACA-DULU.txt guide. It can be downloaded after payment, and we send it by WhatsApp or email. For your own data (Package 2 and 3) the script is adapted to your dataset.
Yes. XGBoost is commonly used at this level in Informatics and Information Systems. We adapt the analysis to your research question, your own data and your supervisor's requirements.
No. The sheet is computed from illustrative synthetic data so you can see the kind of output R Studio gives. For your order we run the same method on your own data.
That is the point of the packages. Every script is commented, and Package 3 includes two coaching sessions plus practice questions so you can explain the method and the results at your seminar and defence.
Each project has three packages: Package 1 (code and explanation) US$31, Package 2 (your data analysis and interpretation) US$88 and Package 3 (full guidance) US$194, excluding 11% VAT. Larger datasets, extra methods or tight deadlines adjust the quote after a short consultation.
The result sheet uses illustrative synthetic data. R is a programming language of the R Foundation project; RStudio and Posit are trademarks of Posit PBC.
Back to R Studio portfolio