🤖 AI/ML

LightGBM

Light Gradient Boosting Machine

Microsoft's gradient boosting. Efficient on large-scale data.

📖 Detailed Explanation

LightGBM (Light Gradient Boosting Machine) is a high-performance gradient boosting framework developed by Microsoft. It is a decision-tree-based ensemble learning algorithm and, together with XGBoost, is the most widely used algorithm in ML competitions such as Kaggle.

Announced in a 2017 NIPS paper, LightGBM was developed to solve the slow training speed of the existing GBDT (Gradient Boosting Decision Tree). It introduced a histogram-based algorithm and a Leaf-wise growth strategy, greatly improving speed and memory efficiency.

LightGBM's core techniques are GOSS (Gradient-based One-Side Sampling) and EFB (Exclusive Feature Bundling). GOSS prioritizes training on samples with large gradients, and EFB bundles sparse features to reduce dimensionality. This allows it to train quickly even on large datasets of more than 100 million rows.

In practice, LightGBM is used at the core of tabular-data ML problems such as CTR prediction, fraud detection, and recommendation systems. With GPU training support, automatic handling of categorical features, and parallel/distributed training, it is also widely used in enterprise environments.

💻 Code Example

import lightgbm as lgb
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_breast_cancer
from sklearn.metrics import accuracy_score, roc_auc_score

# 데이터 로드
data = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(
    data.data, data.target, test_size=0.2, random_state=42
)

# LightGBM 데이터셋 생성
train_data = lgb.Dataset(X_train, label=y_train)
valid_data = lgb.Dataset(X_test, label=y_test, reference=train_data)

# 하이퍼파라미터 설정
params = {
    'objective': 'binary',
    'metric': 'auc',
    'boosting_type': 'gbdt',
    'num_leaves': 31,
    'learning_rate': 0.05,
    'feature_fraction': 0.8,
    'bagging_fraction': 0.8,
    'bagging_freq': 5,
    'verbose': -1
}

# 모델 학습 (Early Stopping 적용)
model = lgb.train(
    params,
    train_data,
    num_boost_round=1000,
    valid_sets=[valid_data],
    callbacks=[lgb.early_stopping(50), lgb.log_evaluation(100)]
)

# 예측 및 평가
y_pred = model.predict(X_test)
y_pred_binary = [1 if p > 0.5 else 0 for p in y_pred]

print(f"Accuracy: {accuracy_score(y_test, y_pred_binary):.4f}")
print(f"AUC: {roc_auc_score(y_test, y_pred):.4f}")

# 피처 중요도 확인
importance = model.feature_importance(importance_type='gain')
print(f"Top 5 Features: {sorted(zip(data.feature_names, importance), key=lambda x: -x[1])[:5]}")

🗣️ Say It Like This in Practice

💬 In a Meeting
"We built this CTR prediction model with LightGBM. We processed 100 million training rows in 30 minutes and achieved an AUC of 0.82. Feature importance analysis showed that user session length was the most important variable."
💬 In an Interview
"LightGBM uses Leaf-wise tree growth, so it can efficiently build deeper trees than XGBoost's Level-wise approach. However, there is a risk of overfitting, so you need to tune num_leaves and max_depth appropriately."
💬 In a Technical Discussion
"For data with many categorical features, it's best to use LightGBM's categorical_feature option. It trains faster and uses less memory than one-hot encoding. With GOSS sampling, it also processes large datasets 2-3x faster than XGBoost."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Setting num_leaves too large

A large num_leaves makes trees deeper and causes overfitting. It should usually be set smaller than 2^max_depth.

✅
Correct setting

Start num_leaves between 31 and 127, and always use early_stopping. Use validation data to find the optimal number of iterations automatically.

🔗 Related Terms

📚 Learn More