penguinboost 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- penguinboost-0.3.3/LICENSE +21 -0
- penguinboost-0.3.3/MANIFEST.in +17 -0
- penguinboost-0.3.3/NOTICE +121 -0
- penguinboost-0.3.3/PKG-INFO +214 -0
- penguinboost-0.3.3/README.md +161 -0
- penguinboost-0.3.3/penguinboost/__init__.py +61 -0
- penguinboost-0.3.3/penguinboost/core/__init__.py +0 -0
- penguinboost-0.3.3/penguinboost/core/binning.py +129 -0
- penguinboost-0.3.3/penguinboost/core/boosting.py +588 -0
- penguinboost-0.3.3/penguinboost/core/categorical.py +101 -0
- penguinboost-0.3.3/penguinboost/core/dart.py +98 -0
- penguinboost-0.3.3/penguinboost/core/era_boost.py +195 -0
- penguinboost-0.3.3/penguinboost/core/financial.py +196 -0
- penguinboost-0.3.3/penguinboost/core/histogram.py +257 -0
- penguinboost-0.3.3/penguinboost/core/monotone.py +52 -0
- penguinboost-0.3.3/penguinboost/core/neutralization.py +205 -0
- penguinboost-0.3.3/penguinboost/core/regularization.py +126 -0
- penguinboost-0.3.3/penguinboost/core/sampling.py +61 -0
- penguinboost-0.3.3/penguinboost/core/tree.py +518 -0
- penguinboost-0.3.3/penguinboost/cpp/_core.cpp +473 -0
- penguinboost-0.3.3/penguinboost/metrics/__init__.py +0 -0
- penguinboost-0.3.3/penguinboost/metrics/metrics.py +183 -0
- penguinboost-0.3.3/penguinboost/objectives/__init__.py +17 -0
- penguinboost-0.3.3/penguinboost/objectives/classification.py +79 -0
- penguinboost-0.3.3/penguinboost/objectives/corr.py +311 -0
- penguinboost-0.3.3/penguinboost/objectives/quantile.py +82 -0
- penguinboost-0.3.3/penguinboost/objectives/ranking.py +125 -0
- penguinboost-0.3.3/penguinboost/objectives/regression.py +70 -0
- penguinboost-0.3.3/penguinboost/objectives/survival.py +102 -0
- penguinboost-0.3.3/penguinboost/sklearn_api.py +529 -0
- penguinboost-0.3.3/penguinboost/utils.py +33 -0
- penguinboost-0.3.3/penguinboost.egg-info/PKG-INFO +214 -0
- penguinboost-0.3.3/penguinboost.egg-info/SOURCES.txt +39 -0
- penguinboost-0.3.3/penguinboost.egg-info/dependency_links.txt +1 -0
- penguinboost-0.3.3/penguinboost.egg-info/requires.txt +5 -0
- penguinboost-0.3.3/penguinboost.egg-info/top_level.txt +5 -0
- penguinboost-0.3.3/pyproject.toml +71 -0
- penguinboost-0.3.3/setup.cfg +4 -0
- penguinboost-0.3.3/setup.py +143 -0
- penguinboost-0.3.3/tests/bench_vs_lightgbm.py +338 -0
- penguinboost-0.3.3/tests/test_penguinboost.py +1763 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 S.I
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include NOTICE
|
|
4
|
+
include pyproject.toml
|
|
5
|
+
include setup.py
|
|
6
|
+
|
|
7
|
+
# C++ ソース・ヘッダー(sdist からビルドできるよう含める)
|
|
8
|
+
recursive-include penguinboost/cpp *.cpp *.h *.hpp
|
|
9
|
+
|
|
10
|
+
# テスト(任意)
|
|
11
|
+
recursive-include tests *.py
|
|
12
|
+
|
|
13
|
+
# 生成物は除外
|
|
14
|
+
global-exclude __pycache__
|
|
15
|
+
global-exclude *.py[cod]
|
|
16
|
+
global-exclude *.so
|
|
17
|
+
global-exclude *.pyd
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
PenguinBoost
|
|
2
|
+
Copyright (c) 2026 S.I
|
|
3
|
+
|
|
4
|
+
This software is released under the MIT License.
|
|
5
|
+
See LICENSE for the full license text.
|
|
6
|
+
|
|
7
|
+
================================================================================
|
|
8
|
+
THIRD-PARTY LIBRARIES
|
|
9
|
+
================================================================================
|
|
10
|
+
|
|
11
|
+
This software depends on the following third-party libraries at runtime or
|
|
12
|
+
build time. Their respective licenses are listed below.
|
|
13
|
+
|
|
14
|
+
--------------------------------------------------------------------------------
|
|
15
|
+
pybind11
|
|
16
|
+
License : BSD 3-Clause
|
|
17
|
+
Copyright: Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>, and others
|
|
18
|
+
Source : https://github.com/pybind/pybind11
|
|
19
|
+
|
|
20
|
+
Redistribution and use in source and binary forms, with or without
|
|
21
|
+
modification, are permitted provided that the following conditions are met:
|
|
22
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
23
|
+
this list of conditions and the following disclaimer.
|
|
24
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
25
|
+
this list of conditions and the following disclaimer in the documentation
|
|
26
|
+
and/or other materials provided with the distribution.
|
|
27
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
28
|
+
may be used to endorse or promote products derived from this software
|
|
29
|
+
without specific prior written permission.
|
|
30
|
+
|
|
31
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
32
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
33
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
34
|
+
ARE DISCLAIMED.
|
|
35
|
+
|
|
36
|
+
--------------------------------------------------------------------------------
|
|
37
|
+
NumPy
|
|
38
|
+
License : BSD 3-Clause
|
|
39
|
+
Copyright: Copyright (c) 2005-2024, NumPy Developers
|
|
40
|
+
Source : https://github.com/numpy/numpy
|
|
41
|
+
|
|
42
|
+
--------------------------------------------------------------------------------
|
|
43
|
+
scikit-learn
|
|
44
|
+
License : BSD 3-Clause
|
|
45
|
+
Copyright: Copyright (c) 2007-2024, scikit-learn developers
|
|
46
|
+
Source : https://github.com/scikit-learn/scikit-learn
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
================================================================================
|
|
50
|
+
ALGORITHMIC REFERENCES
|
|
51
|
+
================================================================================
|
|
52
|
+
|
|
53
|
+
PenguinBoost implements algorithms and techniques described in the following
|
|
54
|
+
papers and projects. No source code was copied from these projects; this
|
|
55
|
+
section serves as attribution for the ideas and methods used.
|
|
56
|
+
|
|
57
|
+
--------------------------------------------------------------------------------
|
|
58
|
+
XGBoost
|
|
59
|
+
Project : https://github.com/dmlc/xgboost
|
|
60
|
+
License : Apache 2.0
|
|
61
|
+
Reference:
|
|
62
|
+
Tianqi Chen and Carlos Guestrin.
|
|
63
|
+
"XGBoost: A Scalable Tree Boosting System."
|
|
64
|
+
Proceedings of the 22nd ACM SIGKDD International Conference on
|
|
65
|
+
Knowledge Discovery and Data Mining (KDD), 2016.
|
|
66
|
+
https://arxiv.org/abs/1603.02754
|
|
67
|
+
|
|
68
|
+
Techniques used in PenguinBoost:
|
|
69
|
+
- L1/L2 regularized leaf weight formula
|
|
70
|
+
- Second-order gradient (hessian) based split gain
|
|
71
|
+
- Minimum child weight / minimum child samples constraints
|
|
72
|
+
|
|
73
|
+
--------------------------------------------------------------------------------
|
|
74
|
+
LightGBM
|
|
75
|
+
Project : https://github.com/microsoft/LightGBM
|
|
76
|
+
License : MIT
|
|
77
|
+
Reference:
|
|
78
|
+
Guolin Ke, Qi Meng, Thomas Finley, Taifeng Wang, Wei Chen, Weidong Ma,
|
|
79
|
+
Qiwei Ye, and Tie-Yan Liu.
|
|
80
|
+
"LightGBM: A Highly Efficient Gradient Boosting Decision Tree."
|
|
81
|
+
Advances in Neural Information Processing Systems (NeurIPS), 2017.
|
|
82
|
+
https://papers.nips.cc/paper/2017/hash/6449f44a102fde848669bdd9eb6b76fa-Abstract.html
|
|
83
|
+
|
|
84
|
+
Techniques used in PenguinBoost:
|
|
85
|
+
- Histogram-based split finding with bin subtraction trick
|
|
86
|
+
- Leaf-wise (best-first) tree growth
|
|
87
|
+
- Gradient-based One-Side Sampling (GOSS)
|
|
88
|
+
- Exclusive Feature Bundling (EFB)
|
|
89
|
+
- NaN bin handling
|
|
90
|
+
|
|
91
|
+
--------------------------------------------------------------------------------
|
|
92
|
+
CatBoost
|
|
93
|
+
Project : https://github.com/catboost/catboost
|
|
94
|
+
License : Apache 2.0
|
|
95
|
+
Reference:
|
|
96
|
+
Liudmila Prokhorenkova, Gleb Gusev, Aleksandr Vorobev,
|
|
97
|
+
Anna Veronika Dorogush, and Andrey Gulin.
|
|
98
|
+
"CatBoost: unbiased boosting with categorical features."
|
|
99
|
+
Advances in Neural Information Processing Systems (NeurIPS), 2018.
|
|
100
|
+
https://arxiv.org/abs/1706.09516
|
|
101
|
+
|
|
102
|
+
Techniques used in PenguinBoost:
|
|
103
|
+
- Ordered (target statistic) boosting to reduce prediction shift
|
|
104
|
+
- Ordered target encoding for categorical features
|
|
105
|
+
- Symmetric (oblivious) tree growth
|
|
106
|
+
|
|
107
|
+
--------------------------------------------------------------------------------
|
|
108
|
+
Numerai
|
|
109
|
+
Project : https://numer.ai
|
|
110
|
+
GitHub : https://github.com/numerai
|
|
111
|
+
Forum : https://forum.numer.ai
|
|
112
|
+
Docs : https://docs.numer.ai
|
|
113
|
+
|
|
114
|
+
Techniques used in PenguinBoost (v3 financial ML features):
|
|
115
|
+
- Era-based cross-validation and per-era performance weighting
|
|
116
|
+
https://docs.numer.ai/numerai-tournament/scoring/correlation
|
|
117
|
+
- Feature neutralization (removing linearly feature-explainable
|
|
118
|
+
components from predictions)
|
|
119
|
+
https://docs.numer.ai/numerai-tournament/feature-neutralization
|
|
120
|
+
- Feature exposure penalty to reduce correlation with input features
|
|
121
|
+
- Sharpe ratio maximization across eras as a training objective
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: penguinboost
|
|
3
|
+
Version: 0.3.3
|
|
4
|
+
Summary: Hybrid gradient boosting fusing LightGBM, CatBoost, and XGBoost techniques with financial-specific overfitting resistance.
|
|
5
|
+
Author-email: "S.I" <test_api_ai@proton.me>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 S.I
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/test-api-ai/penguinboost
|
|
29
|
+
Project-URL: Repository, https://github.com/test-api-ai/penguinboost.git
|
|
30
|
+
Project-URL: Bug Tracker, https://github.com/test-api-ai/penguinboost/issues
|
|
31
|
+
Keywords: gradient boosting,gbdt,machine learning,xgboost,lightgbm,catboost,finance,numerai,quantitative
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Intended Audience :: Science/Research
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Programming Language :: C++
|
|
42
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
43
|
+
Classifier: Operating System :: OS Independent
|
|
44
|
+
Requires-Python: >=3.9
|
|
45
|
+
Description-Content-Type: text/markdown
|
|
46
|
+
License-File: LICENSE
|
|
47
|
+
License-File: NOTICE
|
|
48
|
+
Requires-Dist: numpy>=1.21
|
|
49
|
+
Requires-Dist: scikit-learn>=1.0
|
|
50
|
+
Provides-Extra: dev
|
|
51
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
52
|
+
Dynamic: license-file
|
|
53
|
+
|
|
54
|
+
# PenguinBoost
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## 必要環境
|
|
58
|
+
|
|
59
|
+
| 要件 | バージョン |
|
|
60
|
+
|---|---|
|
|
61
|
+
| Python | >= 3.9 |
|
|
62
|
+
| NumPy | >= 1.21 |
|
|
63
|
+
| scikit-learn | >= 1.0 |
|
|
64
|
+
| C++ コンパイラ | C++17 対応(GCC 7+ / Clang 5+ / MSVC 2017+) |
|
|
65
|
+
| pybind11 | >= 2.10(ビルド時のみ) |
|
|
66
|
+
|
|
67
|
+
> **注意:** コアの計算エンジンは C++ で実装されており、インストール時に C++ のコンパイルが行われます。コンパイラが事前にインストールされている必要があります。
|
|
68
|
+
> - macOS: `xcode-select --install`
|
|
69
|
+
> - Ubuntu/Debian: `sudo apt install build-essential`
|
|
70
|
+
> - Windows: Visual Studio Build Tools(C++ ワークロード付き)
|
|
71
|
+
|
|
72
|
+
## インストール
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# pybind11 を先にインストール
|
|
76
|
+
pip install pybind11
|
|
77
|
+
|
|
78
|
+
# ソースからインストール(C++ 拡張モジュールがビルドされます)
|
|
79
|
+
git clone https://github.com/test-api-ai/penguinboost.git
|
|
80
|
+
cd penguinboost
|
|
81
|
+
pip install .
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
開発用(編集可能インストール):
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pip install -e ".[dev]"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## クイックスタート
|
|
91
|
+
|
|
92
|
+
### 回帰
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from penguinboost import PenguinBoostRegressor
|
|
96
|
+
from sklearn.datasets import make_regression
|
|
97
|
+
from sklearn.model_selection import train_test_split
|
|
98
|
+
from sklearn.metrics import mean_squared_error
|
|
99
|
+
|
|
100
|
+
X, y = make_regression(n_samples=1000, n_features=20, random_state=42)
|
|
101
|
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
|
102
|
+
|
|
103
|
+
model = PenguinBoostRegressor(
|
|
104
|
+
n_estimators=200,
|
|
105
|
+
learning_rate=0.05,
|
|
106
|
+
max_depth=6,
|
|
107
|
+
random_state=42,
|
|
108
|
+
)
|
|
109
|
+
model.fit(X_train, y_train)
|
|
110
|
+
|
|
111
|
+
pred = model.predict(X_test)
|
|
112
|
+
print(f"MSE: {mean_squared_error(y_test, pred):.4f}")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### クラス分類
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from penguinboost import PenguinBoostClassifier
|
|
119
|
+
from sklearn.datasets import make_classification
|
|
120
|
+
from sklearn.model_selection import train_test_split
|
|
121
|
+
from sklearn.metrics import accuracy_score
|
|
122
|
+
|
|
123
|
+
X, y = make_classification(n_samples=1000, n_features=20, random_state=42)
|
|
124
|
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
|
125
|
+
|
|
126
|
+
clf = PenguinBoostClassifier(
|
|
127
|
+
n_estimators=200,
|
|
128
|
+
learning_rate=0.05,
|
|
129
|
+
max_depth=6,
|
|
130
|
+
random_state=42,
|
|
131
|
+
)
|
|
132
|
+
clf.fit(X_train, y_train)
|
|
133
|
+
|
|
134
|
+
pred = clf.predict(X_test)
|
|
135
|
+
print(f"Accuracy: {accuracy_score(y_test, pred):.4f}")
|
|
136
|
+
|
|
137
|
+
# クラス確率を取得
|
|
138
|
+
proba = clf.predict_proba(X_test) # shape=(n_samples, n_classes)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## 主な機能
|
|
142
|
+
|
|
143
|
+
- **多様な学習タスク**: 回帰・二値/多クラス分類・ランキング・生存分析・分位点回帰
|
|
144
|
+
- **4種の木成長戦略**: `leafwise`(LightGBM 式)、`symmetric`(CatBoost 式)、`depthwise`、`hybrid`
|
|
145
|
+
- **過学習対策**: DART、勾配摂動、ベイズ適応正則化、単調制約
|
|
146
|
+
- **金融特化機能**: Era Boosting、特徴量中立化、直交勾配射影、MaxSharpe 目的関数
|
|
147
|
+
- **scikit-learn 互換**: `Pipeline`・`cross_val_score` 等とシームレスに連携
|
|
148
|
+
|
|
149
|
+
詳細は [`docs/USAGE.md`](docs/USAGE.md) を参照してください。
|
|
150
|
+
|
|
151
|
+
## テスト
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
pip install -e ".[dev]"
|
|
155
|
+
pytest tests/
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## ライセンス
|
|
159
|
+
|
|
160
|
+
MIT License — Copyright (c) 2026 S.I
|
|
161
|
+
|
|
162
|
+
詳細は [LICENSE](LICENSE) を参照してください。
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## 使用ライブラリ・著作権表示
|
|
167
|
+
|
|
168
|
+
PenguinBoost は以下のサードパーティライブラリを使用しています。
|
|
169
|
+
|
|
170
|
+
### ランタイム依存
|
|
171
|
+
|
|
172
|
+
| ライブラリ | ライセンス | 著作権 |
|
|
173
|
+
|---|---|---|
|
|
174
|
+
| [NumPy](https://github.com/numpy/numpy) | BSD 3-Clause | Copyright (c) 2005-2024, NumPy Developers |
|
|
175
|
+
| [scikit-learn](https://github.com/scikit-learn/scikit-learn) | BSD 3-Clause | Copyright (c) 2007-2024, scikit-learn developers |
|
|
176
|
+
|
|
177
|
+
### ビルド時依存
|
|
178
|
+
|
|
179
|
+
| ライブラリ | ライセンス | 著作権 |
|
|
180
|
+
|---|---|---|
|
|
181
|
+
| [pybind11](https://github.com/pybind/pybind11) | BSD 3-Clause | Copyright (c) 2016 Wenzel Jakob and others |
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## アルゴリズム参照・著作権表示
|
|
186
|
+
|
|
187
|
+
PenguinBoost は以下のプロジェクトで発表されたアルゴリズムや手法を参考に実装しています。
|
|
188
|
+
|
|
189
|
+
### XGBoost
|
|
190
|
+
|
|
191
|
+
- **Project**: https://github.com/dmlc/xgboost
|
|
192
|
+
- **License**: Apache 2.0
|
|
193
|
+
- **Reference**: Tianqi Chen and Carlos Guestrin. "XGBoost: A Scalable Tree Boosting System." KDD 2016. https://arxiv.org/abs/1603.02754
|
|
194
|
+
- **参考にした手法**: L1/L2 正則化付き葉の重み計算式、ヘシアンベースの分割ゲイン、最小子ノード制約
|
|
195
|
+
|
|
196
|
+
### LightGBM
|
|
197
|
+
|
|
198
|
+
- **Project**: https://github.com/microsoft/LightGBM
|
|
199
|
+
- **License**: MIT
|
|
200
|
+
- **Reference**: Guolin Ke et al. "LightGBM: A Highly Efficient Gradient Boosting Decision Tree." NeurIPS 2017. https://papers.nips.cc/paper/2017/hash/6449f44a102fde848669bdd9eb6b76fa-Abstract.html
|
|
201
|
+
- **参考にした手法**: ヒストグラムベース分割探索・差分トリック、Leaf-wise 木成長、GOSS(勾配ベースサンプリング)、EFB(排他的特徴量バンドリング)
|
|
202
|
+
|
|
203
|
+
### CatBoost
|
|
204
|
+
|
|
205
|
+
- **Project**: https://github.com/catboost/catboost
|
|
206
|
+
- **License**: Apache 2.0
|
|
207
|
+
- **Reference**: Liudmila Prokhorenkova et al. "CatBoost: unbiased boosting with categorical features." NeurIPS 2018. https://arxiv.org/abs/1706.09516
|
|
208
|
+
- **参考にした手法**: Ordered Boosting(予測シフト低減)、Ordered Target Encoding(カテゴリカル特徴量)、対称木(Oblivious Tree)成長
|
|
209
|
+
|
|
210
|
+
### Numerai
|
|
211
|
+
|
|
212
|
+
- **Project**: https://numer.ai
|
|
213
|
+
- **GitHub**: https://github.com/numerai
|
|
214
|
+
- **参考にした手法**: Era ベースのクロスバリデーションと per-era 性能加重、特徴量中立化(線形特徴量成分の除去)、特徴量露出ペナルティ、Era 間 Sharpe 比最大化
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# PenguinBoost
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## 必要環境
|
|
5
|
+
|
|
6
|
+
| 要件 | バージョン |
|
|
7
|
+
|---|---|
|
|
8
|
+
| Python | >= 3.9 |
|
|
9
|
+
| NumPy | >= 1.21 |
|
|
10
|
+
| scikit-learn | >= 1.0 |
|
|
11
|
+
| C++ コンパイラ | C++17 対応(GCC 7+ / Clang 5+ / MSVC 2017+) |
|
|
12
|
+
| pybind11 | >= 2.10(ビルド時のみ) |
|
|
13
|
+
|
|
14
|
+
> **注意:** コアの計算エンジンは C++ で実装されており、インストール時に C++ のコンパイルが行われます。コンパイラが事前にインストールされている必要があります。
|
|
15
|
+
> - macOS: `xcode-select --install`
|
|
16
|
+
> - Ubuntu/Debian: `sudo apt install build-essential`
|
|
17
|
+
> - Windows: Visual Studio Build Tools(C++ ワークロード付き)
|
|
18
|
+
|
|
19
|
+
## インストール
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# pybind11 を先にインストール
|
|
23
|
+
pip install pybind11
|
|
24
|
+
|
|
25
|
+
# ソースからインストール(C++ 拡張モジュールがビルドされます)
|
|
26
|
+
git clone https://github.com/test-api-ai/penguinboost.git
|
|
27
|
+
cd penguinboost
|
|
28
|
+
pip install .
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
開発用(編集可能インストール):
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install -e ".[dev]"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## クイックスタート
|
|
38
|
+
|
|
39
|
+
### 回帰
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from penguinboost import PenguinBoostRegressor
|
|
43
|
+
from sklearn.datasets import make_regression
|
|
44
|
+
from sklearn.model_selection import train_test_split
|
|
45
|
+
from sklearn.metrics import mean_squared_error
|
|
46
|
+
|
|
47
|
+
X, y = make_regression(n_samples=1000, n_features=20, random_state=42)
|
|
48
|
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
|
49
|
+
|
|
50
|
+
model = PenguinBoostRegressor(
|
|
51
|
+
n_estimators=200,
|
|
52
|
+
learning_rate=0.05,
|
|
53
|
+
max_depth=6,
|
|
54
|
+
random_state=42,
|
|
55
|
+
)
|
|
56
|
+
model.fit(X_train, y_train)
|
|
57
|
+
|
|
58
|
+
pred = model.predict(X_test)
|
|
59
|
+
print(f"MSE: {mean_squared_error(y_test, pred):.4f}")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### クラス分類
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from penguinboost import PenguinBoostClassifier
|
|
66
|
+
from sklearn.datasets import make_classification
|
|
67
|
+
from sklearn.model_selection import train_test_split
|
|
68
|
+
from sklearn.metrics import accuracy_score
|
|
69
|
+
|
|
70
|
+
X, y = make_classification(n_samples=1000, n_features=20, random_state=42)
|
|
71
|
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
|
72
|
+
|
|
73
|
+
clf = PenguinBoostClassifier(
|
|
74
|
+
n_estimators=200,
|
|
75
|
+
learning_rate=0.05,
|
|
76
|
+
max_depth=6,
|
|
77
|
+
random_state=42,
|
|
78
|
+
)
|
|
79
|
+
clf.fit(X_train, y_train)
|
|
80
|
+
|
|
81
|
+
pred = clf.predict(X_test)
|
|
82
|
+
print(f"Accuracy: {accuracy_score(y_test, pred):.4f}")
|
|
83
|
+
|
|
84
|
+
# クラス確率を取得
|
|
85
|
+
proba = clf.predict_proba(X_test) # shape=(n_samples, n_classes)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 主な機能
|
|
89
|
+
|
|
90
|
+
- **多様な学習タスク**: 回帰・二値/多クラス分類・ランキング・生存分析・分位点回帰
|
|
91
|
+
- **4種の木成長戦略**: `leafwise`(LightGBM 式)、`symmetric`(CatBoost 式)、`depthwise`、`hybrid`
|
|
92
|
+
- **過学習対策**: DART、勾配摂動、ベイズ適応正則化、単調制約
|
|
93
|
+
- **金融特化機能**: Era Boosting、特徴量中立化、直交勾配射影、MaxSharpe 目的関数
|
|
94
|
+
- **scikit-learn 互換**: `Pipeline`・`cross_val_score` 等とシームレスに連携
|
|
95
|
+
|
|
96
|
+
詳細は [`docs/USAGE.md`](docs/USAGE.md) を参照してください。
|
|
97
|
+
|
|
98
|
+
## テスト
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pip install -e ".[dev]"
|
|
102
|
+
pytest tests/
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## ライセンス
|
|
106
|
+
|
|
107
|
+
MIT License — Copyright (c) 2026 S.I
|
|
108
|
+
|
|
109
|
+
詳細は [LICENSE](LICENSE) を参照してください。
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 使用ライブラリ・著作権表示
|
|
114
|
+
|
|
115
|
+
PenguinBoost は以下のサードパーティライブラリを使用しています。
|
|
116
|
+
|
|
117
|
+
### ランタイム依存
|
|
118
|
+
|
|
119
|
+
| ライブラリ | ライセンス | 著作権 |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| [NumPy](https://github.com/numpy/numpy) | BSD 3-Clause | Copyright (c) 2005-2024, NumPy Developers |
|
|
122
|
+
| [scikit-learn](https://github.com/scikit-learn/scikit-learn) | BSD 3-Clause | Copyright (c) 2007-2024, scikit-learn developers |
|
|
123
|
+
|
|
124
|
+
### ビルド時依存
|
|
125
|
+
|
|
126
|
+
| ライブラリ | ライセンス | 著作権 |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| [pybind11](https://github.com/pybind/pybind11) | BSD 3-Clause | Copyright (c) 2016 Wenzel Jakob and others |
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## アルゴリズム参照・著作権表示
|
|
133
|
+
|
|
134
|
+
PenguinBoost は以下のプロジェクトで発表されたアルゴリズムや手法を参考に実装しています。
|
|
135
|
+
|
|
136
|
+
### XGBoost
|
|
137
|
+
|
|
138
|
+
- **Project**: https://github.com/dmlc/xgboost
|
|
139
|
+
- **License**: Apache 2.0
|
|
140
|
+
- **Reference**: Tianqi Chen and Carlos Guestrin. "XGBoost: A Scalable Tree Boosting System." KDD 2016. https://arxiv.org/abs/1603.02754
|
|
141
|
+
- **参考にした手法**: L1/L2 正則化付き葉の重み計算式、ヘシアンベースの分割ゲイン、最小子ノード制約
|
|
142
|
+
|
|
143
|
+
### LightGBM
|
|
144
|
+
|
|
145
|
+
- **Project**: https://github.com/microsoft/LightGBM
|
|
146
|
+
- **License**: MIT
|
|
147
|
+
- **Reference**: Guolin Ke et al. "LightGBM: A Highly Efficient Gradient Boosting Decision Tree." NeurIPS 2017. https://papers.nips.cc/paper/2017/hash/6449f44a102fde848669bdd9eb6b76fa-Abstract.html
|
|
148
|
+
- **参考にした手法**: ヒストグラムベース分割探索・差分トリック、Leaf-wise 木成長、GOSS(勾配ベースサンプリング)、EFB(排他的特徴量バンドリング)
|
|
149
|
+
|
|
150
|
+
### CatBoost
|
|
151
|
+
|
|
152
|
+
- **Project**: https://github.com/catboost/catboost
|
|
153
|
+
- **License**: Apache 2.0
|
|
154
|
+
- **Reference**: Liudmila Prokhorenkova et al. "CatBoost: unbiased boosting with categorical features." NeurIPS 2018. https://arxiv.org/abs/1706.09516
|
|
155
|
+
- **参考にした手法**: Ordered Boosting(予測シフト低減)、Ordered Target Encoding(カテゴリカル特徴量)、対称木(Oblivious Tree)成長
|
|
156
|
+
|
|
157
|
+
### Numerai
|
|
158
|
+
|
|
159
|
+
- **Project**: https://numer.ai
|
|
160
|
+
- **GitHub**: https://github.com/numerai
|
|
161
|
+
- **参考にした手法**: Era ベースのクロスバリデーションと per-era 性能加重、特徴量中立化(線形特徴量成分の除去)、特徴量露出ペナルティ、Era 間 Sharpe 比最大化
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""PenguinBoost - AROGB: Adversarial Regularized Ordered Gradient Boosting.
|
|
2
|
+
|
|
3
|
+
Hybrid gradient boosting fusing LightGBM, CatBoost, and XGBoost techniques
|
|
4
|
+
with financial-specific overfitting resistance.
|
|
5
|
+
|
|
6
|
+
Features:
|
|
7
|
+
- Feature neutralization and orthogonal gradient projection
|
|
8
|
+
- Era-aware boosting and Sharpe-maximizing objectives
|
|
9
|
+
- Spearman / MaxSharpe / FeatureExposurePenalized objectives
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from penguinboost.sklearn_api import (
|
|
13
|
+
PenguinBoostClassifier,
|
|
14
|
+
PenguinBoostRegressor,
|
|
15
|
+
PenguinBoostRanker,
|
|
16
|
+
PenguinBoostSurvival,
|
|
17
|
+
PenguinBoostQuantileRegressor,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
from penguinboost.core.neutralization import (
|
|
21
|
+
FeatureNeutralizer,
|
|
22
|
+
OrthogonalGradientProjector,
|
|
23
|
+
)
|
|
24
|
+
from penguinboost.core.era_boost import (
|
|
25
|
+
EraBoostingReweighter,
|
|
26
|
+
EraMetrics,
|
|
27
|
+
)
|
|
28
|
+
from penguinboost.objectives.corr import (
|
|
29
|
+
SpearmanObjective,
|
|
30
|
+
MaxSharpeEraObjective,
|
|
31
|
+
FeatureExposurePenalizedObjective,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
from penguinboost._core import set_num_threads, get_num_threads
|
|
36
|
+
except ImportError:
|
|
37
|
+
def set_num_threads(n): pass # noqa: E704
|
|
38
|
+
def get_num_threads(): return 1 # noqa: E704
|
|
39
|
+
|
|
40
|
+
__version__ = "0.3.3"
|
|
41
|
+
__all__ = [
|
|
42
|
+
# sklearn 推定器
|
|
43
|
+
"PenguinBoostClassifier",
|
|
44
|
+
"PenguinBoostRegressor",
|
|
45
|
+
"PenguinBoostRanker",
|
|
46
|
+
"PenguinBoostSurvival",
|
|
47
|
+
"PenguinBoostQuantileRegressor",
|
|
48
|
+
# 特徴量中立化
|
|
49
|
+
"FeatureNeutralizer",
|
|
50
|
+
"OrthogonalGradientProjector",
|
|
51
|
+
# エラ対応ブースティング
|
|
52
|
+
"EraBoostingReweighter",
|
|
53
|
+
"EraMetrics",
|
|
54
|
+
# 金融向け目的関数
|
|
55
|
+
"SpearmanObjective",
|
|
56
|
+
"MaxSharpeEraObjective",
|
|
57
|
+
"FeatureExposurePenalizedObjective",
|
|
58
|
+
# スレッド制御
|
|
59
|
+
"set_num_threads",
|
|
60
|
+
"get_num_threads",
|
|
61
|
+
]
|
|
File without changes
|