분류, 회귀모델을 만들 때 가장 많이 사용한 프레임워크는 LGBM인데요.
LGBM은 마이크로소프트웨어에서 관리하고 있는 그레디언트 부스팅 프레임워크 입니다.
https://github.com/microsoft/LightGBM
GitHub - microsoft/LightGBM: A fast, distributed, high performance gradient boosting (GBT, GBDT, GBRT, GBM or MART) framework ba
A fast, distributed, high performance gradient boosting (GBT, GBDT, GBRT, GBM or MART) framework based on decision tree algorithms, used for ranking, classification and many other machine learning ...
github.com
LGBM을 많이 써 본 후 유용했던 특징은 다음과 같습니다.
- 사실 튜닝할 수 있는 파라미터가 아주 많이 있어서 고려할 사항이 많음 그럼에도 튜닝을 세세하게 하지 않아도, 다른 모델에 비해 어느 정도 성능이 잘 나옴
- 데이터가 불균등한 경우 다음의 옵션을 사용하면 좋은 성능을 가져 올 수 있음 pos_waight is_unbalance
- 범주형 데이터 처리 가능(내부적으로 그룹핑을 통해서 처리)
그러다가 FLAML을 알게 되었는데요.
https://github.com/microsoft/FLAML
GitHub - microsoft/FLAML: A fast library for AutoML and tuning.
A fast library for AutoML and tuning. Contribute to microsoft/FLAML development by creating an account on GitHub.
github.com
너무 많은 관심이 가서 사용 & 정리를 해 보았습니다.
FLAML
자동으로, 효율적으로, 경제적으로 머신러닝을 찾는 가벼운 파이썬 라이브러리 입니다.
사용자는 모델과, 모델의 하이퍼 파라미터를 선택할 필요가 없습니다.
Main Features
- 사용자가 주는 데이터에 대해, 빠르고 적은 리소스를 사용해서 좋은 성능을 가진 모델을 찾아줍니다. 이 모델은 머신러닝과 딥러닝을 모두 포함하고 있습니다.
- 맞춤제작과 확장에 용이합니다. 사용자는 매끄럽게 설정을 할 수 있습니다.
최소 수준 → 컴퓨팅 리소스 중간 수준 → 사이킷런 기반 모델, 메트릭, 알고리즘 탐색 공간 최고 수준 → 임의 학습 / 평가 코드 - 검색 공간을 처리 할 수 있는 경제적인 오토 튜닝을 지원합니다. ML에서 개발한 매우 효율적인 하이퍼 마라미터 최적화와 학습 모델 선택 방법을 기반으로 합니다.
더 관심이 있으시면, 다음을 보시면 됩니다
코드 예제는 다음과 같습니다.
https://microsoft.github.io/FLAML/docs/getting-started
1. 이렇게 모델링을 진행 할 수 있습니다.
from flaml import AutoML
automl = AutoML()
automl.fit(X_train, y_train, task="classification", time_budget=60)
지정된 시간동안 자동으로 하이퍼파라미터를 튜닝하고, 일반적인 신경망 모델을 포함한 LightGBM, XGBoost, 랜덤포레스트 등의 모델에서 자동으로 모델을 선택합니다.
2. 모델 튜닝을 위한 함수도 제공합니다.
from flaml import tune
from flaml.model import LGBMEstimator
def train_lgbm(config: dict) -> dict:
# convert config dict to lgbm params
params = LGBMEstimator(**config).params
# train the model
train_set = lightgbm.Dataset(csv_file_name)
model = lightgbm.train(params, train_set)
# evaluate the model
pred = model.predict(X_test)
mse = mean_squared_error(y_test, pred)
# return eval results as a dictionary
return {"mse": mse}
# load a built-in search space from flaml
flaml_lgbm_search_space = LGBMEstimator.search_space(X_train.shape)
# specify the search space as a dict from hp name to domain; you can define your own search space same way
config_search_space = {hp: space["domain"] for hp, space in flaml_lgbm_search_space.items()}
# give guidance about hp values corresponding to low training cost, i.e., {"n_estimators": 4, "num_leaves": 4}
low_cost_partial_config = {
hp: space["low_cost_init_value"]
for hp, space in flaml_lgbm_search_space.items()
if "low_cost_init_value" in space
}
# run the tuning, minimizing mse, with total time budget 3 seconds
analysis = tune.run(
train_lgbm, metric="mse", mode="min", config=config_search_space,
low_cost_partial_config=low_cost_partial_config, time_budget_s=3, num_samples=-1,
)
사용 후기
https://microsoft.github.io/FLAML/docs/Examples/AutoML-Classification
AutoML로 지원하는 모델은 다음과 같습니다.
Classification, NLP, Rank, Regression, Time Series Forecast,
task 옵션으로 모델의 유형을 선택할 수 있으며, time_budget으로 탐색시간을 설정 할 수 있습니다.
사용 후기는 다음과 같습니다.
- 어떠한 파라미터 설정 없이 준수한 성능의 모델을 만들 수 있습니다.
- time_budget 값이 정확하게 시간을 맞춰주지 않습니다.
크면 클 수록 좋은 모델을 가져오기 때문에 적당한 시간으로 설정 후, 테스트를 완료 한 후에 넉넉하게 잡고 진행하시길 바랍니다. - 데이터의 양이 매우 많아 학습된 모델에 이어서 학습을 진행했었을 때는 설정한 시간 이상으로 매우 많은 시간이 소요되었습니다.
- 모델의 저장 & 불러오기는 joblib를 사용했습니다.
- 캐글과 데이콘을 할 때 매우 유용하게 사용할 수 있을듯 합니다.
'Machine Learning > 기타' 카테고리의 다른 글
2024년에 한 생각과 2025년에 할 생각, 머신러닝 엔지니어는 어디로 가야 하는가? (0) | 2024.12.31 |
---|---|
DeepTrax: 트랜잭션 데이터 임베딩 구현 및 시각화 해보기 (0) | 2024.12.03 |
시계열 분류 모델을 위한 딥러닝 아키텍쳐 (0) | 2022.11.06 |