Skip to content

Commit 6cb4d5d

Browse files
Merge pull request #35 from vincent-laurent/main
[DEV] Improve performance
2 parents 4cda527 + ba08a0e commit 6cb4d5d

25 files changed

+478
-283
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ exclude_lines =
2121
# Don't complain if non-runnable code isn't run:
2222
if 0:
2323
if __name__ == .__main__.:
24+
break
2425
[run]
2526
omit = *tests*

.github/workflows/pytest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Pytest
22
permissions:
33
contents: write
4+
pages: write
45

56
on:
67
push:

.static/logoEurobiosMewsLabs.png

-41.9 KB
Loading

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<img src="./.static/logo.png" width="200"/>
1+
<img src=".static/logo.png" width="200"/>
22

33
### _Project for Automated Learning MAchine_
44

docs/source/conf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import sys
1010

1111
sys.path.insert(0, os.path.abspath('../'))
12-
sys.path.insert(0, os.path.abspath('.'))
12+
sys.path.insert(0, os.path.abspath("../../"))
1313

1414
project = 'palma'
1515
copyright = '2024, Eurobios-Mews-Labs'
@@ -38,7 +38,8 @@
3838
# -- Options for HTML output -------------------------------------------------
3939
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
4040

41-
html_theme = 'sphinx_book_theme'
41+
html_theme = "sphinx_book_theme"
42+
# html_style = '_static/palma.css'
4243
html_static_path = ['../../.static']
4344
source_suffix = {
4445
'.rst': 'restructuredtext',

docs/source/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
sphinx-quickstart on Thu Jan 4 17:25:24 2024.
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
5-
.. image:: ../../.static/logo.png
5+
6+
.. image:: https://raw.githubusercontent.com/eurobios-mews-labs/palma/main/.static/logo.png
67
:width: 200
78

89
\

examples/classification.ipynb

Lines changed: 41 additions & 129 deletions
Large diffs are not rendered by default.

palma/base/engine.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from flaml import AutoML
1717
from sklearn import base
1818

19+
from palma.base.splitting_strategy import ValidationStrategy
20+
1921
try:
2022
from autosklearn.classification import AutoSklearnClassifier
2123
from autosklearn.regression import AutoSklearnRegressor
@@ -29,7 +31,8 @@ def __init__(self, engine_parameters: dict) -> None:
2931
self.__engine_parameters = engine_parameters
3032

3133
@abstractmethod
32-
def optimize(self, X: pd.DataFrame, y: pd.Series, splitter=None
34+
def optimize(self, X: pd.DataFrame, y: pd.Series,
35+
splitter: "ValidationStrategy" = None
3336
) -> None:
3437
...
3538

@@ -87,13 +90,13 @@ def optimize(self, X: pd.DataFrame, y: pd.Series, splitter=None) -> None:
8790
@property
8891
def optimizer(self) -> Union[
8992
'AutoSklearnClassifier',
90-
'AutoSklearnRegressor']:
93+
'AutoSklearnRegressor']:
9194
return self.__optimizer
9295

9396
@property
9497
def estimator_(self) -> Union[
9598
'AutoSklearnClassifier',
96-
'AutoSklearnRegressor']:
99+
'AutoSklearnRegressor']:
97100
return self.__optimizer.get_models_with_weights()
98101

99102
@property
@@ -111,14 +114,20 @@ def __init__(self, problem: str, engine_parameters: dict) -> None:
111114
)
112115
engine_parameters["task"] = problem
113116

114-
def optimize(self, X: pd.DataFrame, y: pd.DataFrame, splitter=None
117+
def optimize(self, X: pd.DataFrame, y: pd.DataFrame,
118+
splitter: ValidationStrategy = None
115119
) -> None:
120+
split_type = None if splitter is None else splitter.splitter
121+
groups = None if splitter is None else splitter.groups
122+
groups = groups if groups is None else groups[splitter.train_index]
123+
116124
self.allowing_splitter(splitter)
117125
self.__optimizer = AutoML()
118126
self.__optimizer.fit(
119127
X_train=pd.DataFrame(X.values, index=range(len(X))),
120128
y_train=pd.Series(y.values, index=range(len(X))),
121-
split_type=splitter, mlflow_logging=False,
129+
split_type=split_type, groups=groups,
130+
mlflow_logging=False,
122131
**self.engine_parameters
123132
)
124133

palma/base/model_selection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,20 @@ def start(self, project: "Project"):
4747
self.engine_.optimize(
4848
project.X.iloc[project.validation_strategy.train_index],
4949
project.y.iloc[project.validation_strategy.train_index],
50-
splitter=project.validation_strategy.splitter
50+
splitter=project.validation_strategy,
5151
)
5252
self.best_model_ = self.engine_.estimator_
5353
logging.basicConfig(level=logging.DEBUG)
5454

5555
logger.logger.log_artifact(
5656
self.engine_.estimator_,
5757
self.__run_id)
58+
try:
59+
logger.logger.log_metrics(
60+
{"best_estimator": str(self.best_model_)}, 'model_selection'
61+
)
62+
except:
63+
pass
5864

5965
@property
6066
def run_id(self) -> str:

palma/base/project.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def start(
9090
from palma.utils.checker import ProjectPlanChecker
9191
from palma import logger
9292
self.__validation_strategy = ValidationStrategy(splitter)
93-
self.__base_index = list(range(len(X)))
9493
self.__X, self.__y = self.__validation_strategy(
9594
X=X, y=y, X_test=X_test, y_test=y_test,
9695
groups=groups)
@@ -108,10 +107,6 @@ def __call_components(self, object_: "Project") -> None:
108107
for _, component in self.components.items():
109108
component(object_)
110109

111-
@property
112-
def base_index(self) -> List[int]:
113-
return self.__base_index
114-
115110
@property
116111
def components(self) -> dict:
117112
return self.__components

0 commit comments

Comments
 (0)