Utilities for easy use of custom losses in CatBoost, LightGBM, XGBoost
Project description
Boost Loss
Utilities for easy use of custom losses in CatBoost, LightGBM, XGBoost. This sounds very simple, but in reality it took a lot of work.
Installation
Install this via pip (or your favourite package manager):
pip install boost-loss
Usage
Basic Usage
import numpy as np
from boost_loss import LossBase
from numpy.typing import NDArray
class L2Loss(LossBase):
def loss(self, y_true: NDArray, y_pred: NDArray) -> NDArray:
return (y_true - y_pred) ** 2 / 2
def grad(self, y_true: NDArray, y_pred: NDArray) -> NDArray: # dL/dy_pred
return - (y_true - y_pred)
def hess(self, y_true: NDArray, y_pred: NDArray) -> NDArray: # d^2L/dy_pred^2
return np.ones_like(y_true)
import lightgbm as lgb
from boost_loss import apply_custom_loss
from sklearn.datasets import load_boston
X, y = load_boston(return_X_y=True)
apply_custom_loss(lgb.LGBMRegressor(), L2Loss()).fit(X, y)
Built-in losses are available. [^bokbokbok]
from boost_loss.regression import LogCoshLoss
torch.autograd Loss [^autograd]
import torch
from boost_loss.torch import TorchLossBase
class L2LossTorch(TorchLossBase):
def loss_torch(self, y_true: torch.Tensor, y_pred: torch.Tensor) -> torch.Tensor:
return (y_true - y_pred) ** 2 / 2
Contributors ✨
Thanks goes to these wonderful people (emoji key):
34j 💻 🤔 📖 |
This project follows the all-contributors specification. Contributions of any kind welcome!
[^bokbokbok]: Inspired by orchardbirds/bokbokbok [^autograd]: Inspired by TomerRonen34/treeboost_autograd
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file boost_loss-0.5.5.tar.gz.
File metadata
- Download URL: boost_loss-0.5.5.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/42.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.1.0 tqdm/4.66.1 importlib-metadata/7.0.1 keyring/24.3.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b301e6a8b711a9ef40c02fce478426fcbf7eeba9073b9a6c2dc5d859230baf05
|
|
| MD5 |
284639f1df99d46df2abe2057f2174e1
|
|
| BLAKE2b-256 |
aecf849acb3e7bd97018d1c9764343e27debd89795e6f900cd89c30f978ab428
|
File details
Details for the file boost_loss-0.5.5-py3-none-any.whl.
File metadata
- Download URL: boost_loss-0.5.5-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/42.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.1.0 tqdm/4.66.1 importlib-metadata/7.0.1 keyring/24.3.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1967f08dc2f3c3cffdefdf996a1e9c1ddc69c37f41ea818b7cf6a50f35d3bb35
|
|
| MD5 |
60fe0ffbb82414b9dbcad7dadabfcfb7
|
|
| BLAKE2b-256 |
8248ec77613130aa71b09ca48bbafc0486771542e1c8de666b0b44d713e647e0
|