mljar-supervised 1.4.0rc2__py3-none-any.whl

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.
Files changed (117) hide show
  1. mljar_supervised-1.4.0rc2.dist-info/METADATA +759 -0
  2. mljar_supervised-1.4.0rc2.dist-info/RECORD +117 -0
  3. mljar_supervised-1.4.0rc2.dist-info/WHEEL +5 -0
  4. mljar_supervised-1.4.0rc2.dist-info/licenses/LICENSE +21 -0
  5. mljar_supervised-1.4.0rc2.dist-info/licenses/LICENSE-pytabkit.txt +201 -0
  6. mljar_supervised-1.4.0rc2.dist-info/top_level.txt +1 -0
  7. supervised/__init__.py +14 -0
  8. supervised/algorithms/__init__.py +0 -0
  9. supervised/algorithms/_pytabkit_compat.py +128 -0
  10. supervised/algorithms/_realmlp_backend.py +84 -0
  11. supervised/algorithms/_sdm_backend.py +75 -0
  12. supervised/algorithms/_tabm_backend.py +221 -0
  13. supervised/algorithms/algorithm.py +169 -0
  14. supervised/algorithms/baseline.py +90 -0
  15. supervised/algorithms/catboost.py +451 -0
  16. supervised/algorithms/decision_tree.py +310 -0
  17. supervised/algorithms/extra_trees.py +178 -0
  18. supervised/algorithms/factory.py +28 -0
  19. supervised/algorithms/knn.py +277 -0
  20. supervised/algorithms/lightgbm.py +418 -0
  21. supervised/algorithms/linear.py +213 -0
  22. supervised/algorithms/nn.py +201 -0
  23. supervised/algorithms/random_forest.py +183 -0
  24. supervised/algorithms/realmlp.py +586 -0
  25. supervised/algorithms/realmlp_resources.py +153 -0
  26. supervised/algorithms/registry.py +85 -0
  27. supervised/algorithms/sdm.py +577 -0
  28. supervised/algorithms/sklearn.py +197 -0
  29. supervised/algorithms/tabm.py +345 -0
  30. supervised/algorithms/tabm_resources.py +94 -0
  31. supervised/algorithms/xgboost.py +420 -0
  32. supervised/apps/__init__.py +5 -0
  33. supervised/apps/generator.py +231 -0
  34. supervised/apps/local_runner.py +120 -0
  35. supervised/apps/metadata.py +380 -0
  36. supervised/apps/publisher.py +497 -0
  37. supervised/apps/templates.py +633 -0
  38. supervised/automl.py +680 -0
  39. supervised/base_automl.py +2758 -0
  40. supervised/callbacks/__init__.py +0 -0
  41. supervised/callbacks/callback.py +25 -0
  42. supervised/callbacks/callback_list.py +33 -0
  43. supervised/callbacks/early_stopping.py +224 -0
  44. supervised/callbacks/learner_time_constraint.py +47 -0
  45. supervised/callbacks/max_iters_constraint.py +16 -0
  46. supervised/callbacks/metric_logger.py +48 -0
  47. supervised/callbacks/terminate_on_nan.py +28 -0
  48. supervised/callbacks/total_time_constraint.py +79 -0
  49. supervised/ensemble.py +588 -0
  50. supervised/exceptions.py +20 -0
  51. supervised/fairness/__init__.py +0 -0
  52. supervised/fairness/certificate.py +129 -0
  53. supervised/fairness/metrics.py +654 -0
  54. supervised/fairness/optimization.py +414 -0
  55. supervised/fairness/plots.py +131 -0
  56. supervised/fairness/report.py +169 -0
  57. supervised/fairness/utils.py +40 -0
  58. supervised/model_framework.py +779 -0
  59. supervised/preprocessing/__init__.py +0 -0
  60. supervised/preprocessing/datetime_transformer.py +106 -0
  61. supervised/preprocessing/encoding_selector.py +31 -0
  62. supervised/preprocessing/exclude_missing_target.py +46 -0
  63. supervised/preprocessing/goldenfeatures_transformer.py +310 -0
  64. supervised/preprocessing/ip_transformer.py +94 -0
  65. supervised/preprocessing/kmeans_transformer.py +119 -0
  66. supervised/preprocessing/label_binarizer.py +81 -0
  67. supervised/preprocessing/label_encoder.py +116 -0
  68. supervised/preprocessing/preprocessing.py +705 -0
  69. supervised/preprocessing/preprocessing_categorical.py +115 -0
  70. supervised/preprocessing/preprocessing_missing.py +105 -0
  71. supervised/preprocessing/preprocessing_utils.py +201 -0
  72. supervised/preprocessing/scale.py +92 -0
  73. supervised/preprocessing/text_transformer.py +73 -0
  74. supervised/tuner/__init__.py +0 -0
  75. supervised/tuner/custom_parameters.py +62 -0
  76. supervised/tuner/data_info.py +83 -0
  77. supervised/tuner/hill_climbing.py +80 -0
  78. supervised/tuner/mljar_tuner.py +1566 -0
  79. supervised/tuner/optuna/__init__.py +0 -0
  80. supervised/tuner/optuna/catboost.py +148 -0
  81. supervised/tuner/optuna/extra_trees.py +80 -0
  82. supervised/tuner/optuna/knn.py +64 -0
  83. supervised/tuner/optuna/lightgbm.py +170 -0
  84. supervised/tuner/optuna/nn.py +68 -0
  85. supervised/tuner/optuna/random_forest.py +77 -0
  86. supervised/tuner/optuna/tuner.py +338 -0
  87. supervised/tuner/optuna/xgboost.py +136 -0
  88. supervised/tuner/preprocessing_tuner.py +147 -0
  89. supervised/tuner/random_parameters.py +22 -0
  90. supervised/tuner/time_controller.py +273 -0
  91. supervised/utils/__init__.py +11 -0
  92. supervised/utils/additional_metrics.py +992 -0
  93. supervised/utils/additional_plots.py +228 -0
  94. supervised/utils/artifact_paths.py +14 -0
  95. supervised/utils/automl_plots.py +329 -0
  96. supervised/utils/blueprint.py +494 -0
  97. supervised/utils/column_scan.py +58 -0
  98. supervised/utils/common.py +39 -0
  99. supervised/utils/config.py +25 -0
  100. supervised/utils/constants.py +4 -0
  101. supervised/utils/data_validation.py +48 -0
  102. supervised/utils/feature_importance.py +266 -0
  103. supervised/utils/importance.py +150 -0
  104. supervised/utils/jsonencoder.py +33 -0
  105. supervised/utils/leaderboard_plots.py +153 -0
  106. supervised/utils/learning_curves.py +145 -0
  107. supervised/utils/metric.py +470 -0
  108. supervised/utils/report_structured.py +718 -0
  109. supervised/utils/shap.py +383 -0
  110. supervised/utils/subsample.py +17 -0
  111. supervised/utils/utils.py +94 -0
  112. supervised/validation/__init__.py +0 -0
  113. supervised/validation/validation_step.py +38 -0
  114. supervised/validation/validator_base.py +36 -0
  115. supervised/validation/validator_custom.py +88 -0
  116. supervised/validation/validator_kfold.py +135 -0
  117. supervised/validation/validator_split.py +111 -0
@@ -0,0 +1,759 @@
1
+ Metadata-Version: 2.4
2
+ Name: mljar-supervised
3
+ Version: 1.4.0rc2
4
+ Summary: Automated Machine Learning for Humans
5
+ Home-page: https://github.com/mljar/mljar-supervised
6
+ Author: MLJAR, Sp. z o.o.
7
+ Author-email: contact@mljar.com
8
+ License: MIT
9
+ Keywords: automated machine learning,automl,machine learning,data science,data mining,mljar,random forest,decision tree,xgboost,lightgbm,catboost,neural network,extra trees,linear model,features selection,features engineering
10
+ Classifier: Programming Language :: Python
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ License-File: LICENSE-pytabkit.txt
19
+ Requires-Dist: numpy<3.0.0,>=2.0.0
20
+ Requires-Dist: pandas>=2.2.2
21
+ Requires-Dist: scipy>=1.13.1
22
+ Requires-Dist: scikit-learn>=1.5.0
23
+ Requires-Dist: xgboost>=2.1.0
24
+ Requires-Dist: lightgbm>=4.3.0
25
+ Requires-Dist: catboost>=1.2.8
26
+ Requires-Dist: joblib>=1.0.1
27
+ Requires-Dist: tabulate>=0.8.7
28
+ Requires-Dist: matplotlib>=3.8.4
29
+ Requires-Dist: dtreeviz>=2.2.2
30
+ Requires-Dist: shap>=0.46.0
31
+ Requires-Dist: seaborn>=0.13.2
32
+ Requires-Dist: optuna-integration>=3.6.0
33
+ Requires-Dist: mljar-scikit-plot>=0.3.11
34
+ Requires-Dist: markdown
35
+ Requires-Dist: typing-extensions
36
+ Requires-Dist: ipython
37
+ Requires-Dist: threadpoolctl>=3.1.0
38
+ Provides-Extra: kumo
39
+ Requires-Dist: torch<3,>=2.7; extra == "kumo"
40
+ Requires-Dist: huggingface_hub<3,>=1; extra == "kumo"
41
+ Requires-Dist: psutil>=5.0; extra == "kumo"
42
+ Provides-Extra: tabiclv2
43
+ Requires-Dist: torch<3,>=2.7; extra == "tabiclv2"
44
+ Requires-Dist: huggingface_hub<3,>=1; extra == "tabiclv2"
45
+ Requires-Dist: psutil>=5.0; extra == "tabiclv2"
46
+ Provides-Extra: tfm
47
+ Requires-Dist: torch<3,>=2.7; extra == "tfm"
48
+ Requires-Dist: huggingface_hub<3,>=1; extra == "tfm"
49
+ Requires-Dist: psutil>=5.0; extra == "tfm"
50
+ Provides-Extra: realmlp
51
+ Requires-Dist: pytabkit<1.8,>=1.7.2; extra == "realmlp"
52
+ Requires-Dist: torch<3,>=2.7; extra == "realmlp"
53
+ Requires-Dist: psutil>=5.0; extra == "realmlp"
54
+ Provides-Extra: tabm
55
+ Requires-Dist: pytabkit<1.8,>=1.7.2; extra == "tabm"
56
+ Requires-Dist: torch<3,>=2.7; extra == "tabm"
57
+ Requires-Dist: psutil>=5.0; extra == "tabm"
58
+ Provides-Extra: all
59
+ Requires-Dist: pytabkit<1.8,>=1.7.2; extra == "all"
60
+ Requires-Dist: torch<3,>=2.7; extra == "all"
61
+ Requires-Dist: psutil>=5.0; extra == "all"
62
+ Requires-Dist: huggingface_hub<3,>=1; extra == "all"
63
+ Dynamic: author
64
+ Dynamic: author-email
65
+ Dynamic: classifier
66
+ Dynamic: description
67
+ Dynamic: description-content-type
68
+ Dynamic: home-page
69
+ Dynamic: keywords
70
+ Dynamic: license
71
+ Dynamic: license-file
72
+ Dynamic: provides-extra
73
+ Dynamic: requires-dist
74
+ Dynamic: requires-python
75
+ Dynamic: summary
76
+
77
+
78
+
79
+ # MLJAR Automated Machine Learning for Humans
80
+
81
+ [![Tests status](https://github.com/mljar/mljar-supervised/actions/workflows/run-tests.yml/badge.svg)](https://github.com/mljar/mljar-supervised/actions/workflows/run-tests.yml)
82
+ [![PyPI version](https://badge.fury.io/py/mljar-supervised.svg)](https://badge.fury.io/py/mljar-supervised)
83
+ [![Anaconda-Server Badge](https://anaconda.org/conda-forge/mljar-supervised/badges/version.svg)](https://anaconda.org/conda-forge/mljar-supervised)
84
+ [![Anaconda-Server Badge](https://anaconda.org/conda-forge/mljar-supervised/badges/license.svg)](https://anaconda.org/conda-forge/mljar-supervised)
85
+ [![Downloads](https://pepy.tech/badge/mljar-supervised)](https://pepy.tech/project/mljar-supervised)
86
+
87
+ <p align="center">
88
+ <img
89
+ alt="mljar AutoML"
90
+ src="https://raw.githubusercontent.com/mljar/mljar-examples/master/media/AutoML_white.png#gh-light-mode-only" width="50%" />
91
+ </p>
92
+ <p align="center">
93
+ <img
94
+ alt="mljar AutoML"
95
+ src="https://raw.githubusercontent.com/mljar/mljar-examples/master/media/AutoML_black.png#gh-dark-mode-only" width="50%" />
96
+ </p>
97
+
98
+ ---
99
+
100
+ **Documentation**: <a href="https://supervised.mljar.com/" target="_blank">https://supervised.mljar.com/</a>
101
+
102
+ **Source Code**: <a href="https://github.com/mljar/mljar-supervised" target="_blank">https://github.com/mljar/mljar-supervised</a>
103
+
104
+ **Use MLJAR Studio (Easiest Way to Run MLJAR AutoML)**
105
+ MLJAR Studio is the easiest way to run MLJAR AutoML, with conversational notebooks and AutoLab experiments (autonomous AI for ML pipeline optimization).
106
+ Start quickly, iterate faster, and manage experiments in one place.
107
+ [Try MLJAR Studio](https://mljar.com)
108
+
109
+
110
+ <p align="center">
111
+ <img src="https://raw.githubusercontent.com/mljar/mljar-examples/master/media/pipeline_AutoML.png" width="100%" />
112
+ </p>
113
+
114
+ ---
115
+
116
+ **Kumo and TabICLv2:** separate Compete algorithms with optional `[tfm]` dependencies
117
+ and a pinned SDM backend. Python 3.11+ required. See [installation and usage](docs/docs/features/sdm.md).
118
+
119
+ ## Table of Contents
120
+
121
+ Install standard MLJAR with `python -m pip install mljar-supervised`.
122
+ For RealMLP, choose [CPU](docs/docs/install.md#realmlp-on-cpu) or
123
+ [NVIDIA GPU](docs/docs/install.md#realmlp-on-nvidia-gpu) setup, then install the
124
+ `[realmlp]` or `[all]` extra. **RealMLP currently requires installation from source**
125
+ and is available only in `mode="Compete"`.
126
+ See the [installation guide](docs/docs/install.md) for copyable commands and
127
+ checks, and the [RealMLP guide](docs/docs/features/realmlp.md) for usage.
128
+ [TabM mini](docs/docs/features/tabm.md) is also available in Compete mode through
129
+ `[tabm]` or `[all]`, using the same pytabkit/PyTorch dependencies and CPU/GPU setup.
130
+
131
+ - [Automated Machine Learning](https://github.com/mljar/mljar-supervised#automated-machine-learning)
132
+ - [Generate Web Apps for Trained Models](https://github.com/mljar/mljar-supervised#generate-web-apps-for-trained-models)
133
+ - [What's good in it?](https://github.com/mljar/mljar-supervised#whats-good-in-it)
134
+ - [Automatic Documentation](https://github.com/mljar/mljar-supervised#automatic-documentation)
135
+ - [Available Modes](https://github.com/mljar/mljar-supervised#available-modes)
136
+ - [Fairness Aware Training](https://github.com/mljar/mljar-supervised#fairness-aware-training)
137
+ - [Examples](https://github.com/mljar/mljar-supervised#examples)
138
+ - [FAQ](https://github.com/mljar/mljar-supervised#faq)
139
+ - [Documentation](https://github.com/mljar/mljar-supervised#documentation)
140
+ - [Installation](https://github.com/mljar/mljar-supervised#installation)
141
+ - [Demo](https://github.com/mljar/mljar-supervised#demo)
142
+ - [Contributing](https://github.com/mljar/mljar-supervised#contributing)
143
+ - [Cite](https://github.com/mljar/mljar-supervised#cite)
144
+ - [License](https://github.com/mljar/mljar-supervised#license)
145
+ - [Commercial support](https://github.com/mljar/mljar-supervised#commercial-support)
146
+ - [MLJAR](https://github.com/mljar/mljar-supervised#mljar)
147
+
148
+
149
+
150
+
151
+
152
+ # Automated Machine Learning
153
+
154
+ 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).
155
+
156
+ The `mljar-supervised` will help you with:
157
+ - explaining and understanding your data through model reports, feature importance, and SHAP explanations,
158
+ - trying many different machine learning models (Algorithm Selection and Hyper-Parameters tuning),
159
+ - creating Markdown reports from analysis with details about all models (Automatic-Documentation),
160
+ - generating a web app for a trained model, so predictions can be used by domain experts,
161
+ - saving, re-running, and loading the analysis and ML models.
162
+
163
+ It has four built-in modes of work:
164
+ - `Explain` mode, which is ideal for explaining and understanding the data, with many data explanations, like decision trees visualization, linear models coefficients display, permutation importance, and SHAP explanations of data,
165
+ - `Perform` for building ML pipelines to use in production,
166
+ - `Compete` mode that trains highly-tuned ML models with ensembling and stacking, with the purpose to use in ML competitions.
167
+ - `Optuna` mode can be used to search for highly-tuned ML models should be used when the performance is the most important, and computation time is not limited (it is available from version `0.10.0`)
168
+
169
+ Of course, you can further customize the details of each `mode` to meet the requirements.
170
+
171
+ ## Generate Web Apps for Trained Models
172
+
173
+ MLJAR AutoML does not stop after training a model. It can automatically generate a web app for your trained model with [Mercury](https://github.com/mljar/mercury). This is useful when you want to share predictions with domain experts, business users, researchers, or other people who do not want to work directly with Python code.
174
+
175
+ After training AutoML, generate the app files with:
176
+
177
+ ```python
178
+ from supervised import AutoML
179
+ # AutoML training
180
+ automl = AutoML(results_path="AutoML")
181
+ automl.fit(X, y)
182
+
183
+ # Generate a Mercury web app for the trained model
184
+ automl.app()
185
+ ```
186
+
187
+ You can also start the app locally:
188
+
189
+ ```python
190
+ automl.local_app()
191
+ ```
192
+
193
+ or publish it quickly:
194
+
195
+ ```python
196
+ automl.publish_app()
197
+ ```
198
+
199
+ `publish_app()` creates an app URL on the first publish and then reuses the last successfully published URL by default.
200
+
201
+ The generated app can include:
202
+ - single prediction dashboard,
203
+ - batch prediction from CSV files,
204
+ - downloadable predictions,
205
+ - feature importance plots,
206
+ - feature context plots for single predictions.
207
+
208
+ With this feature, you can go from: CSV data -> trained ML model -> ready-to-use prediction web app.
209
+
210
+ Please check the [Apps documentation](https://supervised.mljar.com/features/apps/) for details.
211
+
212
+ ## What's good in it?
213
+
214
+ - It uses many algorithms: `Baseline`, `Linear`, `Random Forest`, `Extra Trees`, `LightGBM`, `Xgboost`, `CatBoost`, `Neural Networks`, and `Nearest Neighbors`.
215
+ - It can compute Ensemble based on a greedy algorithm from [Caruana paper](http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf).
216
+ - It can stack models to build a level 2 ensemble (available in `Compete` mode or after setting the `stack_models` parameter).
217
+ - It can do features preprocessing, like missing values imputation and converting categoricals. What is more, it can also handle target values preprocessing.
218
+ - It can do advanced features engineering, like [Golden Features](https://supervised.mljar.com/features/golden_features/), [Features Selection](https://supervised.mljar.com/features/features_selection/), Text and Time Transformations.
219
+ - It can tune hyper-parameters with a `not-so-random-search` algorithm (random-search over a defined set of values) and hill climbing to fine-tune final models.
220
+ - It can compute the `Baseline` for your data so that you will know if you need Machine Learning or not!
221
+ - It has extensive explanations. This package is training simple `Decision Trees` with `max_depth <= 5`, so you can easily visualize them with amazing [dtreeviz](https://github.com/parrt/dtreeviz) to better understand your data.
222
+ - The `mljar-supervised` uses simple linear regression and includes its coefficients in the summary report, so you can check which features are used the most in the linear model.
223
+ - It cares about the explainability of models: for every algorithm, the feature importance is computed based on permutation. Additionally, for every algorithm, the SHAP explanations are computed: feature importance, dependence plots, and decision plots (explanations can be switched off with the `explain_level` parameter).
224
+ - There is automatic documentation for every ML experiment run with AutoML. The `mljar-supervised` creates markdown reports from AutoML training full of ML details, metrics, and charts.
225
+ - It can generate Mercury web apps from trained AutoML models, so the model can be shared as an interactive prediction app.
226
+
227
+ <p align="center">
228
+ <img src="https://raw.githubusercontent.com/mljar/visual-identity/main/media/infograph.png" width="100%" />
229
+ </p>
230
+
231
+ # Automatic Documentation
232
+
233
+ ## The AutoML Report
234
+
235
+ The report from running AutoML will contain the table with information about each model score and the time needed to train the model. There is a link for each model, which you can click to see the model's details. The performance of all ML models is presented as scatter and box plots so you can visually inspect which algorithms perform the best :trophy:.
236
+
237
+ ![AutoML leaderboard](https://github.com/mljar/mljar-examples/blob/master/media/automl_summary.gif)
238
+
239
+ ## The `Decision Tree` Report
240
+
241
+ The example for `Decision Tree` summary with trees visualization. For classification tasks, additional metrics are provided:
242
+ - confusion matrix
243
+ - threshold (optimized in the case of binary classification task)
244
+ - F1 score
245
+ - Accuracy
246
+ - Precision, Recall, MCC
247
+
248
+ ![Decision Tree summary](https://github.com/mljar/mljar-examples/blob/master/media/decision_tree_summary.gif)
249
+
250
+ ## The `LightGBM` Report
251
+
252
+ The example for `LightGBM` summary:
253
+
254
+ ![Decision Tree summary](https://github.com/mljar/mljar-examples/blob/master/media/lightgbm_summary.gif)
255
+
256
+
257
+ ## Available Modes
258
+
259
+ In the [docs](https://supervised.mljar.com/features/modes/) you can find details about AutoML modes that are presented in the table.
260
+
261
+ <p align="center">
262
+ <img src="https://raw.githubusercontent.com/mljar/visual-identity/main/media/mljar_modes.png" width="100%" />
263
+ </p>
264
+
265
+ ### Explain
266
+
267
+ ```py
268
+ automl = AutoML(mode="Explain")
269
+ ```
270
+
271
+ It is aimed to be used when the user wants to explain and understand the data.
272
+ - It is using 75%/25% train/test split.
273
+ - It uses: `Baseline`, `Linear`, `Decision Tree`, `Random Forest`, `Xgboost`, `Neural Network' algorithms, and ensemble.
274
+ - It has full explanations: learning curves, importance plots, and SHAP plots.
275
+
276
+ ### Perform
277
+
278
+ ```py
279
+ automl = AutoML(mode="Perform")
280
+ ```
281
+
282
+ It should be used when the user wants to train a model that will be used in real-life use cases.
283
+ - It uses a 5-fold CV.
284
+ - It uses: `Linear`, `Random Forest`, `LightGBM`, `Xgboost`, `CatBoost`, and `Neural Network`. It uses ensembling.
285
+ - It has learning curves and importance plots in reports.
286
+
287
+ ### Compete
288
+
289
+ ```py
290
+ automl = AutoML(mode="Compete")
291
+ ```
292
+
293
+ It should be used for machine learning competitions.
294
+ Kumo (small/medium/large) and TabICLv2 are also available with the
295
+ [optional SDM installation](docs/docs/install.md#kumo-and-tabiclv2-on-cpu-or-nvidia-gpu).
296
+ They are selected automatically when the backend and CUDA are available; select
297
+ them explicitly for CPU use.
298
+ - It adapts the validation strategy depending on dataset size and `total_time_limit`. It can be: a train/test split (80/20), 5-fold CV or 10-fold CV.
299
+ - It is using: `Linear`, `Decision Tree`, `Random Forest`, `Extra Trees`, `LightGBM`, `Xgboost`, `CatBoost`, `Neural Network`, and `Nearest Neighbors`. It uses ensemble and **stacking**.
300
+ - It has only learning curves in the reports.
301
+
302
+ ### Optuna
303
+
304
+ ```py
305
+ automl = AutoML(mode="Optuna", optuna_time_budget=3600)
306
+ ```
307
+
308
+ It should be used when the performance is the most important and time is not limited.
309
+ - It uses a 10-fold CV
310
+ - It uses: `Random Forest`, `Extra Trees`, `LightGBM`, `Xgboost`, and `CatBoost`. Those algorithms are tuned by `Optuna` framework for `optuna_time_budget` seconds, each. Algorithms are tuned with original data, without advanced feature engineering.
311
+ - It uses advanced feature engineering, stacking and ensembling. The hyperparameters found for original data are reused with those steps.
312
+ - It produces learning curves in the reports.
313
+
314
+
315
+
316
+ ## How to save and load AutoML?
317
+
318
+ All models in the AutoML are saved and loaded automatically. No need to call `save()` or `load()`.
319
+
320
+ ### Example:
321
+
322
+ #### Train AutoML
323
+
324
+ ```python
325
+ automl = AutoML(results_path="AutoML_classifier")
326
+ automl.fit(X, y)
327
+ ```
328
+
329
+ You will have all models saved in the `AutoML_classifier` directory. Each model will have a separate directory with the `README.md` file with all details from the training.
330
+
331
+ #### Compute predictions
332
+ ```python
333
+ automl = AutoML(results_path="AutoML_classifier")
334
+ automl.predict(X)
335
+ ```
336
+
337
+ The AutoML automatically loads models from the `results_path` directory. If you will call `fit()` on already trained AutoML then you will get a warning message that AutoML is already fitted.
338
+
339
+
340
+ ### Why do you automatically save all models?
341
+
342
+ All models are automatically saved to be able to restore the training after interruption. For example, you are training AutoML for 48 hours, and after 47 hours, there is some unexpected interruption. In MLJAR AutoML you just call the same training code after the interruption and AutoML reloads already trained models and finishes the training.
343
+
344
+ ## Supported evaluation metrics (`eval_metric` argument in `AutoML()`)
345
+
346
+ - for binary classification: `logloss`, `auc`, `f1`, `average_precision`, `accuracy`- default is `logloss`
347
+ - for multiclass classification: `logloss`, `f1`, `accuracy` - default is `logloss`
348
+ - for regression: `rmse`, `mse`, `mae`, `r2`, `mape`, `spearman`, `pearson` - default is `rmse`
349
+
350
+ You can also pass a custom Python function directly as `eval_metric`. See the docs for [Custom eval metric](https://supervised.mljar.com/features/custom-eval-metric/).
351
+
352
+ If you don't find the `eval_metric` that you need, please add a new issue. We will add it.
353
+
354
+
355
+ ## Fairness Aware Training
356
+
357
+ Starting from version `1.0.0` AutoML can optimize the Machine Learning pipeline with sensitive features. There are the following fairness related arguments in the AutoML constructor:
358
+ - `fairness_metric` - metric which will be used to decide if the model is fair,
359
+ - `fairness_threshold` - threshold used in decision about model fairness,
360
+ - `privileged_groups` - privileged groups used in fairness metrics computation,
361
+ - `underprivileged_groups` - underprivileged groups used in fairness metrics computation.
362
+
363
+ The `fit()` method accepts `sensitive_features`. When sensitive features are passed to AutoML, the best model will be selected among fair models only. In the AutoML reports, additional information about fairness metrics will be added. The MLJAR AutoML supports two methods for bias mitigation:
364
+ - Sample Weighting - assigns weights to samples to treat samples equally,
365
+ - Smart Grid Search - similar to Sample Weighting, where different weights are checked to optimize fairness metric.
366
+
367
+ The fair ML building can be used with all algorithms, including `Ensemble` and `Stacked Ensemble`. We support three Machine Learning tasks:
368
+ - binary classification,
369
+ - mutliclass classification,
370
+ - regression.
371
+
372
+ Example code:
373
+
374
+
375
+ ```python
376
+ from sklearn.model_selection import train_test_split
377
+ from sklearn.datasets import fetch_openml
378
+ from supervised.automl import AutoML
379
+
380
+ data = fetch_openml(data_id=1590, as_frame=True)
381
+ X = data.data
382
+ y = (data.target == ">50K") * 1
383
+ sensitive_features = X[["sex"]]
384
+
385
+ X_train, X_test, y_train, y_test, S_train, S_test = train_test_split(
386
+ X, y, sensitive_features, stratify=y, test_size=0.75, random_state=42
387
+ )
388
+
389
+ automl = AutoML(
390
+ algorithms=[
391
+ "Xgboost"
392
+ ],
393
+ train_ensemble=False,
394
+ fairness_metric="demographic_parity_ratio",
395
+ fairness_threshold=0.8,
396
+ privileged_groups = [{"sex": "Male"}],
397
+ underprivileged_groups = [{"sex": "Female"}],
398
+ )
399
+
400
+ automl.fit(X_train, y_train, sensitive_features=S_train)
401
+ ```
402
+
403
+ You can read more about fairness aware AutoML training in our article https://mljar.com/blog/fairness-machine-learning/
404
+
405
+ ![Fairness aware AutoML](https://raw.githubusercontent.com/mljar/visual-identity/main/automl/fairness-automl.gif)
406
+
407
+
408
+
409
+ # Examples
410
+
411
+ ## :point_right: Binary Classification Example
412
+
413
+ There is a simple interface available with `fit` and `predict` methods.
414
+
415
+ ```python
416
+ import pandas as pd
417
+ from sklearn.model_selection import train_test_split
418
+ from supervised.automl import AutoML
419
+
420
+ df = pd.read_csv(
421
+ "https://raw.githubusercontent.com/pplonski/datasets-for-start/master/adult/data.csv",
422
+ skipinitialspace=True,
423
+ )
424
+ X_train, X_test, y_train, y_test = train_test_split(
425
+ df[df.columns[:-1]], df["income"], test_size=0.25
426
+ )
427
+
428
+ automl = AutoML()
429
+ automl.fit(X_train, y_train)
430
+
431
+ predictions = automl.predict(X_test)
432
+ ```
433
+
434
+ AutoML `fit` will print:
435
+ ```py
436
+ Create directory AutoML_1
437
+ AutoML task to be solved: binary_classification
438
+ AutoML will use algorithms: ['Baseline', 'Linear', 'Decision Tree', 'Random Forest', 'Xgboost', 'Neural Network']
439
+ AutoML will optimize for metric: logloss
440
+ 1_Baseline final logloss 0.5519845471086654 time 0.08 seconds
441
+ 2_DecisionTree final logloss 0.3655910192804364 time 10.28 seconds
442
+ 3_Linear final logloss 0.38139916864708445 time 3.19 seconds
443
+ 4_Default_RandomForest final logloss 0.2975204390214936 time 79.19 seconds
444
+ 5_Default_Xgboost final logloss 0.2731086827200411 time 5.17 seconds
445
+ 6_Default_NeuralNetwork final logloss 0.319812276905242 time 21.19 seconds
446
+ Ensemble final logloss 0.2731086821194617 time 1.43 seconds
447
+ ```
448
+
449
+ - the AutoML results in [Markdown report](https://github.com/mljar/mljar-examples/tree/master/Income_classification/AutoML_1#automl-leaderboard)
450
+ - the Xgboost [Markdown report](https://github.com/mljar/mljar-examples/blob/master/Income_classification/AutoML_1/5_Default_Xgboost/README.md), please take a look at amazing dependence plots produced by SHAP package :sparkling_heart:
451
+ - the Decision Tree [Markdown report](https://github.com/mljar/mljar-examples/blob/master/Income_classification/AutoML_1/2_DecisionTree/README.md), please take a look at beautiful tree visualization :sparkles:
452
+ - the Logistic Regression [Markdown report](https://github.com/mljar/mljar-examples/blob/master/Income_classification/AutoML_1/3_Linear/README.md), please take a look at coefficients table, and you can compare the SHAP plots between (Xgboost, Decision Tree and Logistic Regression) :coffee:
453
+
454
+
455
+ ## :point_right: Multi-Class Classification Example
456
+
457
+ The example code for classification of the optical recognition of handwritten digits dataset. Running this code in less than 30 minutes will result in test accuracy ~98%.
458
+
459
+ ```python
460
+ import pandas as pd
461
+ # scikit learn utilites
462
+ from sklearn.datasets import load_digits
463
+ from sklearn.metrics import accuracy_score
464
+ from sklearn.model_selection import train_test_split
465
+ # mljar-supervised package
466
+ from supervised.automl import AutoML
467
+
468
+ # load the data
469
+ digits = load_digits()
470
+ X_train, X_test, y_train, y_test = train_test_split(
471
+ pd.DataFrame(digits.data), digits.target, stratify=digits.target, test_size=0.25,
472
+ random_state=123
473
+ )
474
+
475
+ # train models with AutoML
476
+ automl = AutoML(mode="Perform")
477
+ automl.fit(X_train, y_train)
478
+
479
+ # compute the accuracy on test data
480
+ predictions = automl.predict_all(X_test)
481
+ print(predictions.head())
482
+ print("Test accuracy:", accuracy_score(y_test, predictions["label"].astype(int)))
483
+ ```
484
+
485
+ ## :point_right: Regression Example
486
+
487
+ Regression example on `California Housing` house prices data.
488
+
489
+ ```python
490
+ import numpy as np
491
+ import pandas as pd
492
+ from sklearn.datasets import fetch_california_housing
493
+ from sklearn.model_selection import train_test_split
494
+ from sklearn.metrics import mean_squared_error
495
+ from supervised.automl import AutoML # mljar-supervised
496
+
497
+ # Load the data
498
+ housing = fetch_california_housing()
499
+ X_train, X_test, y_train, y_test = train_test_split(
500
+ pd.DataFrame(housing.data, columns=housing.feature_names),
501
+ housing.target,
502
+ test_size=0.25,
503
+ random_state=123,
504
+ )
505
+
506
+ # train models with AutoML
507
+ automl = AutoML(mode="Explain")
508
+ automl.fit(X_train, y_train)
509
+
510
+ # compute the MSE on test data
511
+ predictions = automl.predict(X_test)
512
+ print("Test MSE:", mean_squared_error(y_test, predictions))
513
+ ```
514
+
515
+ ## :point_right: More Examples
516
+
517
+ - [**IP address classification**](examples/scripts/binary_classifier_ip_addresses.py) - train on raw IPv4/IPv6 strings and verify predictions after reload; see the [tutorial](docs/docs/tutorials/ip-addresses.md).
518
+
519
+ - [**Income classification**](https://github.com/mljar/mljar-examples/tree/master/Income_classification) - it is a binary classification task on census data
520
+ - [**Iris classification**](https://github.com/mljar/mljar-examples/tree/master/Iris_classification) - it is a multiclass classification on Iris flowers data
521
+ - [**House price regression**](https://github.com/mljar/mljar-examples/tree/master/House_price_regression) - it is a regression task on Boston houses data
522
+
523
+ # FAQ
524
+
525
+ <details><summary>What method is used for hyperparameters optimization?</summary>
526
+ - For modes: `Explain`, `Perform`, and `Compete` there is used a random search method combined with hill climbing. In this approach, all checked models are saved and used for building Ensemble.
527
+ - For mode: `Optuna` the Optuna framework is used. It uses using TPE sampler for tuning. Models checked during the Optuna hyperparameters search are not saved, only the best model is saved (the final model from tuning). You can check the details about checked hyperparameters from optuna by checking study files in the `optuna` directory in your AutoML `results_path`.
528
+ </details>
529
+
530
+ <details><summary>How to save and load AutoML?</summary>
531
+
532
+ The save and load of AutoML models is automatic. All models created during AutoML training are saved in the directory set in `results_path` (argument of `AutoML()` constructor). If there is no `results_path` set, then the directory is created based on following name convention: `AutoML_{number}` the `number` will be number from 1 to 1000 (depends which directory name will be free).
533
+
534
+ Example save and load:
535
+
536
+ ```python
537
+ automl = AutoML(results_path='AutoML_1')
538
+ automl.fit(X, y)
539
+ ```
540
+
541
+ The all models from AutoML are saved in `AutoML_1` directory.
542
+
543
+ To load models:
544
+
545
+ ```python
546
+ automl = AutoML(results_path='AutoML_1')
547
+ automl.predict(X)
548
+ ```
549
+
550
+ </details>
551
+
552
+ <details><summary>How to set ML task (select between classification or regression)?</summary>
553
+
554
+ The MLJAR AutoML can work with:
555
+ - binary classification
556
+ - multi-class classification
557
+ - regression
558
+
559
+ The ML task detection is automatic based on target values. There can be situation if you want to manually force AutoML to select the ML task, then you need to set `ml_task` parameter. It can be set to `'binary_classification'`, `'multiclass_classification'`, `'regression'`.
560
+
561
+ Example:
562
+ ```python
563
+ automl = AutoML(ml_task='regression')
564
+ automl.fit(X, y)
565
+ ```
566
+ In the above example the regression model will be fitted.
567
+
568
+ </details>
569
+
570
+ <details><summary>How to reuse Optuna hyperparameters?</summary>
571
+
572
+ You can reuse Optuna hyperparameters that were found in other AutoML training. You need to pass them in `optuna_init_params` argument. All hyperparameters found during Optuna tuning are saved in the `optuna/optuna.json` file (inside `results_path` directory).
573
+
574
+ Example:
575
+
576
+ ```python
577
+ optuna_init = json.loads(open('previous_AutoML_training/optuna/optuna.json').read())
578
+
579
+ automl = AutoML(
580
+ mode='Optuna',
581
+ optuna_init_params=optuna_init
582
+ )
583
+ automl.fit(X, y)
584
+ ```
585
+
586
+ When reusing Optuna hyperparameters the Optuna tuning is simply skipped. The model will be trained with hyperparameters set in `optuna_init_params`. Right now there is no option to continue Optuna tuning with seed parameters.
587
+
588
+
589
+ </details>
590
+
591
+
592
+ <details><summary>How to know the order of classes for binary or multiclass problem when using predict_proba?</summary>
593
+
594
+ To get predicted probabilites with information about class label please use the `predict_all()` method. It returns the pandas DataFrame with class names in the columns. The order of predicted columns is the same in the `predict_proba()` and `predict_all()` methods. The `predict_all()` method will additionaly have the column with the predicted class label.
595
+
596
+ </details>
597
+
598
+ # Documentation
599
+
600
+ For details please check [mljar-supervised docs](https://supervised.mljar.com).
601
+
602
+ ## Structured Report for LLMs
603
+
604
+ The AutoML object can generate a structured report that is easier to analyze with LLMs and external tools:
605
+
606
+ ```python
607
+ from supervised import AutoML
608
+
609
+ automl = AutoML(results_path="AutoML_example")
610
+ automl.fit(X, y)
611
+
612
+ # Default output is markdown text
613
+ markdown_report = automl.report_structured()
614
+ print(markdown_report)
615
+ ```
616
+
617
+ You can also get programmatic formats:
618
+
619
+ ```python
620
+ # Python dictionary
621
+ payload = automl.report_structured(format="dict")
622
+
623
+ # JSON string
624
+ payload_json = automl.report_structured(format="json")
625
+ ```
626
+
627
+ Each call creates/updates:
628
+
629
+ ```text
630
+ <results_path>/report_structured.json
631
+ ```
632
+
633
+ Use `model_name` to display detailed metrics for one selected model:
634
+
635
+ ```python
636
+ compact = automl.report_structured()
637
+ detailed = automl.report_structured(model_name="3_Linear")
638
+ ```
639
+
640
+ When `model_name` is provided, the markdown includes detailed metrics, fairness details (if used), and feature importance summaries for that model.
641
+
642
+ # Installation
643
+
644
+ For standard MLJAR, optional neural models, and Kumo/TabICLv2 CPU/GPU setup, see the
645
+ [installation guide](docs/docs/install.md). Version `1.4.0rc2` is a release
646
+ candidate that adds optional RealMLP, TabM mini, Kumo and TabICLv2 support.
647
+
648
+ Compatibility:
649
+ - Python `>=3.9`
650
+ - NumPy `>=2.0,<3`
651
+
652
+ From PyPi repository:
653
+
654
+ ```
655
+ pip install mljar-supervised
656
+ ```
657
+
658
+ To test the release candidate, select its exact version:
659
+
660
+ ```bash
661
+ python -m pip install "mljar-supervised==1.4.0rc2"
662
+ ```
663
+
664
+ See the [release notes](https://github.com/mljar/mljar-supervised/blob/master/release.md)
665
+ for changes and optional-model requirements.
666
+
667
+ To install this package with conda run:
668
+ ```
669
+ conda install -c conda-forge mljar-supervised
670
+ ```
671
+
672
+ From source code:
673
+
674
+ ```
675
+ git clone https://github.com/mljar/mljar-supervised.git
676
+ cd mljar-supervised
677
+ python setup.py install
678
+ ```
679
+
680
+ Installation for development
681
+ ```
682
+ git clone https://github.com/mljar/mljar-supervised.git
683
+ virtualenv venv --python=python3.9
684
+ source venv/bin/activate
685
+ pip install -r requirements.txt
686
+ pip install -r requirements_dev.txt
687
+ ```
688
+
689
+ Running in the docker:
690
+ ```
691
+ FROM python:3.9-slim-buster
692
+ RUN apt-get update && apt-get -y update
693
+ RUN apt-get install -y build-essential python3-pip python3-dev
694
+ RUN pip3 -q install pip --upgrade
695
+ RUN pip3 install mljar-supervised jupyter
696
+ CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]
697
+ ```
698
+
699
+ Install from GitHub with pip:
700
+ ```
701
+ pip install -q -U git+https://github.com/mljar/mljar-supervised.git@master
702
+ ```
703
+ # Demo
704
+
705
+ In the below demo GIF you will see:
706
+ - MLJAR AutoML trained in Jupyter Notebook on the Titanic dataset
707
+ - overview of created files
708
+ - a showcase of selected plots created during AutoML training
709
+ - algorithm comparison report along with their plots
710
+ - example of README file and CSV file with results
711
+
712
+ ![](https://github.com/mljar/mljar-examples/raw/master/media/mljar_files.gif)
713
+
714
+ # Contributing
715
+
716
+ To get started take a look at our [Contribution Guide](https://supervised.mljar.com/contributing/) for information about our process and where you can fit in!
717
+
718
+ ### Contributors
719
+ <a href="https://github.com/mljar/mljar-supervised/graphs/contributors">
720
+ <img src="https://contributors-img.web.app/image?repo=mljar/mljar-supervised" />
721
+ </a>
722
+
723
+ # Cite
724
+
725
+ Would you like to cite MLJAR? Great! :)
726
+
727
+ You can cite MLJAR as follows:
728
+
729
+ ```
730
+ @misc{mljar,
731
+ author = {Aleksandra P\l{}o\'{n}ska and Piotr P\l{}o\'{n}ski},
732
+ year = {2021},
733
+ publisher = {MLJAR},
734
+ address = {\L{}apy, Poland},
735
+ title = {MLJAR: State-of-the-art Automated Machine Learning Framework for Tabular Data. Version 0.10.3},
736
+ url = {https://github.com/mljar/mljar-supervised}
737
+ }
738
+ ```
739
+
740
+ Would love to hear from you about how have you used MLJAR AutoML in your project.
741
+ Please feel free to let us know at
742
+ ![image](https://user-images.githubusercontent.com/6959032/118103228-f5ea9a00-b3d9-11eb-87ed-8cfb1f873f91.png)
743
+
744
+
745
+ # License
746
+
747
+ The `mljar-supervised` is provided with [MIT license](https://github.com/mljar/mljar-supervised/blob/master/LICENSE).
748
+
749
+ # Commercial support
750
+
751
+ Looking for commercial support? Do you need new feature implementation? Please contact us by [email](https://mljar.com/contact/) for details.
752
+
753
+ # MLJAR
754
+ <p align="center">
755
+ <img src="https://github.com/mljar/mljar-examples/blob/master/media/large_logo.png" width="314" />
756
+ </p>
757
+
758
+ The `mljar-supervised` is an open-source project created by [MLJAR](https://mljar.com). We care about ease of use in Machine Learning.
759
+ The [mljar.com](https://mljar.com) provides a beautiful and simple user interface for building machine learning models.