Skip to content

Commit

Permalink
fix building extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymoudiki committed Apr 25, 2024
1 parent b2276fc commit 04eddae
Show file tree
Hide file tree
Showing 17 changed files with 754 additions and 646 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# version 0.13.0
# version 0.13.1

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

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ dist: clean ## builds source and wheel package
ls -l dist

install: clean ## install the package to the active Python's site-packages
python3 -m pip install .
python3 -m pip install . --verbose

run-examples: ## run all examples with one command
find examples -maxdepth 2 -name "*.py" -exec python3 {} \;
3 changes: 3 additions & 0 deletions examples/lsboost_regressor_pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")

print(os.path.dirname(
os.path.abspath(__file__)
))

subprocess.check_call([sys.executable, "-m", "pip", "install", "matplotlib"])

Expand Down
63 changes: 38 additions & 25 deletions mlsauce/adaopt/_adaopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
from numpy.linalg import norm
from tqdm import tqdm
from ..utils import subsample
from ..utils import cluster
from ..utils import cluster

try:
from . import _adaoptc as adaoptc
except ImportError:
pass
import pyximport

pyximport.install()
import _adaoptc as adaoptc

class AdaOpt(BaseEstimator, ClassifierMixin):
"""AdaOpt classifier.
Expand Down Expand Up @@ -72,15 +74,15 @@ class AdaOpt(BaseEstimator, ClassifierMixin):
cache: boolean
if the nearest neighbors are cached or not, for faster retrieval in
subsequent calls.
n_clusters_input: int
number of clusters (a priori) for clustering the features
clustering_method: str
clustering method: currently 'kmeans', 'gmm'
cluster_scaling: str
scaling method for clustering: currently 'standard', 'robust', 'minmax'
scaling method for clustering: currently 'standard', 'robust', 'minmax'
seed: int
reproducibility seed for nodes_sim=='uniform', clustering and dropout.
Expand All @@ -104,12 +106,12 @@ def __init__(
n_jobs=None,
verbose=0,
cache=True,
n_clusters_input = 0,
clustering_method = "kmeans",
cluster_scaling = "standard",
n_clusters_input=0,
clustering_method="kmeans",
cluster_scaling="standard",
seed=123,
):
if n_clusters_input > 0:
if n_clusters_input > 0:
assert clustering_method in (
"kmeans",
"gmm",
Expand Down Expand Up @@ -145,7 +147,7 @@ def __init__(
self.n_clusters_input = n_clusters_input
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.seed = seed

def fit(self, X, y, **kwargs):
Expand All @@ -168,12 +170,17 @@ def fit(self, X, y, **kwargs):
"""

if self.n_clusters_input > 0:
clustered_X, self.scaler_, self.label_encoder_, self.clusterer_ = cluster(X, n_clusters=self.n_clusters_input,
method=self.clustering_method,
type_scaling=self.cluster_scaling,
training=True,
seed=self.seed)
if self.n_clusters_input > 0:
clustered_X, self.scaler_, self.label_encoder_, self.clusterer_ = (
cluster(
X,
n_clusters=self.n_clusters_input,
method=self.clustering_method,
type_scaling=self.cluster_scaling,
training=True,
seed=self.seed,
)
)
X = np.column_stack((X.copy(), clustered_X))

if self.row_sample < 1:
Expand Down Expand Up @@ -212,7 +219,7 @@ def fit(self, X, y, **kwargs):
self.alphas = res["alphas"]
self.n_iterations = res["n_iterations"]
self.scaled_X_train = np.array(res["scaled_X_train"], dtype=np.float64)
self.n_classes_ = len(np.unique(y)) # for compatibility with sklearn
self.n_classes_ = len(np.unique(y)) # for compatibility with sklearn
return self

def predict(self, X, **kwargs):
Expand Down Expand Up @@ -255,13 +262,19 @@ def predict_proba(self, X, **kwargs):
n_train, p_train = self.scaled_X_train.shape

if self.n_clusters_input > 0:
X = np.column_stack((X.copy(), cluster(
X, training=False,
scaler=self.scaler_,
label_encoder=self.label_encoder_,
clusterer=self.clusterer_,
seed=self.seed
)))
X = np.column_stack(
(
X.copy(),
cluster(
X,
training=False,
scaler=self.scaler_,
label_encoder=self.label_encoder_,
clusterer=self.clusterer_,
seed=self.seed,
),
)
)

n_test = X.shape[0]

Expand Down
Loading

0 comments on commit 04eddae

Please sign in to comment.