mljar-supervised 1.2.1__tar.gz → 1.3.0__tar.gz
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.
- {mljar_supervised-1.2.1/mljar_supervised.egg-info → mljar_supervised-1.3.0}/PKG-INFO +6 -6
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/README.md +5 -5
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0/mljar_supervised.egg-info}/PKG-INFO +6 -6
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/mljar_supervised.egg-info/SOURCES.txt +7 -0
- mljar_supervised-1.3.0/requirements_dev.txt +9 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/setup.py +1 -1
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/__init__.py +1 -1
- mljar_supervised-1.3.0/supervised/apps/__init__.py +5 -0
- mljar_supervised-1.3.0/supervised/apps/generator.py +230 -0
- mljar_supervised-1.3.0/supervised/apps/local_runner.py +120 -0
- mljar_supervised-1.3.0/supervised/apps/metadata.py +328 -0
- mljar_supervised-1.3.0/supervised/apps/publisher.py +486 -0
- mljar_supervised-1.3.0/supervised/apps/templates.py +626 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/automl.py +41 -6
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/base_automl.py +43 -7
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/exceptions.py +0 -1
- mljar_supervised-1.3.0/supervised/fairness/certificate.py +129 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/fairness/report.py +55 -2
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/additional_metrics.py +40 -3
- mljar_supervised-1.3.0/supervised/utils/report_structured.py +749 -0
- mljar_supervised-1.2.1/requirements_dev.txt +0 -4
- mljar_supervised-1.2.1/supervised/utils/report_structured.py +0 -525
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/LICENSE +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/MANIFEST.in +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/mljar_supervised.egg-info/dependency_links.txt +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/mljar_supervised.egg-info/requires.txt +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/mljar_supervised.egg-info/top_level.txt +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/requirements.txt +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/setup.cfg +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/__init__.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/algorithm.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/baseline.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/catboost.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/decision_tree.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/extra_trees.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/factory.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/knn.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/lightgbm.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/linear.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/nn.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/random_forest.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/registry.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/sklearn.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/algorithms/xgboost.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/callbacks/__init__.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/callbacks/callback.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/callbacks/callback_list.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/callbacks/early_stopping.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/callbacks/learner_time_constraint.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/callbacks/max_iters_constraint.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/callbacks/metric_logger.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/callbacks/terminate_on_nan.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/callbacks/total_time_constraint.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/ensemble.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/fairness/__init__.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/fairness/metrics.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/fairness/optimization.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/fairness/plots.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/fairness/utils.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/model_framework.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/__init__.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/datetime_transformer.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/encoding_selector.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/exclude_missing_target.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/goldenfeatures_transformer.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/kmeans_transformer.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/label_binarizer.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/label_encoder.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/preprocessing.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/preprocessing_categorical.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/preprocessing_missing.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/preprocessing_utils.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/scale.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/preprocessing/text_transformer.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/__init__.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/data_info.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/hill_climbing.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/mljar_tuner.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/optuna/__init__.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/optuna/catboost.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/optuna/extra_trees.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/optuna/knn.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/optuna/lightgbm.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/optuna/nn.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/optuna/random_forest.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/optuna/tuner.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/optuna/xgboost.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/preprocessing_tuner.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/random_parameters.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/tuner/time_controller.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/__init__.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/additional_plots.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/automl_plots.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/common.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/config.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/constants.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/data_validation.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/importance.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/jsonencoder.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/leaderboard_plots.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/learning_curves.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/metric.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/shap.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/subsample.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/utils/utils.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/validation/__init__.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/validation/validation_step.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/validation/validator_base.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/validation/validator_custom.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/validation/validator_kfold.py +0 -0
- {mljar_supervised-1.2.1 → mljar_supervised-1.3.0}/supervised/validation/validator_split.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mljar-supervised
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Automated Machine Learning for Humans
|
|
5
5
|
Home-page: https://github.com/mljar/mljar-supervised
|
|
6
6
|
Author: MLJAR, Sp. z o.o.
|
|
@@ -116,7 +116,7 @@ Start quickly, iterate faster, and manage experiments in one place.
|
|
|
116
116
|
The `mljar-supervised` is an Automated Machine Learning Python package that works with tabular data. It is designed to save time for a data scientist. It abstracts the common way to preprocess the data, construct the machine learning models, and perform hyper-parameters tuning to find the best model :trophy:. It is no black box, as you can see exactly how the ML pipeline is constructed (with a detailed Markdown report for each ML model).
|
|
117
117
|
|
|
118
118
|
The `mljar-supervised` will help you with:
|
|
119
|
-
- explaining and understanding your data
|
|
119
|
+
- explaining and understanding your data through model reports, feature importance, and SHAP explanations,
|
|
120
120
|
- trying many different machine learning models (Algorithm Selection and Hyper-Parameters tuning),
|
|
121
121
|
- creating Markdown reports from analysis with details about all models (Automatic-Documentation),
|
|
122
122
|
- saving, re-running, and loading the analysis and ML models.
|
|
@@ -541,14 +541,14 @@ Each call creates/updates:
|
|
|
541
541
|
<results_path>/report_structured.json
|
|
542
542
|
```
|
|
543
543
|
|
|
544
|
-
Use
|
|
544
|
+
Use `model_name` to display detailed metrics for one selected model:
|
|
545
545
|
|
|
546
546
|
```python
|
|
547
|
-
compact = automl.report_structured(
|
|
548
|
-
detailed = automl.report_structured(
|
|
547
|
+
compact = automl.report_structured()
|
|
548
|
+
detailed = automl.report_structured(model_name="3_Linear")
|
|
549
549
|
```
|
|
550
550
|
|
|
551
|
-
|
|
551
|
+
When `model_name` is provided, the markdown includes detailed metrics, fairness details (if used), and feature importance summaries for that model.
|
|
552
552
|
|
|
553
553
|
# Installation
|
|
554
554
|
|
|
@@ -68,7 +68,7 @@ Start quickly, iterate faster, and manage experiments in one place.
|
|
|
68
68
|
The `mljar-supervised` is an Automated Machine Learning Python package that works with tabular data. It is designed to save time for a data scientist. It abstracts the common way to preprocess the data, construct the machine learning models, and perform hyper-parameters tuning to find the best model :trophy:. It is no black box, as you can see exactly how the ML pipeline is constructed (with a detailed Markdown report for each ML model).
|
|
69
69
|
|
|
70
70
|
The `mljar-supervised` will help you with:
|
|
71
|
-
- explaining and understanding your data
|
|
71
|
+
- explaining and understanding your data through model reports, feature importance, and SHAP explanations,
|
|
72
72
|
- trying many different machine learning models (Algorithm Selection and Hyper-Parameters tuning),
|
|
73
73
|
- creating Markdown reports from analysis with details about all models (Automatic-Documentation),
|
|
74
74
|
- saving, re-running, and loading the analysis and ML models.
|
|
@@ -493,14 +493,14 @@ Each call creates/updates:
|
|
|
493
493
|
<results_path>/report_structured.json
|
|
494
494
|
```
|
|
495
495
|
|
|
496
|
-
Use
|
|
496
|
+
Use `model_name` to display detailed metrics for one selected model:
|
|
497
497
|
|
|
498
498
|
```python
|
|
499
|
-
compact = automl.report_structured(
|
|
500
|
-
detailed = automl.report_structured(
|
|
499
|
+
compact = automl.report_structured()
|
|
500
|
+
detailed = automl.report_structured(model_name="3_Linear")
|
|
501
501
|
```
|
|
502
502
|
|
|
503
|
-
|
|
503
|
+
When `model_name` is provided, the markdown includes detailed metrics, fairness details (if used), and feature importance summaries for that model.
|
|
504
504
|
|
|
505
505
|
# Installation
|
|
506
506
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mljar-supervised
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Automated Machine Learning for Humans
|
|
5
5
|
Home-page: https://github.com/mljar/mljar-supervised
|
|
6
6
|
Author: MLJAR, Sp. z o.o.
|
|
@@ -116,7 +116,7 @@ Start quickly, iterate faster, and manage experiments in one place.
|
|
|
116
116
|
The `mljar-supervised` is an Automated Machine Learning Python package that works with tabular data. It is designed to save time for a data scientist. It abstracts the common way to preprocess the data, construct the machine learning models, and perform hyper-parameters tuning to find the best model :trophy:. It is no black box, as you can see exactly how the ML pipeline is constructed (with a detailed Markdown report for each ML model).
|
|
117
117
|
|
|
118
118
|
The `mljar-supervised` will help you with:
|
|
119
|
-
- explaining and understanding your data
|
|
119
|
+
- explaining and understanding your data through model reports, feature importance, and SHAP explanations,
|
|
120
120
|
- trying many different machine learning models (Algorithm Selection and Hyper-Parameters tuning),
|
|
121
121
|
- creating Markdown reports from analysis with details about all models (Automatic-Documentation),
|
|
122
122
|
- saving, re-running, and loading the analysis and ML models.
|
|
@@ -541,14 +541,14 @@ Each call creates/updates:
|
|
|
541
541
|
<results_path>/report_structured.json
|
|
542
542
|
```
|
|
543
543
|
|
|
544
|
-
Use
|
|
544
|
+
Use `model_name` to display detailed metrics for one selected model:
|
|
545
545
|
|
|
546
546
|
```python
|
|
547
|
-
compact = automl.report_structured(
|
|
548
|
-
detailed = automl.report_structured(
|
|
547
|
+
compact = automl.report_structured()
|
|
548
|
+
detailed = automl.report_structured(model_name="3_Linear")
|
|
549
549
|
```
|
|
550
550
|
|
|
551
|
-
|
|
551
|
+
When `model_name` is provided, the markdown includes detailed metrics, fairness details (if used), and feature importance summaries for that model.
|
|
552
552
|
|
|
553
553
|
# Installation
|
|
554
554
|
|
|
@@ -30,6 +30,12 @@ supervised/algorithms/random_forest.py
|
|
|
30
30
|
supervised/algorithms/registry.py
|
|
31
31
|
supervised/algorithms/sklearn.py
|
|
32
32
|
supervised/algorithms/xgboost.py
|
|
33
|
+
supervised/apps/__init__.py
|
|
34
|
+
supervised/apps/generator.py
|
|
35
|
+
supervised/apps/local_runner.py
|
|
36
|
+
supervised/apps/metadata.py
|
|
37
|
+
supervised/apps/publisher.py
|
|
38
|
+
supervised/apps/templates.py
|
|
33
39
|
supervised/callbacks/__init__.py
|
|
34
40
|
supervised/callbacks/callback.py
|
|
35
41
|
supervised/callbacks/callback_list.py
|
|
@@ -40,6 +46,7 @@ supervised/callbacks/metric_logger.py
|
|
|
40
46
|
supervised/callbacks/terminate_on_nan.py
|
|
41
47
|
supervised/callbacks/total_time_constraint.py
|
|
42
48
|
supervised/fairness/__init__.py
|
|
49
|
+
supervised/fairness/certificate.py
|
|
43
50
|
supervised/fairness/metrics.py
|
|
44
51
|
supervised/fairness/optimization.py
|
|
45
52
|
supervised/fairness/plots.py
|
|
@@ -10,7 +10,7 @@ with open(path.join(here, "README.md"), encoding="utf-8") as f:
|
|
|
10
10
|
|
|
11
11
|
setup(
|
|
12
12
|
name="mljar-supervised",
|
|
13
|
-
version="1.
|
|
13
|
+
version="1.3.0",
|
|
14
14
|
description="Automated Machine Learning for Humans",
|
|
15
15
|
long_description=long_description,
|
|
16
16
|
long_description_content_type="text/markdown",
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
import shlex
|
|
6
|
+
import tempfile
|
|
7
|
+
import zipfile
|
|
8
|
+
|
|
9
|
+
from supervised.apps.metadata import collect_app_metadata
|
|
10
|
+
from supervised.apps.templates import (
|
|
11
|
+
app_support_source,
|
|
12
|
+
batch_notebook_source,
|
|
13
|
+
config_toml,
|
|
14
|
+
readme_md,
|
|
15
|
+
requirements_txt,
|
|
16
|
+
runtime_txt,
|
|
17
|
+
single_notebook_source,
|
|
18
|
+
)
|
|
19
|
+
from supervised.exceptions import AutoMLException
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
PUBLISHABLE_WORKSPACE_FILES = (
|
|
23
|
+
"predict_single.ipynb",
|
|
24
|
+
"predict_batch.ipynb",
|
|
25
|
+
"app_support.py",
|
|
26
|
+
"config.toml",
|
|
27
|
+
"requirements.txt",
|
|
28
|
+
"runtime.txt",
|
|
29
|
+
"automl.zip",
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def generate_app(automl, path=None, overwrite=False, title=None, verbose=True):
|
|
34
|
+
results_path = automl._get_results_path()
|
|
35
|
+
_ensure_automl_ready(automl, results_path)
|
|
36
|
+
output_path = _resolve_output_path(results_path, path)
|
|
37
|
+
_prepare_output_dir(output_path, overwrite=overwrite)
|
|
38
|
+
|
|
39
|
+
selected_models = _selected_model_names(automl)
|
|
40
|
+
manifest = collect_app_metadata(
|
|
41
|
+
automl,
|
|
42
|
+
title=title,
|
|
43
|
+
selected_models=selected_models,
|
|
44
|
+
)
|
|
45
|
+
try:
|
|
46
|
+
_write_workspace(output_path, results_path, manifest, selected_models)
|
|
47
|
+
except Exception:
|
|
48
|
+
shutil.rmtree(output_path, ignore_errors=True)
|
|
49
|
+
raise
|
|
50
|
+
if verbose:
|
|
51
|
+
_print_verbose_summary(output_path)
|
|
52
|
+
return output_path
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def publishable_workspace_paths(output_path):
|
|
56
|
+
return [
|
|
57
|
+
os.path.join(output_path, filename) for filename in PUBLISHABLE_WORKSPACE_FILES
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _ensure_automl_ready(automl, results_path):
|
|
62
|
+
if results_path is None or not os.path.exists(os.path.join(results_path, "params.json")):
|
|
63
|
+
raise AutoMLException(
|
|
64
|
+
"This model has not been fitted yet. Please call `fit()` first."
|
|
65
|
+
)
|
|
66
|
+
if automl._best_model is None:
|
|
67
|
+
automl.load(results_path)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _prepare_output_dir(output_path, overwrite=False):
|
|
71
|
+
if os.path.exists(output_path):
|
|
72
|
+
if not overwrite:
|
|
73
|
+
raise AutoMLException(
|
|
74
|
+
f"Cannot generate app. Directory '{output_path}' already exists."
|
|
75
|
+
)
|
|
76
|
+
shutil.rmtree(output_path)
|
|
77
|
+
os.makedirs(output_path)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _resolve_output_path(results_path, path):
|
|
81
|
+
if path is None:
|
|
82
|
+
return os.path.abspath(os.path.join(results_path, "app"))
|
|
83
|
+
return os.path.abspath(path)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _selected_model_names(automl):
|
|
87
|
+
if automl._best_model is None:
|
|
88
|
+
automl.load(automl._get_results_path())
|
|
89
|
+
best_model_name = automl._best_model.get_name()
|
|
90
|
+
return automl.models_needed_on_predict(best_model_name)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _write_workspace(output_path, results_path, manifest, selected_models):
|
|
94
|
+
_create_automl_zip(output_path, results_path, selected_models)
|
|
95
|
+
_write_json(os.path.join(output_path, "mljar_app.json"), manifest)
|
|
96
|
+
notebook_sources = {
|
|
97
|
+
"predict_single.ipynb": single_notebook_source(),
|
|
98
|
+
"predict_batch.ipynb": batch_notebook_source(),
|
|
99
|
+
}
|
|
100
|
+
for notebook in manifest.get("notebooks", []):
|
|
101
|
+
filename = notebook.get("filename")
|
|
102
|
+
payload = notebook_sources.get(filename)
|
|
103
|
+
if payload is not None:
|
|
104
|
+
_write_json(os.path.join(output_path, filename), payload)
|
|
105
|
+
_write_text(os.path.join(output_path, "app_support.py"), app_support_source())
|
|
106
|
+
_write_text(os.path.join(output_path, "config.toml"), config_toml(manifest["title"]))
|
|
107
|
+
_write_text(os.path.join(output_path, "requirements.txt"), requirements_txt())
|
|
108
|
+
_write_text(os.path.join(output_path, "runtime.txt"), runtime_txt())
|
|
109
|
+
_write_text(os.path.join(output_path, "README.md"), readme_md())
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _write_json(path, payload):
|
|
113
|
+
with open(path, "w", encoding="utf-8") as fout:
|
|
114
|
+
json.dump(payload, fout, indent=2)
|
|
115
|
+
fout.write("\n")
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _write_text(path, payload):
|
|
119
|
+
with open(path, "w", encoding="utf-8") as fout:
|
|
120
|
+
fout.write(payload)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _print_verbose_summary(output_path):
|
|
124
|
+
quoted_path = shlex.quote(output_path)
|
|
125
|
+
mercury_command = f"mercury --working-dir={quoted_path}"
|
|
126
|
+
manifest = _load_manifest(output_path)
|
|
127
|
+
|
|
128
|
+
print(f"App directory: {output_path}")
|
|
129
|
+
if manifest and not manifest.get("supports", {}).get("single_sample", True):
|
|
130
|
+
feature_count = len(manifest.get("feature_schema", []))
|
|
131
|
+
print(
|
|
132
|
+
"Single prediction UI was skipped because the model has "
|
|
133
|
+
f"{feature_count} features, which is above the 15-feature limit."
|
|
134
|
+
)
|
|
135
|
+
print("Generated app includes batch CSV prediction only.")
|
|
136
|
+
print(f"Enter app directory: cd {quoted_path}")
|
|
137
|
+
try:
|
|
138
|
+
importlib.import_module("mercury")
|
|
139
|
+
except ImportError:
|
|
140
|
+
print(
|
|
141
|
+
"Mercury is not available in the current Python environment. "
|
|
142
|
+
"Install it with: pip install -r requirements.txt"
|
|
143
|
+
)
|
|
144
|
+
print(f"Start Mercury: {mercury_command}")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _load_manifest(output_path):
|
|
148
|
+
manifest_path = os.path.join(output_path, "mljar_app.json")
|
|
149
|
+
if not os.path.exists(manifest_path):
|
|
150
|
+
return None
|
|
151
|
+
with open(manifest_path, "r", encoding="utf-8") as fin:
|
|
152
|
+
return json.load(fin)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _create_automl_zip(output_path, results_path, selected_models):
|
|
156
|
+
zip_path = os.path.join(output_path, "automl.zip")
|
|
157
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
|
158
|
+
bundle_root = os.path.join(temp_dir, "automl")
|
|
159
|
+
os.makedirs(bundle_root)
|
|
160
|
+
_write_json(
|
|
161
|
+
os.path.join(bundle_root, "params.json"),
|
|
162
|
+
_build_minimal_params(results_path, selected_models),
|
|
163
|
+
)
|
|
164
|
+
_copy_root_runtime_files(results_path, bundle_root, selected_models)
|
|
165
|
+
_copy_selected_model_dirs(results_path, bundle_root, selected_models)
|
|
166
|
+
|
|
167
|
+
with zipfile.ZipFile(zip_path, "w", compression=zipfile.ZIP_DEFLATED) as zf:
|
|
168
|
+
for root, _, files in os.walk(temp_dir):
|
|
169
|
+
for filename in files:
|
|
170
|
+
file_path = os.path.join(root, filename)
|
|
171
|
+
arcname = os.path.relpath(file_path, temp_dir)
|
|
172
|
+
zf.write(file_path, arcname)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _build_minimal_params(results_path, selected_models):
|
|
176
|
+
with open(os.path.join(results_path, "params.json"), "r", encoding="utf-8") as fin:
|
|
177
|
+
params = json.load(fin)
|
|
178
|
+
|
|
179
|
+
params["saved"] = [name for name in params.get("saved", []) if name in selected_models]
|
|
180
|
+
params["load_on_predict"] = list(selected_models)
|
|
181
|
+
if "stacked" in params:
|
|
182
|
+
params["stacked"] = [
|
|
183
|
+
name for name in params.get("stacked", []) if name in selected_models
|
|
184
|
+
]
|
|
185
|
+
params["results_path"] = "automl"
|
|
186
|
+
return params
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _copy_root_runtime_files(results_path, bundle_root, selected_models):
|
|
190
|
+
root_files = ["data_info.json"]
|
|
191
|
+
if _needs_golden_features(results_path, selected_models):
|
|
192
|
+
root_files.append("golden_features.json")
|
|
193
|
+
|
|
194
|
+
for filename in root_files:
|
|
195
|
+
source = os.path.join(results_path, filename)
|
|
196
|
+
if os.path.exists(source):
|
|
197
|
+
shutil.copy2(source, os.path.join(bundle_root, filename))
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _needs_golden_features(results_path, selected_models):
|
|
201
|
+
for model_name in selected_models:
|
|
202
|
+
framework_path = os.path.join(results_path, model_name, "framework.json")
|
|
203
|
+
if not os.path.exists(framework_path):
|
|
204
|
+
continue
|
|
205
|
+
with open(framework_path, "r", encoding="utf-8") as fin:
|
|
206
|
+
framework = json.load(fin)
|
|
207
|
+
for preprocessing in framework.get("preprocessing", []):
|
|
208
|
+
if "golden_features" in preprocessing:
|
|
209
|
+
return True
|
|
210
|
+
return False
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def _copy_selected_model_dirs(results_path, bundle_root, selected_models):
|
|
214
|
+
for model_name in selected_models:
|
|
215
|
+
source = os.path.join(results_path, model_name)
|
|
216
|
+
target = os.path.join(bundle_root, model_name)
|
|
217
|
+
if os.path.isdir(source):
|
|
218
|
+
shutil.copytree(source, target, ignore=_ignore_non_runtime_files)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def _ignore_non_runtime_files(_, names):
|
|
222
|
+
ignored = []
|
|
223
|
+
for name in names:
|
|
224
|
+
lower = name.lower()
|
|
225
|
+
if lower in {"readme.md", "readme.html"}:
|
|
226
|
+
ignored.append(name)
|
|
227
|
+
continue
|
|
228
|
+
if lower.endswith((".png", ".svg", ".html", ".md", ".log")):
|
|
229
|
+
ignored.append(name)
|
|
230
|
+
return ignored
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import shutil
|
|
3
|
+
import socket
|
|
4
|
+
import subprocess
|
|
5
|
+
import time
|
|
6
|
+
import webbrowser
|
|
7
|
+
from urllib import error as urllib_error
|
|
8
|
+
from urllib import request as urllib_request
|
|
9
|
+
|
|
10
|
+
from supervised.apps.generator import generate_app
|
|
11
|
+
from supervised.exceptions import AutoMLException
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
LOCAL_APP_HOST = "127.0.0.1"
|
|
15
|
+
LOCAL_APP_START_TIMEOUT_SECONDS = 30
|
|
16
|
+
LOCAL_APP_POLL_INTERVAL_SECONDS = 0.5
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def run_local_app_from_automl(automl):
|
|
20
|
+
app_dir = generate_app(automl, overwrite=True, verbose=False)
|
|
21
|
+
mercury_path = shutil.which("mercury")
|
|
22
|
+
if mercury_path is None:
|
|
23
|
+
raise AutoMLException(
|
|
24
|
+
"Mercury is not installed or not available in PATH. "
|
|
25
|
+
"Install it with: pip install -r requirements.txt"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
port = _get_free_port()
|
|
29
|
+
url = f"http://{LOCAL_APP_HOST}:{port}"
|
|
30
|
+
os.makedirs(app_dir, exist_ok=True)
|
|
31
|
+
log_path = os.path.join(app_dir, ".local_app.log")
|
|
32
|
+
with open(log_path, "w", encoding="utf-8") as log_file:
|
|
33
|
+
process = subprocess.Popen(
|
|
34
|
+
[
|
|
35
|
+
mercury_path,
|
|
36
|
+
f"--ip={LOCAL_APP_HOST}",
|
|
37
|
+
f"--port={port}",
|
|
38
|
+
"--no-browser",
|
|
39
|
+
],
|
|
40
|
+
cwd=app_dir,
|
|
41
|
+
stdout=log_file,
|
|
42
|
+
stderr=subprocess.STDOUT,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
_wait_until_ready(url, process, log_path)
|
|
46
|
+
webbrowser.open(url)
|
|
47
|
+
print(f"Local app URL: {url}")
|
|
48
|
+
print("Press Ctrl+C to stop the local app.")
|
|
49
|
+
automl._local_app_process = process
|
|
50
|
+
automl._local_app_url = url
|
|
51
|
+
return _wait_for_local_app_shutdown(process, log_path, url)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _get_free_port():
|
|
55
|
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|
56
|
+
sock.bind((LOCAL_APP_HOST, 0))
|
|
57
|
+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
58
|
+
return sock.getsockname()[1]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _wait_until_ready(url, process, log_path):
|
|
62
|
+
deadline = time.time() + LOCAL_APP_START_TIMEOUT_SECONDS
|
|
63
|
+
last_error = None
|
|
64
|
+
while time.time() < deadline:
|
|
65
|
+
if process.poll() is not None:
|
|
66
|
+
raise AutoMLException(_process_failure_message(process.returncode, log_path))
|
|
67
|
+
try:
|
|
68
|
+
with urllib_request.urlopen(url, timeout=2) as response:
|
|
69
|
+
if 200 <= getattr(response, "status", 200) < 500:
|
|
70
|
+
return
|
|
71
|
+
except urllib_error.URLError as exc:
|
|
72
|
+
last_error = exc
|
|
73
|
+
time.sleep(LOCAL_APP_POLL_INTERVAL_SECONDS)
|
|
74
|
+
|
|
75
|
+
raise AutoMLException(
|
|
76
|
+
"Mercury server did not start in time. "
|
|
77
|
+
f"Tried URL {url}. Last error: {last_error}"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _process_failure_message(returncode, log_path):
|
|
82
|
+
tail = _read_log_tail(log_path)
|
|
83
|
+
message = f"Mercury server exited with code {returncode}."
|
|
84
|
+
if tail:
|
|
85
|
+
message += f" Last log output:\n{tail}"
|
|
86
|
+
return message
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _wait_for_local_app_shutdown(process, log_path, url):
|
|
90
|
+
try:
|
|
91
|
+
returncode = process.wait()
|
|
92
|
+
except KeyboardInterrupt:
|
|
93
|
+
_stop_process(process)
|
|
94
|
+
return url
|
|
95
|
+
|
|
96
|
+
if returncode not in (None, 0):
|
|
97
|
+
raise AutoMLException(_process_failure_message(returncode, log_path))
|
|
98
|
+
return url
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _stop_process(process, timeout=5):
|
|
102
|
+
if process.poll() is not None:
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
process.terminate()
|
|
106
|
+
try:
|
|
107
|
+
process.wait(timeout=timeout)
|
|
108
|
+
except subprocess.TimeoutExpired:
|
|
109
|
+
process.kill()
|
|
110
|
+
process.wait()
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _read_log_tail(log_path, max_chars=2000):
|
|
114
|
+
if not os.path.exists(log_path):
|
|
115
|
+
return ""
|
|
116
|
+
with open(log_path, "r", encoding="utf-8", errors="replace") as fin:
|
|
117
|
+
content = fin.read()
|
|
118
|
+
if len(content) <= max_chars:
|
|
119
|
+
return content
|
|
120
|
+
return content[-max_chars:]
|