unifiedbooster 0.2.1__py3-none-any.whl → 0.2.2__py3-none-any.whl

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.
@@ -1,4 +1,5 @@
1
+ from .gbdt import GBDT
1
2
  from .gbdt_classification import GBDTClassifier
2
3
  from .gbdt_regression import GBDTRegressor
3
4
 
4
- __all__ = ["GBDTClassifier", "GBDTRegressor"]
5
+ __all__ = ["GBDT", "GBDTClassifier", "GBDTRegressor"]
unifiedbooster/gbdt.py CHANGED
@@ -1,69 +1,131 @@
1
- import numpy as np
1
+ import numpy as np
2
2
  from sklearn.base import BaseEstimator
3
3
 
4
4
 
5
5
  class GBDT(BaseEstimator):
6
- def __init__(self,
7
- model_type='xgboost',
8
- n_estimators=100,
9
- learning_rate=0.1,
10
- max_depth=3,
11
- rowsample=1.0,
12
- colsample=1.0,
13
- verbose=0,
14
- seed=123,
15
- **kwargs):
16
-
6
+ """Gradient Boosted Decision Trees (GBDT) base class
7
+
8
+ Attributes:
9
+
10
+ n_estimators: int
11
+ maximum number of trees that can be built
12
+
13
+ learning_rate: float
14
+ shrinkage rate; used for reducing the gradient step
15
+
16
+ rowsample: float
17
+ subsample ratio of the training instances
18
+
19
+ colsample: float
20
+ percentage of features to use at each node split
21
+
22
+ verbose: int
23
+ controls verbosity (default=0)
24
+
25
+ seed: int
26
+ reproducibility seed
27
+ """
28
+
29
+ def __init__(
30
+ self,
31
+ model_type="xgboost",
32
+ n_estimators=100,
33
+ learning_rate=0.1,
34
+ max_depth=3,
35
+ rowsample=1.0,
36
+ colsample=1.0,
37
+ verbose=0,
38
+ seed=123,
39
+ **kwargs
40
+ ):
41
+
17
42
  self.model_type = model_type
18
43
  self.n_estimators = n_estimators
19
44
  self.learning_rate = learning_rate
20
45
  self.max_depth = max_depth
21
46
  self.rowsample = rowsample
22
- self.colsample = colsample
23
- self.verbose = verbose
24
- self.seed = seed
47
+ self.colsample = colsample
48
+ self.verbose = verbose
49
+ self.seed = seed
25
50
 
26
- if self.model_type == "xgboost":
51
+ if self.model_type == "xgboost":
27
52
  self.params = {
28
- 'n_estimators': self.n_estimators,
29
- 'learning_rate': self.learning_rate,
30
- 'subsample': self.rowsample,
31
- 'colsample_bynode': self.colsample,
32
- 'max_depth': self.max_depth,
33
- 'verbosity': self.verbose,
34
- 'seed': self.seed,
35
- **kwargs
53
+ "n_estimators": self.n_estimators,
54
+ "learning_rate": self.learning_rate,
55
+ "subsample": self.rowsample,
56
+ "colsample_bynode": self.colsample,
57
+ "max_depth": self.max_depth,
58
+ "verbosity": self.verbose,
59
+ "seed": self.seed,
60
+ **kwargs,
36
61
  }
37
62
  elif self.model_type == "lightgbm":
38
- verbose = self.verbose - 1 if self.verbose==0 else self.verbose
39
- self.params = {
40
- 'n_estimators': self.n_estimators,
41
- 'learning_rate': self.learning_rate,
42
- 'subsample': self.rowsample,
43
- 'feature_fraction_bynode': self.colsample,
44
- 'max_depth': self.max_depth,
45
- 'verbose': verbose, # keep this way
46
- 'seed': self.seed,
47
- **kwargs
63
+ verbose = self.verbose - 1 if self.verbose == 0 else self.verbose
64
+ self.params = {
65
+ "n_estimators": self.n_estimators,
66
+ "learning_rate": self.learning_rate,
67
+ "subsample": self.rowsample,
68
+ "feature_fraction_bynode": self.colsample,
69
+ "max_depth": self.max_depth,
70
+ "verbose": verbose, # keep this way
71
+ "seed": self.seed,
72
+ **kwargs,
48
73
  }
49
74
  elif self.model_type == "catboost":
50
- self.params = {
51
- 'iterations': self.n_estimators,
52
- 'learning_rate': self.learning_rate,
53
- 'subsample': self.rowsample,
54
- 'rsm': self.colsample,
55
- 'depth': self.max_depth,
56
- 'verbose': self.verbose,
57
- 'random_seed': self.seed,
58
- 'bootstrap_type': 'Bernoulli',
59
- **kwargs
60
- }
61
-
75
+ self.params = {
76
+ "iterations": self.n_estimators,
77
+ "learning_rate": self.learning_rate,
78
+ "subsample": self.rowsample,
79
+ "rsm": self.colsample,
80
+ "depth": self.max_depth,
81
+ "verbose": self.verbose,
82
+ "random_seed": self.seed,
83
+ "bootstrap_type": "Bernoulli",
84
+ **kwargs,
85
+ }
86
+
62
87
  def fit(self, X, y, **kwargs):
88
+ """Fit custom model to training data (X, y).
89
+
90
+ Parameters:
91
+
92
+ X: {array-like}, shape = [n_samples, n_features]
93
+ Training vectors, where n_samples is the number
94
+ of samples and n_features is the number of features.
95
+
96
+ y: array-like, shape = [n_samples]
97
+ Target values.
98
+
99
+ **kwargs: additional parameters to be passed to
100
+ self.cook_training_set or self.obj.fit
101
+
102
+ Returns:
103
+
104
+ self: object
105
+ """
106
+
63
107
  if getattr(self, "type_fit") == "classification":
64
- self.classes_ = np.unique(y) # for compatibility with sklearn
65
- self.n_classes_ = len(self.classes_) # for compatibility with sklearn
108
+ self.classes_ = np.unique(y) # for compatibility with sklearn
109
+ self.n_classes_ = len(
110
+ self.classes_
111
+ ) # for compatibility with sklearn
66
112
  return getattr(self, "model").fit(X, y, **kwargs)
67
-
113
+
68
114
  def predict(self, X):
69
- return getattr(self, "model").predict(X)
115
+ """Predict test data X.
116
+
117
+ Parameters:
118
+
119
+ X: {array-like}, shape = [n_samples, n_features]
120
+ Training vectors, where n_samples is the number
121
+ of samples and n_features is the number of features.
122
+
123
+ **kwargs: additional parameters to be passed to
124
+ self.cook_test_set
125
+
126
+ Returns:
127
+
128
+ model predictions: {array-like}
129
+ """
130
+
131
+ return getattr(self, "model").predict(X)
@@ -1,7 +1,11 @@
1
1
  from .gbdt import GBDT
2
2
  from sklearn.base import ClassifierMixin
3
3
  from xgboost import XGBClassifier
4
- from catboost import CatBoostClassifier
4
+
5
+ try:
6
+ from catboost import CatBoostClassifier
7
+ except:
8
+ print("catboost package can't be built")
5
9
  from lightgbm import LGBMClassifier
6
10
 
7
11
 
@@ -11,7 +15,7 @@ class GBDTClassifier(GBDT, ClassifierMixin):
11
15
  Attributes:
12
16
 
13
17
  n_estimators: int
14
- maximum number of trees that can be built
18
+ maximum number of trees that can be built
15
19
 
16
20
  learning_rate: float
17
21
  shrinkage rate; used for reducing the gradient step
@@ -24,9 +28,9 @@ class GBDTClassifier(GBDT, ClassifierMixin):
24
28
 
25
29
  verbose: int
26
30
  controls verbosity (default=0)
27
-
28
- seed: int
29
- reproducibility seed
31
+
32
+ seed: int
33
+ reproducibility seed
30
34
 
31
35
  Examples:
32
36
 
@@ -68,39 +72,57 @@ class GBDTClassifier(GBDT, ClassifierMixin):
68
72
  ```
69
73
  """
70
74
 
71
- def __init__(self,
72
- model_type='xgboost',
73
- n_estimators=100,
74
- learning_rate=0.1,
75
- max_depth=3,
76
- rowsample=1.0,
77
- colsample=1.0,
78
- verbose=0,
79
- seed=123,
80
- **kwargs):
81
-
75
+ def __init__(
76
+ self,
77
+ model_type="xgboost",
78
+ n_estimators=100,
79
+ learning_rate=0.1,
80
+ max_depth=3,
81
+ rowsample=1.0,
82
+ colsample=1.0,
83
+ verbose=0,
84
+ seed=123,
85
+ **kwargs,
86
+ ):
87
+
82
88
  self.type_fit = "classification"
83
-
89
+
84
90
  super().__init__(
85
- model_type=model_type,
86
- n_estimators=n_estimators,
87
- learning_rate=learning_rate,
88
- max_depth=max_depth,
91
+ model_type=model_type,
92
+ n_estimators=n_estimators,
93
+ learning_rate=learning_rate,
94
+ max_depth=max_depth,
89
95
  rowsample=rowsample,
90
- colsample=colsample,
91
- verbose=verbose,
92
- seed=seed,
93
- **kwargs
96
+ colsample=colsample,
97
+ verbose=verbose,
98
+ seed=seed,
99
+ **kwargs,
94
100
  )
95
101
 
96
- if model_type == 'xgboost':
102
+ if model_type == "xgboost":
97
103
  self.model = XGBClassifier(**self.params)
98
- elif model_type == 'catboost':
104
+ elif model_type == "catboost":
99
105
  self.model = CatBoostClassifier(**self.params)
100
- elif model_type == 'lightgbm':
106
+ elif model_type == "lightgbm":
101
107
  self.model = LGBMClassifier(**self.params)
102
108
  else:
103
109
  raise ValueError(f"Unknown model_type: {model_type}")
104
-
110
+
105
111
  def predict_proba(self, X):
106
- return self.model.predict_proba(X)
112
+ """Predict probabilities for test data X.
113
+
114
+ Args:
115
+
116
+ X: {array-like}, shape = [n_samples, n_features]
117
+ Training vectors, where n_samples is the number
118
+ of samples and n_features is the number of features.
119
+
120
+ **kwargs: additional parameters to be passed to
121
+ self.cook_test_set
122
+
123
+ Returns:
124
+
125
+ probability estimates for test data: {array-like}
126
+ """
127
+
128
+ return self.model.predict_proba(X)
@@ -1,7 +1,11 @@
1
1
  from .gbdt import GBDT
2
2
  from sklearn.base import RegressorMixin
3
3
  from xgboost import XGBRegressor
4
- from catboost import CatBoostRegressor
4
+
5
+ try:
6
+ from catboost import CatBoostRegressor
7
+ except:
8
+ print("catboost package can't be built")
5
9
  from lightgbm import LGBMRegressor
6
10
 
7
11
 
@@ -11,7 +15,7 @@ class GBDTRegressor(GBDT, RegressorMixin):
11
15
  Attributes:
12
16
 
13
17
  n_estimators: int
14
- maximum number of trees that can be built
18
+ maximum number of trees that can be built
15
19
 
16
20
  learning_rate: float
17
21
  shrinkage rate; used for reducing the gradient step
@@ -24,9 +28,9 @@ class GBDTRegressor(GBDT, RegressorMixin):
24
28
 
25
29
  verbose: int
26
30
  controls verbosity (default=0)
27
-
28
- seed: int
29
- reproducibility seed
31
+
32
+ seed: int
33
+ reproducibility seed
30
34
 
31
35
  Examples:
32
36
 
@@ -68,36 +72,38 @@ class GBDTRegressor(GBDT, RegressorMixin):
68
72
  ```
69
73
  """
70
74
 
71
- def __init__(self,
72
- model_type='xgboost',
73
- n_estimators=100,
74
- learning_rate=0.1,
75
- max_depth=3,
76
- rowsample=1.0,
77
- colsample=1.0,
78
- verbose=0,
79
- seed=123,
80
- **kwargs):
81
-
75
+ def __init__(
76
+ self,
77
+ model_type="xgboost",
78
+ n_estimators=100,
79
+ learning_rate=0.1,
80
+ max_depth=3,
81
+ rowsample=1.0,
82
+ colsample=1.0,
83
+ verbose=0,
84
+ seed=123,
85
+ **kwargs,
86
+ ):
87
+
82
88
  self.type_fit = "regression"
83
-
89
+
84
90
  super().__init__(
85
- model_type=model_type,
86
- n_estimators=n_estimators,
87
- learning_rate=learning_rate,
88
- max_depth=max_depth,
91
+ model_type=model_type,
92
+ n_estimators=n_estimators,
93
+ learning_rate=learning_rate,
94
+ max_depth=max_depth,
89
95
  rowsample=rowsample,
90
- colsample=colsample,
91
- verbose=verbose,
92
- seed=seed,
93
- **kwargs
96
+ colsample=colsample,
97
+ verbose=verbose,
98
+ seed=seed,
99
+ **kwargs,
94
100
  )
95
101
 
96
- if model_type == 'xgboost':
102
+ if model_type == "xgboost":
97
103
  self.model = XGBRegressor(**self.params)
98
- elif model_type == 'catboost':
104
+ elif model_type == "catboost":
99
105
  self.model = CatBoostRegressor(**self.params)
100
- elif model_type == 'lightgbm':
106
+ elif model_type == "lightgbm":
101
107
  self.model = LGBMRegressor(**self.params)
102
108
  else:
103
109
  raise ValueError(f"Unknown model_type: {model_type}")
@@ -0,0 +1,7 @@
1
+ Copyright <2024> <T. Moudiki>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unifiedbooster
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Unified interface for Gradient Boosted Decision Trees
5
5
  Home-page: https://github.com/thierrymoudiki/unifiedbooster
6
6
  Author: T. Moudiki
@@ -16,6 +16,7 @@ Classifier: Programming Language :: Python :: 3.6
16
16
  Classifier: Programming Language :: Python :: 3.7
17
17
  Classifier: Programming Language :: Python :: 3.8
18
18
  Requires-Python: >=3.6
19
+ License-File: LICENSE
19
20
  Requires-Dist: Cython
20
21
  Requires-Dist: numpy
21
22
  Requires-Dist: scikit-learn
@@ -0,0 +1,10 @@
1
+ unifiedbooster/__init__.py,sha256=3d8wQVXaeVIxqtk_STM6nvIGZiGTxKn9aAWjuwiDYuo,169
2
+ unifiedbooster/gbdt.py,sha256=Y5gweEEfI5DGMsuE_Z-gJlbteawolzk2uFyoGXGwgKA,3958
3
+ unifiedbooster/gbdt_classification.py,sha256=sIdoeqOBYGmzeHV3Rk3DrBav-ebG2v-o9cv0X0LREXg,3634
4
+ unifiedbooster/gbdt_regression.py,sha256=VE129JJ_DNoi3knLI5I_5QNRkW0M3KAKRmE-sfXrCLk,3127
5
+ unifiedbooster-0.2.2.dist-info/LICENSE,sha256=3rWw63btcdqbC0XMnpzCQhxDP8Vx7yKkKS7EDgJiY_4,1061
6
+ unifiedbooster-0.2.2.dist-info/METADATA,sha256=Y-BX935CwMCs4uD-mNoniEeU0F0yuySg97dhZF5NSEQ,930
7
+ unifiedbooster-0.2.2.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
8
+ unifiedbooster-0.2.2.dist-info/entry_points.txt,sha256=OVNTsCzMYnaJ11WIByB7G8Lym_dj-ERKZyQxWFUcW30,59
9
+ unifiedbooster-0.2.2.dist-info/top_level.txt,sha256=gOMxxpRtx8_nJXTWsXJDFkNeCsjSJQPs6aUXKK5_nI4,15
10
+ unifiedbooster-0.2.2.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- unifiedbooster/__init__.py,sha256=urmH2DAkJ4e-idIh0oMZX9lP9rlqTPyZ-qHuNeJcEIc,137
2
- unifiedbooster/gbdt.py,sha256=MS8M71r9uXM2NsWj54bH8_k0labL2V4p_R55qgNqGIg,2630
3
- unifiedbooster/gbdt_classification.py,sha256=326I7d70nF__uOlynMU7IrS-8cyez4xlMYDNJMTSL6Y,3277
4
- unifiedbooster/gbdt_regression.py,sha256=wOT1iigiXELzQ_lL_SjgdiP2pm7RgMVXY89QMLMkhYk,3229
5
- unifiedbooster-0.2.1.dist-info/METADATA,sha256=YZdEVXeU2WWgtC7acTOvmbqyoXFPVofIjJur2IkKxRE,908
6
- unifiedbooster-0.2.1.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
7
- unifiedbooster-0.2.1.dist-info/entry_points.txt,sha256=OVNTsCzMYnaJ11WIByB7G8Lym_dj-ERKZyQxWFUcW30,59
8
- unifiedbooster-0.2.1.dist-info/top_level.txt,sha256=gOMxxpRtx8_nJXTWsXJDFkNeCsjSJQPs6aUXKK5_nI4,15
9
- unifiedbooster-0.2.1.dist-info/RECORD,,