Git Product home page Git Product logo

boost-loss's Introduction

Boost Loss

CI Status Documentation Status Test coverage percentage

Poetry black pre-commit

PyPI Version Supported Python versions License

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. 1

from boost_loss.regression import LogCoshLoss
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
34j

๐Ÿ’ป ๐Ÿค” ๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

Footnotes

  1. Inspired by orchardbirds/bokbokbok โ†ฉ

  2. Inspired by TomerRonen34/treeboost_autograd โ†ฉ

boost-loss's People

Contributors

34j avatar pre-commit-ci[bot] avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

boost-loss's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Use matchDepNames instead of matchPackageNames

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update pre-commit hook asottile/pyupgrade to v3.15.2
  • chore(deps): update pre-commit hook pycqa/bandit to v1.7.8
  • chore(deps): update dependency pre-commit to v3.7.0
  • chore(deps): update dependency sphinx to v7.3.7
  • chore(deps): update dependency torch to v2.3.0
  • chore(deps): update pre-commit hook commitizen-tools/commitizen to v3.25.0
  • chore(deps): update pre-commit hook pre-commit/mirrors-mypy to v1.10.0
  • chore(deps): update pre-commit hook pre-commit/pre-commit-hooks to v4.6.0
  • chore(deps): update pre-commit hook pycqa/autoflake to v2.3.1
  • chore(deps): update pre-commit hook python-poetry/poetry to v1.8.2
  • chore(deps): update wagoid/commitlint-github-action action to v5.5.1
  • fix(deps): update dependency scikit-learn to v1.4.2
  • chore(deps): update dependency pytest-cov to v5
  • chore(deps): update wagoid/commitlint-github-action action to v6
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • actions/setup-python v4
  • pre-commit/action v3.0.0
  • actions/checkout v3
  • wagoid/commitlint-github-action v5.4.5
  • actions/checkout v3
  • actions/setup-python v4
  • snok/install-poetry v1.3.4
  • codecov/codecov-action v3
  • actions/checkout v3
  • relekang/python-semantic-release v7.34.6
  • relekang/python-semantic-release v7.34.6
.github/workflows/hacktoberfest.yml
  • browniebroke/hacktoberfest-labeler-action v2.3.0
.github/workflows/issue-manager.yml
  • tiangolo/issue-manager 0.5.0
.github/workflows/labels.yml
  • actions/checkout v3
  • actions/setup-python v4
.github/workflows/poetry-upgrade.yml
  • browniebroke/github-actions v1
pep621
pyproject.toml
  • poetry-core >=1.0.0
poetry
pyproject.toml
  • python ^3.8
  • xgboost ^2.0.0
  • lightgbm ^4.0.0
  • pyhumps ^3.8.0
  • attrs ^23.1.0
  • scikit-learn ^1.3.2
  • pre-commit >=3
  • pytest ^7.0
  • pytest-cov ^4.0.0
  • parameterized ^0.9.0
  • myst-parser >=0.16
  • sphinx >=4.0
  • sphinx-rtd-theme >=1.0
  • torch ^2.0.1
pre-commit
.pre-commit-config.yaml
  • commitizen-tools/commitizen v3.14.1
  • pre-commit/pre-commit-hooks v4.5.0
  • python-poetry/poetry 1.7.1
  • pre-commit/mirrors-prettier v3.0.3
  • asottile/pyupgrade v3.15.0
  • PyCQA/autoflake v2.2.1
  • PyCQA/isort 5.13.2
  • psf/black 23.12.1
  • codespell-project/codespell v2.2.6
  • PyCQA/flake8 6.1.0
  • pre-commit/mirrors-mypy v1.8.0
  • PyCQA/bandit 1.7.7
  • srstevenson/nb-clean 3.2.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.