mljar-supervised 1.2.1__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 (94) hide show
  1. mljar_supervised-1.2.1.dist-info/METADATA +657 -0
  2. mljar_supervised-1.2.1.dist-info/RECORD +94 -0
  3. mljar_supervised-1.2.1.dist-info/WHEEL +5 -0
  4. mljar_supervised-1.2.1.dist-info/licenses/LICENSE +21 -0
  5. mljar_supervised-1.2.1.dist-info/top_level.txt +1 -0
  6. supervised/__init__.py +14 -0
  7. supervised/algorithms/__init__.py +0 -0
  8. supervised/algorithms/algorithm.py +151 -0
  9. supervised/algorithms/baseline.py +90 -0
  10. supervised/algorithms/catboost.py +436 -0
  11. supervised/algorithms/decision_tree.py +305 -0
  12. supervised/algorithms/extra_trees.py +176 -0
  13. supervised/algorithms/factory.py +28 -0
  14. supervised/algorithms/knn.py +137 -0
  15. supervised/algorithms/lightgbm.py +406 -0
  16. supervised/algorithms/linear.py +211 -0
  17. supervised/algorithms/nn.py +180 -0
  18. supervised/algorithms/random_forest.py +181 -0
  19. supervised/algorithms/registry.py +76 -0
  20. supervised/algorithms/sklearn.py +197 -0
  21. supervised/algorithms/xgboost.py +413 -0
  22. supervised/automl.py +568 -0
  23. supervised/base_automl.py +2542 -0
  24. supervised/callbacks/__init__.py +0 -0
  25. supervised/callbacks/callback.py +25 -0
  26. supervised/callbacks/callback_list.py +33 -0
  27. supervised/callbacks/early_stopping.py +213 -0
  28. supervised/callbacks/learner_time_constraint.py +47 -0
  29. supervised/callbacks/max_iters_constraint.py +16 -0
  30. supervised/callbacks/metric_logger.py +48 -0
  31. supervised/callbacks/terminate_on_nan.py +28 -0
  32. supervised/callbacks/total_time_constraint.py +79 -0
  33. supervised/ensemble.py +583 -0
  34. supervised/exceptions.py +21 -0
  35. supervised/fairness/__init__.py +0 -0
  36. supervised/fairness/metrics.py +654 -0
  37. supervised/fairness/optimization.py +414 -0
  38. supervised/fairness/plots.py +131 -0
  39. supervised/fairness/report.py +116 -0
  40. supervised/fairness/utils.py +40 -0
  41. supervised/model_framework.py +734 -0
  42. supervised/preprocessing/__init__.py +0 -0
  43. supervised/preprocessing/datetime_transformer.py +106 -0
  44. supervised/preprocessing/encoding_selector.py +30 -0
  45. supervised/preprocessing/exclude_missing_target.py +46 -0
  46. supervised/preprocessing/goldenfeatures_transformer.py +310 -0
  47. supervised/preprocessing/kmeans_transformer.py +115 -0
  48. supervised/preprocessing/label_binarizer.py +81 -0
  49. supervised/preprocessing/label_encoder.py +54 -0
  50. supervised/preprocessing/preprocessing.py +652 -0
  51. supervised/preprocessing/preprocessing_categorical.py +117 -0
  52. supervised/preprocessing/preprocessing_missing.py +97 -0
  53. supervised/preprocessing/preprocessing_utils.py +136 -0
  54. supervised/preprocessing/scale.py +92 -0
  55. supervised/preprocessing/text_transformer.py +73 -0
  56. supervised/tuner/__init__.py +0 -0
  57. supervised/tuner/data_info.py +64 -0
  58. supervised/tuner/hill_climbing.py +80 -0
  59. supervised/tuner/mljar_tuner.py +1501 -0
  60. supervised/tuner/optuna/__init__.py +0 -0
  61. supervised/tuner/optuna/catboost.py +148 -0
  62. supervised/tuner/optuna/extra_trees.py +80 -0
  63. supervised/tuner/optuna/knn.py +64 -0
  64. supervised/tuner/optuna/lightgbm.py +165 -0
  65. supervised/tuner/optuna/nn.py +66 -0
  66. supervised/tuner/optuna/random_forest.py +77 -0
  67. supervised/tuner/optuna/tuner.py +335 -0
  68. supervised/tuner/optuna/xgboost.py +130 -0
  69. supervised/tuner/preprocessing_tuner.py +137 -0
  70. supervised/tuner/random_parameters.py +22 -0
  71. supervised/tuner/time_controller.py +273 -0
  72. supervised/utils/__init__.py +11 -0
  73. supervised/utils/additional_metrics.py +955 -0
  74. supervised/utils/additional_plots.py +228 -0
  75. supervised/utils/automl_plots.py +368 -0
  76. supervised/utils/common.py +39 -0
  77. supervised/utils/config.py +25 -0
  78. supervised/utils/constants.py +4 -0
  79. supervised/utils/data_validation.py +48 -0
  80. supervised/utils/importance.py +93 -0
  81. supervised/utils/jsonencoder.py +33 -0
  82. supervised/utils/leaderboard_plots.py +137 -0
  83. supervised/utils/learning_curves.py +145 -0
  84. supervised/utils/metric.py +450 -0
  85. supervised/utils/report_structured.py +525 -0
  86. supervised/utils/shap.py +373 -0
  87. supervised/utils/subsample.py +17 -0
  88. supervised/utils/utils.py +29 -0
  89. supervised/validation/__init__.py +0 -0
  90. supervised/validation/validation_step.py +37 -0
  91. supervised/validation/validator_base.py +17 -0
  92. supervised/validation/validator_custom.py +112 -0
  93. supervised/validation/validator_kfold.py +153 -0
  94. supervised/validation/validator_split.py +143 -0
@@ -0,0 +1,657 @@
1
+ Metadata-Version: 2.4
2
+ Name: mljar-supervised
3
+ Version: 1.2.1
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
+ Requires-Dist: numpy<3.0.0,>=2.0.0
19
+ Requires-Dist: pandas>=2.2.2
20
+ Requires-Dist: scipy>=1.13.1
21
+ Requires-Dist: scikit-learn>=1.5.0
22
+ Requires-Dist: xgboost>=2.1.0
23
+ Requires-Dist: lightgbm>=4.3.0
24
+ Requires-Dist: catboost>=1.2.8
25
+ Requires-Dist: joblib>=1.0.1
26
+ Requires-Dist: tabulate>=0.8.7
27
+ Requires-Dist: matplotlib>=3.8.4
28
+ Requires-Dist: dtreeviz>=2.2.2
29
+ Requires-Dist: shap>=0.46.0
30
+ Requires-Dist: seaborn>=0.13.2
31
+ Requires-Dist: optuna-integration>=3.6.0
32
+ Requires-Dist: mljar-scikit-plot>=0.3.11
33
+ Requires-Dist: markdown
34
+ Requires-Dist: typing-extensions
35
+ Requires-Dist: ipython
36
+ Dynamic: author
37
+ Dynamic: author-email
38
+ Dynamic: classifier
39
+ Dynamic: description
40
+ Dynamic: description-content-type
41
+ Dynamic: home-page
42
+ Dynamic: keywords
43
+ Dynamic: license
44
+ Dynamic: license-file
45
+ Dynamic: requires-dist
46
+ Dynamic: requires-python
47
+ Dynamic: summary
48
+
49
+
50
+
51
+ # MLJAR Automated Machine Learning for Humans
52
+
53
+ [![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)
54
+ [![PyPI version](https://badge.fury.io/py/mljar-supervised.svg)](https://badge.fury.io/py/mljar-supervised)
55
+ [![Anaconda-Server Badge](https://anaconda.org/conda-forge/mljar-supervised/badges/version.svg)](https://anaconda.org/conda-forge/mljar-supervised)
56
+ [![PyPI pyversions](https://img.shields.io/pypi/pyversions/mljar-supervised.svg)](https://pypi.python.org/pypi/mljar-supervised/)
57
+
58
+
59
+ [![Anaconda-Server Badge](https://anaconda.org/conda-forge/mljar-supervised/badges/platforms.svg)](https://anaconda.org/conda-forge/mljar-supervised)
60
+ [![Anaconda-Server Badge](https://anaconda.org/conda-forge/mljar-supervised/badges/license.svg)](https://anaconda.org/conda-forge/mljar-supervised)
61
+ [![Downloads](https://pepy.tech/badge/mljar-supervised)](https://pepy.tech/project/mljar-supervised)
62
+
63
+ <p align="center">
64
+ <img
65
+ alt="mljar AutoML"
66
+ src="https://raw.githubusercontent.com/mljar/mljar-examples/master/media/AutoML_white.png#gh-light-mode-only" width="50%" />
67
+ </p>
68
+ <p align="center">
69
+ <img
70
+ alt="mljar AutoML"
71
+ src="https://raw.githubusercontent.com/mljar/mljar-examples/master/media/AutoML_black.png#gh-dark-mode-only" width="50%" />
72
+ </p>
73
+
74
+ ---
75
+
76
+ **Documentation**: <a href="https://supervised.mljar.com/" target="_blank">https://supervised.mljar.com/</a>
77
+
78
+ **Source Code**: <a href="https://github.com/mljar/mljar-supervised" target="_blank">https://github.com/mljar/mljar-supervised</a>
79
+
80
+ **Use MLJAR Studio (Easiest Way to Run MLJAR AutoML)**
81
+ MLJAR Studio is the easiest way to run MLJAR AutoML, with conversational notebooks and AutoLab experiments (autonomous AI for ML pipeline optimization).
82
+ Start quickly, iterate faster, and manage experiments in one place.
83
+ [Try MLJAR Studio](https://mljar.com)
84
+
85
+
86
+ <p align="center">
87
+ <img src="https://raw.githubusercontent.com/mljar/mljar-examples/master/media/pipeline_AutoML.png" width="100%" />
88
+ </p>
89
+
90
+ ---
91
+
92
+ ## Table of Contents
93
+
94
+ - [Automated Machine Learning](https://github.com/mljar/mljar-supervised#automated-machine-learning)
95
+ - [What's good in it?](https://github.com/mljar/mljar-supervised#whats-good-in-it)
96
+ - [Automatic Documentation](https://github.com/mljar/mljar-supervised#automatic-documentation)
97
+ - [Available Modes](https://github.com/mljar/mljar-supervised#available-modes)
98
+ - [Fairness Aware Training](https://github.com/mljar/mljar-supervised#fairness-aware-training)
99
+ - [Examples](https://github.com/mljar/mljar-supervised#examples)
100
+ - [FAQ](https://github.com/mljar/mljar-supervised#faq)
101
+ - [Documentation](https://github.com/mljar/mljar-supervised#documentation)
102
+ - [Installation](https://github.com/mljar/mljar-supervised#installation)
103
+ - [Demo](https://github.com/mljar/mljar-supervised#demo)
104
+ - [Contributing](https://github.com/mljar/mljar-supervised#contributing)
105
+ - [Cite](https://github.com/mljar/mljar-supervised#cite)
106
+ - [License](https://github.com/mljar/mljar-supervised#license)
107
+ - [Commercial support](https://github.com/mljar/mljar-supervised#commercial-support)
108
+ - [MLJAR](https://github.com/mljar/mljar-supervised#mljar)
109
+
110
+
111
+
112
+
113
+
114
+ # Automated Machine Learning
115
+
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
+
118
+ The `mljar-supervised` will help you with:
119
+ - explaining and understanding your data (Automatic Exploratory Data Analysis),
120
+ - trying many different machine learning models (Algorithm Selection and Hyper-Parameters tuning),
121
+ - creating Markdown reports from analysis with details about all models (Automatic-Documentation),
122
+ - saving, re-running, and loading the analysis and ML models.
123
+
124
+ It has four built-in modes of work:
125
+ - `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,
126
+ - `Perform` for building ML pipelines to use in production,
127
+ - `Compete` mode that trains highly-tuned ML models with ensembling and stacking, with the purpose to use in ML competitions.
128
+ - `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`)
129
+
130
+ Of course, you can further customize the details of each `mode` to meet the requirements.
131
+
132
+ ## What's good in it?
133
+
134
+ - It uses many algorithms: `Baseline`, `Linear`, `Random Forest`, `Extra Trees`, `LightGBM`, `Xgboost`, `CatBoost`, `Neural Networks`, and `Nearest Neighbors`.
135
+ - It can compute Ensemble based on a greedy algorithm from [Caruana paper](http://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf).
136
+ - It can stack models to build a level 2 ensemble (available in `Compete` mode or after setting the `stack_models` parameter).
137
+ - It can do features preprocessing, like missing values imputation and converting categoricals. What is more, it can also handle target values preprocessing.
138
+ - 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.
139
+ - 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.
140
+ - It can compute the `Baseline` for your data so that you will know if you need Machine Learning or not!
141
+ - 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.
142
+ - 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.
143
+ - 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).
144
+ - 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.
145
+
146
+ <p align="center">
147
+ <img src="https://raw.githubusercontent.com/mljar/visual-identity/main/media/infograph.png" width="100%" />
148
+ </p>
149
+
150
+ # Automatic Documentation
151
+
152
+ ## The AutoML Report
153
+
154
+ 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:.
155
+
156
+ ![AutoML leaderboard](https://github.com/mljar/mljar-examples/blob/master/media/automl_summary.gif)
157
+
158
+ ## The `Decision Tree` Report
159
+
160
+ The example for `Decision Tree` summary with trees visualization. For classification tasks, additional metrics are provided:
161
+ - confusion matrix
162
+ - threshold (optimized in the case of binary classification task)
163
+ - F1 score
164
+ - Accuracy
165
+ - Precision, Recall, MCC
166
+
167
+ ![Decision Tree summary](https://github.com/mljar/mljar-examples/blob/master/media/decision_tree_summary.gif)
168
+
169
+ ## The `LightGBM` Report
170
+
171
+ The example for `LightGBM` summary:
172
+
173
+ ![Decision Tree summary](https://github.com/mljar/mljar-examples/blob/master/media/lightgbm_summary.gif)
174
+
175
+
176
+ ## Available Modes
177
+
178
+ In the [docs](https://supervised.mljar.com/features/modes/) you can find details about AutoML modes that are presented in the table.
179
+
180
+ <p align="center">
181
+ <img src="https://raw.githubusercontent.com/mljar/visual-identity/main/media/mljar_modes.png" width="100%" />
182
+ </p>
183
+
184
+ ### Explain
185
+
186
+ ```py
187
+ automl = AutoML(mode="Explain")
188
+ ```
189
+
190
+ It is aimed to be used when the user wants to explain and understand the data.
191
+ - It is using 75%/25% train/test split.
192
+ - It uses: `Baseline`, `Linear`, `Decision Tree`, `Random Forest`, `Xgboost`, `Neural Network' algorithms, and ensemble.
193
+ - It has full explanations: learning curves, importance plots, and SHAP plots.
194
+
195
+ ### Perform
196
+
197
+ ```py
198
+ automl = AutoML(mode="Perform")
199
+ ```
200
+
201
+ It should be used when the user wants to train a model that will be used in real-life use cases.
202
+ - It uses a 5-fold CV.
203
+ - It uses: `Linear`, `Random Forest`, `LightGBM`, `Xgboost`, `CatBoost`, and `Neural Network`. It uses ensembling.
204
+ - It has learning curves and importance plots in reports.
205
+
206
+ ### Compete
207
+
208
+ ```py
209
+ automl = AutoML(mode="Compete")
210
+ ```
211
+
212
+ It should be used for machine learning competitions.
213
+ - 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.
214
+ - It is using: `Linear`, `Decision Tree`, `Random Forest`, `Extra Trees`, `LightGBM`, `Xgboost`, `CatBoost`, `Neural Network`, and `Nearest Neighbors`. It uses ensemble and **stacking**.
215
+ - It has only learning curves in the reports.
216
+
217
+ ### Optuna
218
+
219
+ ```py
220
+ automl = AutoML(mode="Optuna", optuna_time_budget=3600)
221
+ ```
222
+
223
+ It should be used when the performance is the most important and time is not limited.
224
+ - It uses a 10-fold CV
225
+ - 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.
226
+ - It uses advanced feature engineering, stacking and ensembling. The hyperparameters found for original data are reused with those steps.
227
+ - It produces learning curves in the reports.
228
+
229
+
230
+
231
+ ## How to save and load AutoML?
232
+
233
+ All models in the AutoML are saved and loaded automatically. No need to call `save()` or `load()`.
234
+
235
+ ### Example:
236
+
237
+ #### Train AutoML
238
+
239
+ ```python
240
+ automl = AutoML(results_path="AutoML_classifier")
241
+ automl.fit(X, y)
242
+ ```
243
+
244
+ 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.
245
+
246
+ #### Compute predictions
247
+ ```python
248
+ automl = AutoML(results_path="AutoML_classifier")
249
+ automl.predict(X)
250
+ ```
251
+
252
+ 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.
253
+
254
+
255
+ ### Why do you automatically save all models?
256
+
257
+ 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.
258
+
259
+ ## Supported evaluation metrics (`eval_metric` argument in `AutoML()`)
260
+
261
+ - for binary classification: `logloss`, `auc`, `f1`, `average_precision`, `accuracy`- default is `logloss`
262
+ - for multiclass classification: `logloss`, `f1`, `accuracy` - default is `logloss`
263
+ - for regression: `rmse`, `mse`, `mae`, `r2`, `mape`, `spearman`, `pearson` - default is `rmse`
264
+
265
+ If you don't find the `eval_metric` that you need, please add a new issue. We will add it.
266
+
267
+
268
+ ## Fairness Aware Training
269
+
270
+ 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:
271
+ - `fairness_metric` - metric which will be used to decide if the model is fair,
272
+ - `fairness_threshold` - threshold used in decision about model fairness,
273
+ - `privileged_groups` - privileged groups used in fairness metrics computation,
274
+ - `underprivileged_groups` - underprivileged groups used in fairness metrics computation.
275
+
276
+ 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:
277
+ - Sample Weighting - assigns weights to samples to treat samples equally,
278
+ - Smart Grid Search - similar to Sample Weighting, where different weights are checked to optimize fairness metric.
279
+
280
+ The fair ML building can be used with all algorithms, including `Ensemble` and `Stacked Ensemble`. We support three Machine Learning tasks:
281
+ - binary classification,
282
+ - mutliclass classification,
283
+ - regression.
284
+
285
+ Example code:
286
+
287
+
288
+ ```python
289
+ from sklearn.model_selection import train_test_split
290
+ from sklearn.datasets import fetch_openml
291
+ from supervised.automl import AutoML
292
+
293
+ data = fetch_openml(data_id=1590, as_frame=True)
294
+ X = data.data
295
+ y = (data.target == ">50K") * 1
296
+ sensitive_features = X[["sex"]]
297
+
298
+ X_train, X_test, y_train, y_test, S_train, S_test = train_test_split(
299
+ X, y, sensitive_features, stratify=y, test_size=0.75, random_state=42
300
+ )
301
+
302
+ automl = AutoML(
303
+ algorithms=[
304
+ "Xgboost"
305
+ ],
306
+ train_ensemble=False,
307
+ fairness_metric="demographic_parity_ratio",
308
+ fairness_threshold=0.8,
309
+ privileged_groups = [{"sex": "Male"}],
310
+ underprivileged_groups = [{"sex": "Female"}],
311
+ )
312
+
313
+ automl.fit(X_train, y_train, sensitive_features=S_train)
314
+ ```
315
+
316
+ You can read more about fairness aware AutoML training in our article https://mljar.com/blog/fairness-machine-learning/
317
+
318
+ ![Fairness aware AutoML](https://raw.githubusercontent.com/mljar/visual-identity/main/automl/fairness-automl.gif)
319
+
320
+
321
+
322
+ # Examples
323
+
324
+ ## :point_right: Binary Classification Example
325
+
326
+ There is a simple interface available with `fit` and `predict` methods.
327
+
328
+ ```python
329
+ import pandas as pd
330
+ from sklearn.model_selection import train_test_split
331
+ from supervised.automl import AutoML
332
+
333
+ df = pd.read_csv(
334
+ "https://raw.githubusercontent.com/pplonski/datasets-for-start/master/adult/data.csv",
335
+ skipinitialspace=True,
336
+ )
337
+ X_train, X_test, y_train, y_test = train_test_split(
338
+ df[df.columns[:-1]], df["income"], test_size=0.25
339
+ )
340
+
341
+ automl = AutoML()
342
+ automl.fit(X_train, y_train)
343
+
344
+ predictions = automl.predict(X_test)
345
+ ```
346
+
347
+ AutoML `fit` will print:
348
+ ```py
349
+ Create directory AutoML_1
350
+ AutoML task to be solved: binary_classification
351
+ AutoML will use algorithms: ['Baseline', 'Linear', 'Decision Tree', 'Random Forest', 'Xgboost', 'Neural Network']
352
+ AutoML will optimize for metric: logloss
353
+ 1_Baseline final logloss 0.5519845471086654 time 0.08 seconds
354
+ 2_DecisionTree final logloss 0.3655910192804364 time 10.28 seconds
355
+ 3_Linear final logloss 0.38139916864708445 time 3.19 seconds
356
+ 4_Default_RandomForest final logloss 0.2975204390214936 time 79.19 seconds
357
+ 5_Default_Xgboost final logloss 0.2731086827200411 time 5.17 seconds
358
+ 6_Default_NeuralNetwork final logloss 0.319812276905242 time 21.19 seconds
359
+ Ensemble final logloss 0.2731086821194617 time 1.43 seconds
360
+ ```
361
+
362
+ - the AutoML results in [Markdown report](https://github.com/mljar/mljar-examples/tree/master/Income_classification/AutoML_1#automl-leaderboard)
363
+ - 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:
364
+ - 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:
365
+ - 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:
366
+
367
+
368
+ ## :point_right: Multi-Class Classification Example
369
+
370
+ 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%.
371
+
372
+ ```python
373
+ import pandas as pd
374
+ # scikit learn utilites
375
+ from sklearn.datasets import load_digits
376
+ from sklearn.metrics import accuracy_score
377
+ from sklearn.model_selection import train_test_split
378
+ # mljar-supervised package
379
+ from supervised.automl import AutoML
380
+
381
+ # load the data
382
+ digits = load_digits()
383
+ X_train, X_test, y_train, y_test = train_test_split(
384
+ pd.DataFrame(digits.data), digits.target, stratify=digits.target, test_size=0.25,
385
+ random_state=123
386
+ )
387
+
388
+ # train models with AutoML
389
+ automl = AutoML(mode="Perform")
390
+ automl.fit(X_train, y_train)
391
+
392
+ # compute the accuracy on test data
393
+ predictions = automl.predict_all(X_test)
394
+ print(predictions.head())
395
+ print("Test accuracy:", accuracy_score(y_test, predictions["label"].astype(int)))
396
+ ```
397
+
398
+ ## :point_right: Regression Example
399
+
400
+ Regression example on `California Housing` house prices data.
401
+
402
+ ```python
403
+ import numpy as np
404
+ import pandas as pd
405
+ from sklearn.datasets import fetch_california_housing
406
+ from sklearn.model_selection import train_test_split
407
+ from sklearn.metrics import mean_squared_error
408
+ from supervised.automl import AutoML # mljar-supervised
409
+
410
+ # Load the data
411
+ housing = fetch_california_housing()
412
+ X_train, X_test, y_train, y_test = train_test_split(
413
+ pd.DataFrame(housing.data, columns=housing.feature_names),
414
+ housing.target,
415
+ test_size=0.25,
416
+ random_state=123,
417
+ )
418
+
419
+ # train models with AutoML
420
+ automl = AutoML(mode="Explain")
421
+ automl.fit(X_train, y_train)
422
+
423
+ # compute the MSE on test data
424
+ predictions = automl.predict(X_test)
425
+ print("Test MSE:", mean_squared_error(y_test, predictions))
426
+ ```
427
+
428
+ ## :point_right: More Examples
429
+
430
+ - [**Income classification**](https://github.com/mljar/mljar-examples/tree/master/Income_classification) - it is a binary classification task on census data
431
+ - [**Iris classification**](https://github.com/mljar/mljar-examples/tree/master/Iris_classification) - it is a multiclass classification on Iris flowers data
432
+ - [**House price regression**](https://github.com/mljar/mljar-examples/tree/master/House_price_regression) - it is a regression task on Boston houses data
433
+
434
+ # FAQ
435
+
436
+ <details><summary>What method is used for hyperparameters optimization?</summary>
437
+ - 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.
438
+ - 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`.
439
+ </details>
440
+
441
+ <details><summary>How to save and load AutoML?</summary>
442
+
443
+ 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).
444
+
445
+ Example save and load:
446
+
447
+ ```python
448
+ automl = AutoML(results_path='AutoML_1')
449
+ automl.fit(X, y)
450
+ ```
451
+
452
+ The all models from AutoML are saved in `AutoML_1` directory.
453
+
454
+ To load models:
455
+
456
+ ```python
457
+ automl = AutoML(results_path='AutoML_1')
458
+ automl.predict(X)
459
+ ```
460
+
461
+ </details>
462
+
463
+ <details><summary>How to set ML task (select between classification or regression)?</summary>
464
+
465
+ The MLJAR AutoML can work with:
466
+ - binary classification
467
+ - multi-class classification
468
+ - regression
469
+
470
+ 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'`.
471
+
472
+ Example:
473
+ ```python
474
+ automl = AutoML(ml_task='regression')
475
+ automl.fit(X, y)
476
+ ```
477
+ In the above example the regression model will be fitted.
478
+
479
+ </details>
480
+
481
+ <details><summary>How to reuse Optuna hyperparameters?</summary>
482
+
483
+ 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).
484
+
485
+ Example:
486
+
487
+ ```python
488
+ optuna_init = json.loads(open('previous_AutoML_training/optuna/optuna.json').read())
489
+
490
+ automl = AutoML(
491
+ mode='Optuna',
492
+ optuna_init_params=optuna_init
493
+ )
494
+ automl.fit(X, y)
495
+ ```
496
+
497
+ 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.
498
+
499
+
500
+ </details>
501
+
502
+
503
+ <details><summary>How to know the order of classes for binary or multiclass problem when using predict_proba?</summary>
504
+
505
+ 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.
506
+
507
+ </details>
508
+
509
+ # Documentation
510
+
511
+ For details please check [mljar-supervised docs](https://supervised.mljar.com).
512
+
513
+ ## Structured Report for LLMs
514
+
515
+ The AutoML object can generate a structured report that is easier to analyze with LLMs and external tools:
516
+
517
+ ```python
518
+ from supervised import AutoML
519
+
520
+ automl = AutoML(results_path="AutoML_example")
521
+ automl.fit(X, y)
522
+
523
+ # Default output is markdown text
524
+ markdown_report = automl.report_structured()
525
+ print(markdown_report)
526
+ ```
527
+
528
+ You can also get programmatic formats:
529
+
530
+ ```python
531
+ # Python dictionary
532
+ payload = automl.report_structured(format="dict")
533
+
534
+ # JSON string
535
+ payload_json = automl.report_structured(format="json")
536
+ ```
537
+
538
+ Each call creates/updates:
539
+
540
+ ```text
541
+ <results_path>/report_structured.json
542
+ ```
543
+
544
+ Use the `model_details` argument to control markdown verbosity:
545
+
546
+ ```python
547
+ compact = automl.report_structured(model_details=False)
548
+ detailed = automl.report_structured(model_details=True)
549
+ ```
550
+
551
+ The detailed markdown includes per-model metric tables, fairness details (if used), and feature importance summaries when importance files are available.
552
+
553
+ # Installation
554
+
555
+ Compatibility:
556
+ - Python `>=3.9`
557
+ - NumPy `>=2.0,<3`
558
+
559
+ From PyPi repository:
560
+
561
+ ```
562
+ pip install mljar-supervised
563
+ ```
564
+
565
+ To install this package with conda run:
566
+ ```
567
+ conda install -c conda-forge mljar-supervised
568
+ ```
569
+
570
+ From source code:
571
+
572
+ ```
573
+ git clone https://github.com/mljar/mljar-supervised.git
574
+ cd mljar-supervised
575
+ python setup.py install
576
+ ```
577
+
578
+ Installation for development
579
+ ```
580
+ git clone https://github.com/mljar/mljar-supervised.git
581
+ virtualenv venv --python=python3.9
582
+ source venv/bin/activate
583
+ pip install -r requirements.txt
584
+ pip install -r requirements_dev.txt
585
+ ```
586
+
587
+ Running in the docker:
588
+ ```
589
+ FROM python:3.9-slim-buster
590
+ RUN apt-get update && apt-get -y update
591
+ RUN apt-get install -y build-essential python3-pip python3-dev
592
+ RUN pip3 -q install pip --upgrade
593
+ RUN pip3 install mljar-supervised jupyter
594
+ CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]
595
+ ```
596
+
597
+ Install from GitHub with pip:
598
+ ```
599
+ pip install -q -U git+https://github.com/mljar/mljar-supervised.git@master
600
+ ```
601
+ # Demo
602
+
603
+ In the below demo GIF you will see:
604
+ - MLJAR AutoML trained in Jupyter Notebook on the Titanic dataset
605
+ - overview of created files
606
+ - a showcase of selected plots created during AutoML training
607
+ - algorithm comparison report along with their plots
608
+ - example of README file and CSV file with results
609
+
610
+ ![](https://github.com/mljar/mljar-examples/raw/master/media/mljar_files.gif)
611
+
612
+ # Contributing
613
+
614
+ 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!
615
+
616
+ ### Contributors
617
+ <a href="https://github.com/mljar/mljar-supervised/graphs/contributors">
618
+ <img src="https://contributors-img.web.app/image?repo=mljar/mljar-supervised" />
619
+ </a>
620
+
621
+ # Cite
622
+
623
+ Would you like to cite MLJAR? Great! :)
624
+
625
+ You can cite MLJAR as follows:
626
+
627
+ ```
628
+ @misc{mljar,
629
+ author = {Aleksandra P\l{}o\'{n}ska and Piotr P\l{}o\'{n}ski},
630
+ year = {2021},
631
+ publisher = {MLJAR},
632
+ address = {\L{}apy, Poland},
633
+ title = {MLJAR: State-of-the-art Automated Machine Learning Framework for Tabular Data. Version 0.10.3},
634
+ url = {https://github.com/mljar/mljar-supervised}
635
+ }
636
+ ```
637
+
638
+ Would love to hear from you about how have you used MLJAR AutoML in your project.
639
+ Please feel free to let us know at
640
+ ![image](https://user-images.githubusercontent.com/6959032/118103228-f5ea9a00-b3d9-11eb-87ed-8cfb1f873f91.png)
641
+
642
+
643
+ # License
644
+
645
+ The `mljar-supervised` is provided with [MIT license](https://github.com/mljar/mljar-supervised/blob/master/LICENSE).
646
+
647
+ # Commercial support
648
+
649
+ Looking for commercial support? Do you need new feature implementation? Please contact us by [email](https://mljar.com/contact/) for details.
650
+
651
+ # MLJAR
652
+ <p align="center">
653
+ <img src="https://github.com/mljar/mljar-examples/blob/master/media/large_logo.png" width="314" />
654
+ </p>
655
+
656
+ The `mljar-supervised` is an open-source project created by [MLJAR](https://mljar.com). We care about ease of use in Machine Learning.
657
+ The [mljar.com](https://mljar.com) provides a beautiful and simple user interface for building machine learning models.