Skip to content

Commit 75f43ec

Browse files
bump -> v0.14.0
1 parent ee690c5 commit 75f43ec

File tree

7 files changed

+63
-3
lines changed

7 files changed

+63
-3
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# version 0.14.0
2+
3+
- add polynomial (interactions) features to `LSBoostRegressor` and `LSBoostClassifier`
4+
15
# version 0.13.1
26

37
- add clustering to `LSBoostRegressor`, `LSBoostClassifier`, and `AdaOpt`

examples/lsboost_classifier.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,20 @@
246246
start = time()
247247
print(obj.score(X_test, y_test))
248248
print(time()-start)
249+
print(f"loss: {np.log(obj.obj['loss'])}")
250+
251+
obj = ms.LSBoostClassifier(solver="lasso",
252+
n_clusters=3,
253+
clustering_method="gmm",
254+
degree=2)
255+
print(obj.get_params())
256+
start = time()
257+
obj.fit(X_train, y_train)
258+
print(time()-start)
259+
start = time()
260+
print(obj.score(X_test, y_test))
261+
print(time()-start)
262+
print(f"loss: {np.log(obj.obj['loss'])}")
249263

250264
# MORE DATA NEEDED # MORE DATA NEEDED # MORE DATA NEEDED
251265
# obj = ms.LSBoostClassifier(backend="gpu", solver="lasso")

examples/lsboost_regressor_pi.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,21 @@
121121
print(f"splitconformal kde coverage 2: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}")
122122

123123

124+
obj = ms.LSBoostRegressor(col_sample=0.9, row_sample=0.9,
125+
replications=50,
126+
type_pi="kde",
127+
degree=2)
128+
print(obj.get_params())
129+
start = time()
130+
obj.fit(X_train, y_train)
131+
print(f"Elapsed: {time()-start}")
132+
start = time()
133+
preds = obj.predict(X_test, return_pi=True,
134+
method="splitconformal")
135+
print(time()-start)
136+
print(f"splitconformal kde coverage 2: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}")
137+
138+
124139

125140
# lasso
126141

mlsauce.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: mlsauce
3-
Version: 0.13.0
3+
Version: 0.13.1
44
Summary: Miscellaneous Statistical/Machine Learning tools
55
Maintainer: T. Moudiki
66
Maintainer-email: thierry.moudiki@gmail.com

mlsauce/booster/_booster_classifier.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
import platform
99
import warnings
10+
from sklearn.preprocessing import PolynomialFeatures
1011
from sklearn.base import BaseEstimator
1112
from sklearn.base import ClassifierMixin
1213

@@ -70,6 +71,9 @@ class LSBoostClassifier(BaseEstimator, ClassifierMixin):
7071
7172
cluster_scaling: str
7273
scaling method for clustering: currently 'standard', 'robust', 'minmax'
74+
75+
degree: int
76+
degree of features interactions to include in the model
7377
7478
"""
7579

@@ -92,6 +96,7 @@ def __init__(
9296
n_clusters=0,
9397
clustering_method="kmeans",
9498
cluster_scaling="standard",
99+
degree=0
95100
):
96101
if n_clusters > 0:
97102
assert clustering_method in (
@@ -142,6 +147,8 @@ def __init__(
142147
self.clustering_method = clustering_method
143148
self.cluster_scaling = cluster_scaling
144149
self.scaler_, self.label_encoder_, self.clusterer_ = None, None, None
150+
self.degree = degree
151+
self.poly_ = None
145152

146153
def fit(self, X, y, **kwargs):
147154
"""Fit Booster (classifier) to training data (X, y)
@@ -162,6 +169,10 @@ def fit(self, X, y, **kwargs):
162169
self: object.
163170
"""
164171

172+
if self.degree > 1:
173+
self.poly_ = PolynomialFeatures(degree=self.degree, interaction_only=True)
174+
X = self.poly_.fit_transform(X.copy())[:,1:]
175+
165176
if self.n_clusters > 0:
166177
clustered_X, self.scaler_, self.label_encoder_, self.clusterer_ = (
167178
cluster(
@@ -232,6 +243,9 @@ def predict_proba(self, X, **kwargs):
232243
233244
probability estimates for test data: {array-like}
234245
"""
246+
if self.degree > 0:
247+
X = self.poly_.transform(X.copy())[:,1:]
248+
235249
if self.n_clusters > 0:
236250
X = np.column_stack(
237251
(

mlsauce/booster/_booster_regressor.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import warnings
1010
from sklearn.base import BaseEstimator
1111
from sklearn.base import RegressorMixin
12+
from sklearn.preprocessing import PolynomialFeatures
1213
from . import _boosterc as boosterc
1314
from ..predictioninterval import PredictionInterval
1415
from ..utils import cluster
@@ -81,6 +82,9 @@ class LSBoostRegressor(BaseEstimator, RegressorMixin):
8182
8283
cluster_scaling: str
8384
scaling method for clustering: currently 'standard', 'robust', 'minmax'
85+
86+
degree: int
87+
degree of features interactions to include in the model
8488
8589
"""
8690

@@ -106,6 +110,7 @@ def __init__(
106110
n_clusters=0,
107111
clustering_method="kmeans",
108112
cluster_scaling="standard",
113+
degree=0
109114
):
110115
if n_clusters > 0:
111116
assert clustering_method in (
@@ -158,7 +163,9 @@ def __init__(
158163
self.n_clusters = n_clusters
159164
self.clustering_method = clustering_method
160165
self.cluster_scaling = cluster_scaling
161-
self.scaler_, self.label_encoder_, self.clusterer_ = None, None, None
166+
self.scaler_, self.label_encoder_, self.clusterer_ = None, None, None
167+
self.degree = degree
168+
self.poly_ = None
162169

163170
def fit(self, X, y, **kwargs):
164171
"""Fit Booster (regressor) to training data (X, y)
@@ -179,6 +186,10 @@ def fit(self, X, y, **kwargs):
179186
self: object.
180187
"""
181188

189+
if self.degree > 1:
190+
self.poly_ = PolynomialFeatures(degree=self.degree, interaction_only=True)
191+
X = self.poly_.fit_transform(X.copy())[:,1:]
192+
182193
if self.n_clusters > 0:
183194
clustered_X, self.scaler_, self.label_encoder_, self.clusterer_ = (
184195
cluster(
@@ -242,6 +253,8 @@ def predict(self, X, level=95, method=None, **kwargs):
242253
243254
probability estimates for test data: {array-like}
244255
"""
256+
if self.degree > 0:
257+
X = self.poly_.transform(X.copy())[:,1:]
245258

246259
if self.n_clusters > 0:
247260
X = np.column_stack(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
MAINTAINER_EMAIL = 'thierry.moudiki@gmail.com'
3939
LICENSE = 'BSD3 Clause Clear'
4040

41-
__version__ = '0.13.1'
41+
__version__ = '0.14.0'
4242

4343
VERSION = __version__
4444

0 commit comments

Comments
 (0)