rxgb 0.1.0__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.
- rxgb-0.1.0/LICENSE +21 -0
- rxgb-0.1.0/PKG-INFO +43 -0
- rxgb-0.1.0/README.md +19 -0
- rxgb-0.1.0/pyproject.toml +39 -0
- rxgb-0.1.0/setup.cfg +4 -0
- rxgb-0.1.0/src/rxgb/__init__.py +26 -0
- rxgb-0.1.0/src/rxgb/core.py +364 -0
- rxgb-0.1.0/src/rxgb.egg-info/PKG-INFO +43 -0
- rxgb-0.1.0/src/rxgb.egg-info/SOURCES.txt +10 -0
- rxgb-0.1.0/src/rxgb.egg-info/dependency_links.txt +1 -0
- rxgb-0.1.0/src/rxgb.egg-info/requires.txt +3 -0
- rxgb-0.1.0/src/rxgb.egg-info/top_level.txt +1 -0
rxgb-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kiarash Norri
|
|
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.
|
rxgb-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rxgb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: RXGB: A bagging ensemble of shallow XGBoost learners for classification and regression
|
|
5
|
+
Author-email: Kiarash Nouri <kia1391n@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Kia_ML/rxgb
|
|
8
|
+
Keywords: machine learning,ensemble,xgboost,bagging,random forest
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: xgboost>=1.7
|
|
21
|
+
Requires-Dist: scikit-learn>=1.0
|
|
22
|
+
Requires-Dist: numpy>=1.21
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# RXGB: Random eXtreme Gradient Boosting
|
|
26
|
+
|
|
27
|
+
A bagging ensemble framework that combines Random Forest's bagging strategy
|
|
28
|
+
with depth-constrained XGBoost learners as base estimators.
|
|
29
|
+
|
|
30
|
+
[](https://www.python.org/)
|
|
31
|
+
[](https://opensource.org/licenses/MIT)
|
|
32
|
+
|
|
33
|
+
## Overview
|
|
34
|
+
|
|
35
|
+
RXGB substitutes conventional decision trees in Random Forest with
|
|
36
|
+
depth-constrained XGBoost learners. This combination simultaneously
|
|
37
|
+
reduces **bias** and **variance**, which neither standalone Random Forest
|
|
38
|
+
nor standalone XGBoost can achieve alone.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install rxgb
|
rxgb-0.1.0/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# RXGB: Random eXtreme Gradient Boosting
|
|
2
|
+
|
|
3
|
+
A bagging ensemble framework that combines Random Forest's bagging strategy
|
|
4
|
+
with depth-constrained XGBoost learners as base estimators.
|
|
5
|
+
|
|
6
|
+
[](https://www.python.org/)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
RXGB substitutes conventional decision trees in Random Forest with
|
|
12
|
+
depth-constrained XGBoost learners. This combination simultaneously
|
|
13
|
+
reduces **bias** and **variance**, which neither standalone Random Forest
|
|
14
|
+
nor standalone XGBoost can achieve alone.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install rxgb
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rxgb"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "RXGB: A bagging ensemble of shallow XGBoost learners for classification and regression"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Kiarash Nouri", email = "kia1391n@gmail.com" }
|
|
14
|
+
]
|
|
15
|
+
keywords = ["machine learning", "ensemble", "xgboost", "bagging", "random forest"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"xgboost>=1.7",
|
|
28
|
+
"scikit-learn>=1.0",
|
|
29
|
+
"numpy>=1.21",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/Kia_ML/rxgb"
|
|
34
|
+
|
|
35
|
+
[tool.setuptools]
|
|
36
|
+
package-dir = { "" = "src" }
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
where = ["src"]
|
rxgb-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""RXGB: Random eXtreme Gradient Boosting.
|
|
2
|
+
|
|
3
|
+
A bagging ensemble framework that combines Random Forest's bagging
|
|
4
|
+
strategy with depth-constrained XGBoost learners as base estimators.
|
|
5
|
+
|
|
6
|
+
The framework provides two scikit-learn compatible estimators:
|
|
7
|
+
|
|
8
|
+
- :class:`RXGBClassifier` for classification
|
|
9
|
+
- :class:`RXGBRegressor` for regression
|
|
10
|
+
|
|
11
|
+
Example
|
|
12
|
+
-------
|
|
13
|
+
>>> from rxgb import RXGBClassifier
|
|
14
|
+
>>> from sklearn.datasets import load_iris
|
|
15
|
+
>>> X, y = load_iris(return_X_y=True)
|
|
16
|
+
>>> clf = RXGBClassifier(n_estimators=25, max_depth=4)
|
|
17
|
+
>>> clf.fit(X, y)
|
|
18
|
+
RXGBClassifier(...)
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from .core import RXGBClassifier, RXGBRegressor
|
|
22
|
+
|
|
23
|
+
__version__ = "0.1.0"
|
|
24
|
+
__author__ = "Kiarash Nouri"
|
|
25
|
+
__email__ = "kiarash.nr.ml@gmail.com"
|
|
26
|
+
__all__ = ["RXGBClassifier", "RXGBRegressor"]
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
"""RXGB Core: Bagging ensemble of shallow XGBoost learners.
|
|
2
|
+
|
|
3
|
+
This module provides two scikit-learn compatible estimators:
|
|
4
|
+
|
|
5
|
+
- :class:`RXGBClassifier` for classification tasks.
|
|
6
|
+
- :class:`RXGBRegressor` for regression tasks.
|
|
7
|
+
|
|
8
|
+
Both estimators implement the RXGB architecture, which combines the
|
|
9
|
+
bagging strategy of Random Forest with depth-constrained XGBoost
|
|
10
|
+
learners as base estimators. This design reduces both bias and variance
|
|
11
|
+
simultaneously, which neither standalone Random Forest nor standalone
|
|
12
|
+
XGBoost can achieve.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import numpy as np
|
|
16
|
+
from xgboost import XGBClassifier, XGBRegressor
|
|
17
|
+
from sklearn.base import BaseEstimator, ClassifierMixin, RegressorMixin
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class _RXGBBase(BaseEstimator):
|
|
21
|
+
"""Base class shared by RXGBClassifier and RXGBRegressor.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
n_estimators : int, default=25
|
|
26
|
+
Number of XGBoost base learners in the bagging ensemble.
|
|
27
|
+
|
|
28
|
+
max_depth : int, default=4
|
|
29
|
+
Maximum depth of each XGBoost base learner.
|
|
30
|
+
|
|
31
|
+
learning_rate : float, default=0.1
|
|
32
|
+
Learning rate (shrinkage) for each XGBoost base learner.
|
|
33
|
+
|
|
34
|
+
inner_n_estimators : int, default=50
|
|
35
|
+
Number of boosting rounds (trees) inside each XGBoost base
|
|
36
|
+
learner.
|
|
37
|
+
|
|
38
|
+
max_samples : float, default=0.8
|
|
39
|
+
Fraction of samples drawn (with replacement) for each base
|
|
40
|
+
learner.
|
|
41
|
+
|
|
42
|
+
max_features : float, default=0.8
|
|
43
|
+
Fraction of features randomly selected for each base learner.
|
|
44
|
+
|
|
45
|
+
n_jobs : int, default=None
|
|
46
|
+
The number of jobs to run in parallel. ``None`` means 1 unless
|
|
47
|
+
in a :obj:`joblib.parallel_backend` context. ``-1`` means using
|
|
48
|
+
all processors. See :term:`Glossary <n_jobs>` for more details.
|
|
49
|
+
|
|
50
|
+
random_state : int, default=42
|
|
51
|
+
Random seed for reproducibility.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(self, n_estimators=25, max_depth=4, learning_rate=0.1,
|
|
55
|
+
inner_n_estimators=50, max_samples=0.8, max_features=0.8,
|
|
56
|
+
n_jobs=None, random_state=42):
|
|
57
|
+
self.n_estimators = n_estimators
|
|
58
|
+
self.max_depth = max_depth
|
|
59
|
+
self.learning_rate = learning_rate
|
|
60
|
+
self.inner_n_estimators = inner_n_estimators
|
|
61
|
+
self.max_samples = max_samples
|
|
62
|
+
self.max_features = max_features
|
|
63
|
+
self.n_jobs = n_jobs
|
|
64
|
+
self.random_state = random_state
|
|
65
|
+
|
|
66
|
+
def _validate_input(self, X, y):
|
|
67
|
+
"""Validate the input arrays X and y."""
|
|
68
|
+
X = np.asarray(X)
|
|
69
|
+
y = np.asarray(y)
|
|
70
|
+
if X.ndim != 2:
|
|
71
|
+
raise ValueError(f"X must be 2D, got shape {X.shape}")
|
|
72
|
+
if y.ndim != 1:
|
|
73
|
+
raise ValueError(f"y must be 1D, got shape {y.shape}")
|
|
74
|
+
if len(y) != X.shape[0]:
|
|
75
|
+
raise ValueError(
|
|
76
|
+
f"X and y have inconsistent lengths: "
|
|
77
|
+
f"{X.shape[0]} vs {len(y)}"
|
|
78
|
+
)
|
|
79
|
+
return X, y
|
|
80
|
+
|
|
81
|
+
def _make_base_model(self, seed):
|
|
82
|
+
"""Create a single base estimator. Must be overridden."""
|
|
83
|
+
raise NotImplementedError
|
|
84
|
+
|
|
85
|
+
def fit(self, X, y):
|
|
86
|
+
"""Build the RXGB ensemble from the training data.
|
|
87
|
+
|
|
88
|
+
Parameters
|
|
89
|
+
----------
|
|
90
|
+
X : array-like of shape (n_samples, n_features)
|
|
91
|
+
The training input samples.
|
|
92
|
+
|
|
93
|
+
y : array-like of shape (n_samples,)
|
|
94
|
+
The target values.
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
self : object
|
|
99
|
+
Fitted estimator.
|
|
100
|
+
"""
|
|
101
|
+
X, y = self._validate_input(X, y)
|
|
102
|
+
n, p = X.shape
|
|
103
|
+
rng = np.random.RandomState(self.random_state)
|
|
104
|
+
|
|
105
|
+
self.models_ = []
|
|
106
|
+
self.features_ = []
|
|
107
|
+
|
|
108
|
+
for i in range(self.n_estimators):
|
|
109
|
+
idx = rng.choice(
|
|
110
|
+
n, size=int(self.max_samples * n), replace=True
|
|
111
|
+
)
|
|
112
|
+
feats = rng.choice(
|
|
113
|
+
p, size=max(1, int(self.max_features * p)), replace=False
|
|
114
|
+
)
|
|
115
|
+
model = self._make_base_model(seed=self.random_state + i)
|
|
116
|
+
model.fit(X[np.ix_(idx, feats)], y[idx])
|
|
117
|
+
self.models_.append(model)
|
|
118
|
+
self.features_.append(feats)
|
|
119
|
+
|
|
120
|
+
return self
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class RXGBClassifier(_RXGBBase, ClassifierMixin):
|
|
124
|
+
"""RXGB classifier: Bagging ensemble of shallow XGBoost classifiers.
|
|
125
|
+
|
|
126
|
+
RXGB replaces the conventional decision trees of a Random Forest with
|
|
127
|
+
depth-constrained XGBoost learners. The bagging layer (bootstrap
|
|
128
|
+
sampling of rows and random subsampling of features) ensures diversity
|
|
129
|
+
across base learners, while XGBoost's gradient boosting reduces bias.
|
|
130
|
+
|
|
131
|
+
Parameters
|
|
132
|
+
----------
|
|
133
|
+
n_estimators : int, default=25
|
|
134
|
+
Number of XGBoost base learners in the bagging ensemble.
|
|
135
|
+
|
|
136
|
+
max_depth : int, default=4
|
|
137
|
+
Maximum depth of each XGBoost base learner.
|
|
138
|
+
|
|
139
|
+
learning_rate : float, default=0.1
|
|
140
|
+
Learning rate (shrinkage) for each XGBoost base learner.
|
|
141
|
+
|
|
142
|
+
inner_n_estimators : int, default=50
|
|
143
|
+
Number of boosting rounds (trees) inside each XGBoost base
|
|
144
|
+
learner.
|
|
145
|
+
|
|
146
|
+
max_samples : float, default=0.8
|
|
147
|
+
Fraction of samples drawn (with replacement) for each base
|
|
148
|
+
learner.
|
|
149
|
+
|
|
150
|
+
max_features : float, default=0.8
|
|
151
|
+
Fraction of features randomly selected for each base learner.
|
|
152
|
+
|
|
153
|
+
n_jobs : int, default=None
|
|
154
|
+
The number of jobs to run in parallel. ``None`` means 1 unless
|
|
155
|
+
in a :obj:`joblib.parallel_backend` context. ``-1`` means using
|
|
156
|
+
all processors. See :term:`Glossary <n_jobs>` for more details.
|
|
157
|
+
|
|
158
|
+
random_state : int, default=42
|
|
159
|
+
Random seed for reproducibility.
|
|
160
|
+
|
|
161
|
+
Attributes
|
|
162
|
+
----------
|
|
163
|
+
classes_ : ndarray of shape (n_classes,)
|
|
164
|
+
The class labels.
|
|
165
|
+
|
|
166
|
+
models_ : list of XGBClassifier
|
|
167
|
+
The trained XGBoost base estimators.
|
|
168
|
+
|
|
169
|
+
features_ : list of ndarray
|
|
170
|
+
The feature indices used by each base estimator.
|
|
171
|
+
|
|
172
|
+
Examples
|
|
173
|
+
--------
|
|
174
|
+
>>> from rxgb import RXGBClassifier
|
|
175
|
+
>>> from sklearn.datasets import load_iris
|
|
176
|
+
>>> X, y = load_iris(return_X_y=True)
|
|
177
|
+
>>> clf = RXGBClassifier(n_estimators=15, max_depth=4)
|
|
178
|
+
>>> clf.fit(X, y)
|
|
179
|
+
RXGBClassifier(...)
|
|
180
|
+
>>> clf.predict(X[:5])
|
|
181
|
+
array([0, 0, 0, 0, 0])
|
|
182
|
+
"""
|
|
183
|
+
|
|
184
|
+
def _make_base_model(self, seed):
|
|
185
|
+
return XGBClassifier(
|
|
186
|
+
n_estimators=self.inner_n_estimators,
|
|
187
|
+
max_depth=self.max_depth,
|
|
188
|
+
learning_rate=self.learning_rate,
|
|
189
|
+
n_jobs=self.n_jobs,
|
|
190
|
+
random_state=seed,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
def fit(self, X, y):
|
|
194
|
+
"""Fit the RXGB classifier.
|
|
195
|
+
|
|
196
|
+
Parameters
|
|
197
|
+
----------
|
|
198
|
+
X : array-like of shape (n_samples, n_features)
|
|
199
|
+
Training data.
|
|
200
|
+
|
|
201
|
+
y : array-like of shape (n_samples,)
|
|
202
|
+
Target class labels. Can be integers, strings, or booleans.
|
|
203
|
+
|
|
204
|
+
Returns
|
|
205
|
+
-------
|
|
206
|
+
self : RXGBClassifier
|
|
207
|
+
Fitted classifier.
|
|
208
|
+
"""
|
|
209
|
+
X = np.asarray(X)
|
|
210
|
+
y = np.asarray(y)
|
|
211
|
+
self.classes_, y_encoded = np.unique(y, return_inverse=True)
|
|
212
|
+
super().fit(X, y_encoded)
|
|
213
|
+
return self
|
|
214
|
+
|
|
215
|
+
def predict_proba(self, X):
|
|
216
|
+
"""Predict class probabilities for X.
|
|
217
|
+
|
|
218
|
+
Parameters
|
|
219
|
+
----------
|
|
220
|
+
X : array-like of shape (n_samples, n_features)
|
|
221
|
+
Input samples.
|
|
222
|
+
|
|
223
|
+
Returns
|
|
224
|
+
-------
|
|
225
|
+
proba : ndarray of shape (n_samples, n_classes)
|
|
226
|
+
Mean predicted class probabilities across all base learners.
|
|
227
|
+
"""
|
|
228
|
+
X = np.asarray(X)
|
|
229
|
+
n_classes = len(self.classes_)
|
|
230
|
+
probas = []
|
|
231
|
+
for m, f in zip(self.models_, self.features_):
|
|
232
|
+
p = m.predict_proba(X[:, f])
|
|
233
|
+
if p.shape[1] < n_classes:
|
|
234
|
+
full = np.zeros((p.shape[0], n_classes))
|
|
235
|
+
for i, c in enumerate(m.classes_):
|
|
236
|
+
full[:, c] = p[:, i]
|
|
237
|
+
p = full
|
|
238
|
+
probas.append(p)
|
|
239
|
+
return np.mean(probas, axis=0)
|
|
240
|
+
|
|
241
|
+
def predict(self, X):
|
|
242
|
+
"""Predict class labels for X.
|
|
243
|
+
|
|
244
|
+
Parameters
|
|
245
|
+
----------
|
|
246
|
+
X : array-like of shape (n_samples, n_features)
|
|
247
|
+
Input samples.
|
|
248
|
+
|
|
249
|
+
Returns
|
|
250
|
+
-------
|
|
251
|
+
y_pred : ndarray of shape (n_samples,)
|
|
252
|
+
Predicted class labels.
|
|
253
|
+
"""
|
|
254
|
+
proba = self.predict_proba(X)
|
|
255
|
+
return self.classes_[np.argmax(proba, axis=1)]
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
class RXGBRegressor(_RXGBBase, RegressorMixin):
|
|
259
|
+
"""RXGB regressor: Bagging ensemble of shallow XGBoost regressors.
|
|
260
|
+
|
|
261
|
+
RXGB replaces the conventional decision trees of a Random Forest with
|
|
262
|
+
depth-constrained XGBoost regressors. Predictions from all base
|
|
263
|
+
learners are averaged to produce the final output.
|
|
264
|
+
|
|
265
|
+
Parameters
|
|
266
|
+
----------
|
|
267
|
+
n_estimators : int, default=25
|
|
268
|
+
Number of XGBoost base learners in the bagging ensemble.
|
|
269
|
+
|
|
270
|
+
max_depth : int, default=4
|
|
271
|
+
Maximum depth of each XGBoost base learner.
|
|
272
|
+
|
|
273
|
+
learning_rate : float, default=0.1
|
|
274
|
+
Learning rate (shrinkage) for each XGBoost base learner.
|
|
275
|
+
|
|
276
|
+
inner_n_estimators : int, default=50
|
|
277
|
+
Number of boosting rounds inside each XGBoost base learner.
|
|
278
|
+
|
|
279
|
+
max_samples : float, default=0.8
|
|
280
|
+
Fraction of samples drawn for each base learner.
|
|
281
|
+
|
|
282
|
+
max_features : float, default=0.8
|
|
283
|
+
Fraction of features randomly selected for each base learner.
|
|
284
|
+
|
|
285
|
+
n_jobs : int, default=None
|
|
286
|
+
The number of jobs to run in parallel. ``None`` means 1 unless
|
|
287
|
+
in a :obj:`joblib.parallel_backend` context. ``-1`` means using
|
|
288
|
+
all processors.
|
|
289
|
+
|
|
290
|
+
random_state : int, default=42
|
|
291
|
+
Random seed for reproducibility.
|
|
292
|
+
|
|
293
|
+
Attributes
|
|
294
|
+
----------
|
|
295
|
+
models_ : list of XGBRegressor
|
|
296
|
+
The trained XGBoost base estimators.
|
|
297
|
+
|
|
298
|
+
features_ : list of ndarray
|
|
299
|
+
The feature indices used by each base estimator.
|
|
300
|
+
|
|
301
|
+
Examples
|
|
302
|
+
--------
|
|
303
|
+
>>> from rxgb import RXGBRegressor
|
|
304
|
+
>>> from sklearn.datasets import make_regression
|
|
305
|
+
>>> X, y = make_regression(n_samples=100, n_features=10, random_state=42)
|
|
306
|
+
>>> reg = RXGBRegressor(n_estimators=15, max_depth=4)
|
|
307
|
+
>>> reg.fit(X, y)
|
|
308
|
+
RXGBRegressor(...)
|
|
309
|
+
>>> y_pred = reg.predict(X)
|
|
310
|
+
"""
|
|
311
|
+
|
|
312
|
+
def _make_base_model(self, seed):
|
|
313
|
+
return XGBRegressor(
|
|
314
|
+
n_estimators=self.inner_n_estimators,
|
|
315
|
+
max_depth=self.max_depth,
|
|
316
|
+
learning_rate=self.learning_rate,
|
|
317
|
+
n_jobs=self.n_jobs,
|
|
318
|
+
random_state=seed,
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
def fit(self, X, y):
|
|
322
|
+
"""Fit the RXGB regressor.
|
|
323
|
+
|
|
324
|
+
Parameters
|
|
325
|
+
----------
|
|
326
|
+
X : array-like of shape (n_samples, n_features)
|
|
327
|
+
Training data.
|
|
328
|
+
|
|
329
|
+
y : array-like of shape (n_samples,)
|
|
330
|
+
Target values. Must be numeric.
|
|
331
|
+
|
|
332
|
+
Returns
|
|
333
|
+
-------
|
|
334
|
+
self : RXGBRegressor
|
|
335
|
+
Fitted regressor.
|
|
336
|
+
"""
|
|
337
|
+
X = np.asarray(X)
|
|
338
|
+
y = np.asarray(y)
|
|
339
|
+
if not np.issubdtype(y.dtype, np.number):
|
|
340
|
+
raise ValueError(
|
|
341
|
+
f"y must be numeric for regression, got dtype {y.dtype}"
|
|
342
|
+
)
|
|
343
|
+
super().fit(X, y)
|
|
344
|
+
return self
|
|
345
|
+
|
|
346
|
+
def predict(self, X):
|
|
347
|
+
"""Predict target values for X.
|
|
348
|
+
|
|
349
|
+
Parameters
|
|
350
|
+
----------
|
|
351
|
+
X : array-like of shape (n_samples, n_features)
|
|
352
|
+
Input samples.
|
|
353
|
+
|
|
354
|
+
Returns
|
|
355
|
+
-------
|
|
356
|
+
y_pred : ndarray of shape (n_samples,)
|
|
357
|
+
Mean predicted values across all base learners.
|
|
358
|
+
"""
|
|
359
|
+
X = np.asarray(X)
|
|
360
|
+
preds = np.array([
|
|
361
|
+
m.predict(X[:, f])
|
|
362
|
+
for m, f in zip(self.models_, self.features_)
|
|
363
|
+
])
|
|
364
|
+
return preds.mean(axis=0)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rxgb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: RXGB: A bagging ensemble of shallow XGBoost learners for classification and regression
|
|
5
|
+
Author-email: Kiarash Nouri <kia1391n@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Kia_ML/rxgb
|
|
8
|
+
Keywords: machine learning,ensemble,xgboost,bagging,random forest
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: xgboost>=1.7
|
|
21
|
+
Requires-Dist: scikit-learn>=1.0
|
|
22
|
+
Requires-Dist: numpy>=1.21
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# RXGB: Random eXtreme Gradient Boosting
|
|
26
|
+
|
|
27
|
+
A bagging ensemble framework that combines Random Forest's bagging strategy
|
|
28
|
+
with depth-constrained XGBoost learners as base estimators.
|
|
29
|
+
|
|
30
|
+
[](https://www.python.org/)
|
|
31
|
+
[](https://opensource.org/licenses/MIT)
|
|
32
|
+
|
|
33
|
+
## Overview
|
|
34
|
+
|
|
35
|
+
RXGB substitutes conventional decision trees in Random Forest with
|
|
36
|
+
depth-constrained XGBoost learners. This combination simultaneously
|
|
37
|
+
reduces **bias** and **variance**, which neither standalone Random Forest
|
|
38
|
+
nor standalone XGBoost can achieve alone.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install rxgb
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rxgb
|