Skip to content

Commit

Permalink
bump -> v0.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymoudiki committed Apr 25, 2024
1 parent ee690c5 commit 75f43ec
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# version 0.14.0

- add polynomial (interactions) features to `LSBoostRegressor` and `LSBoostClassifier`

# version 0.13.1

- add clustering to `LSBoostRegressor`, `LSBoostClassifier`, and `AdaOpt`
Expand Down
14 changes: 14 additions & 0 deletions examples/lsboost_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@
start = time()
print(obj.score(X_test, y_test))
print(time()-start)
print(f"loss: {np.log(obj.obj['loss'])}")

obj = ms.LSBoostClassifier(solver="lasso",
n_clusters=3,
clustering_method="gmm",
degree=2)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(obj.score(X_test, y_test))
print(time()-start)
print(f"loss: {np.log(obj.obj['loss'])}")

# MORE DATA NEEDED # MORE DATA NEEDED # MORE DATA NEEDED
# obj = ms.LSBoostClassifier(backend="gpu", solver="lasso")
Expand Down
15 changes: 15 additions & 0 deletions examples/lsboost_regressor_pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@
print(f"splitconformal kde coverage 2: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}")


obj = ms.LSBoostRegressor(col_sample=0.9, row_sample=0.9,
replications=50,
type_pi="kde",
degree=2)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(f"Elapsed: {time()-start}")
start = time()
preds = obj.predict(X_test, return_pi=True,
method="splitconformal")
print(time()-start)
print(f"splitconformal kde coverage 2: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}")



# lasso

Expand Down
2 changes: 1 addition & 1 deletion mlsauce.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: mlsauce
Version: 0.13.0
Version: 0.13.1
Summary: Miscellaneous Statistical/Machine Learning tools
Maintainer: T. Moudiki
Maintainer-email: [email protected]
Expand Down
14 changes: 14 additions & 0 deletions mlsauce/booster/_booster_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import platform
import warnings
from sklearn.preprocessing import PolynomialFeatures
from sklearn.base import BaseEstimator
from sklearn.base import ClassifierMixin

Expand Down Expand Up @@ -70,6 +71,9 @@ class LSBoostClassifier(BaseEstimator, ClassifierMixin):
cluster_scaling: str
scaling method for clustering: currently 'standard', 'robust', 'minmax'
degree: int
degree of features interactions to include in the model
"""

Expand All @@ -92,6 +96,7 @@ def __init__(
n_clusters=0,
clustering_method="kmeans",
cluster_scaling="standard",
degree=0
):
if n_clusters > 0:
assert clustering_method in (
Expand Down Expand Up @@ -142,6 +147,8 @@ def __init__(
self.clustering_method = clustering_method
self.cluster_scaling = cluster_scaling
self.scaler_, self.label_encoder_, self.clusterer_ = None, None, None
self.degree = degree
self.poly_ = None

def fit(self, X, y, **kwargs):
"""Fit Booster (classifier) to training data (X, y)
Expand All @@ -162,6 +169,10 @@ def fit(self, X, y, **kwargs):
self: object.
"""

if self.degree > 1:
self.poly_ = PolynomialFeatures(degree=self.degree, interaction_only=True)
X = self.poly_.fit_transform(X.copy())[:,1:]

if self.n_clusters > 0:
clustered_X, self.scaler_, self.label_encoder_, self.clusterer_ = (
cluster(
Expand Down Expand Up @@ -232,6 +243,9 @@ def predict_proba(self, X, **kwargs):
probability estimates for test data: {array-like}
"""
if self.degree > 0:
X = self.poly_.transform(X.copy())[:,1:]

if self.n_clusters > 0:
X = np.column_stack(
(
Expand Down
15 changes: 14 additions & 1 deletion mlsauce/booster/_booster_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import warnings
from sklearn.base import BaseEstimator
from sklearn.base import RegressorMixin
from sklearn.preprocessing import PolynomialFeatures
from . import _boosterc as boosterc
from ..predictioninterval import PredictionInterval
from ..utils import cluster
Expand Down Expand Up @@ -81,6 +82,9 @@ class LSBoostRegressor(BaseEstimator, RegressorMixin):
cluster_scaling: str
scaling method for clustering: currently 'standard', 'robust', 'minmax'
degree: int
degree of features interactions to include in the model
"""

Expand All @@ -106,6 +110,7 @@ def __init__(
n_clusters=0,
clustering_method="kmeans",
cluster_scaling="standard",
degree=0
):
if n_clusters > 0:
assert clustering_method in (
Expand Down Expand Up @@ -158,7 +163,9 @@ def __init__(
self.n_clusters = n_clusters
self.clustering_method = clustering_method
self.cluster_scaling = cluster_scaling
self.scaler_, self.label_encoder_, self.clusterer_ = None, None, None
self.scaler_, self.label_encoder_, self.clusterer_ = None, None, None
self.degree = degree
self.poly_ = None

def fit(self, X, y, **kwargs):
"""Fit Booster (regressor) to training data (X, y)
Expand All @@ -179,6 +186,10 @@ def fit(self, X, y, **kwargs):
self: object.
"""

if self.degree > 1:
self.poly_ = PolynomialFeatures(degree=self.degree, interaction_only=True)
X = self.poly_.fit_transform(X.copy())[:,1:]

if self.n_clusters > 0:
clustered_X, self.scaler_, self.label_encoder_, self.clusterer_ = (
cluster(
Expand Down Expand Up @@ -242,6 +253,8 @@ def predict(self, X, level=95, method=None, **kwargs):
probability estimates for test data: {array-like}
"""
if self.degree > 0:
X = self.poly_.transform(X.copy())[:,1:]

if self.n_clusters > 0:
X = np.column_stack(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
MAINTAINER_EMAIL = '[email protected]'
LICENSE = 'BSD3 Clause Clear'

__version__ = '0.13.1'
__version__ = '0.14.0'

VERSION = __version__

Expand Down

0 comments on commit 75f43ec

Please sign in to comment.