-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial_binary_classification.py
696 lines (464 loc) · 24.8 KB
/
tutorial_binary_classification.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
# -*- coding: utf-8 -*-
"""Tutorial - Binary Classification.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/github/pycaret/pycaret/blob/master/tutorials/Tutorial%20-%20Binary%20Classification.ipynb
Last updated: 16 Feb 2023
# 👋 PyCaret Binary Classification Tutorial
PyCaret is an open-source, low-code machine learning library in Python that automates machine learning workflows. It is an end-to-end machine learning and model management tool that exponentially speeds up the experiment cycle and makes you more productive.
Compared with the other open-source machine learning libraries, PyCaret is an alternate low-code library that can be used to replace hundreds of lines of code with a few lines only. This makes experiments exponentially fast and efficient. PyCaret is essentially a Python wrapper around several machine learning libraries and frameworks, such as scikit-learn, XGBoost, LightGBM, CatBoost, spaCy, Optuna, Hyperopt, Ray, and a few more.
The design and simplicity of PyCaret are inspired by the emerging role of citizen data scientists, a term first used by Gartner. Citizen Data Scientists are power users who can perform both simple and moderately sophisticated analytical tasks that would previously have required more technical expertise.
# 💻 Installation
PyCaret is tested and supported on the following 64-bit systems:
- Python 3.7 – 3.10
- Python 3.9 for Ubuntu only
- Ubuntu 16.04 or later
- Windows 7 or later
You can install PyCaret with Python's pip package manager:
`pip install pycaret`
PyCaret's default installation will not install all the extra dependencies automatically. For that you will have to install the full version:
`pip install pycaret[full]`
or depending on your use-case you may install one of the following variant:
- `pip install pycaret[analysis]`
- `pip install pycaret[models]`
- `pip install pycaret[tuner]`
- `pip install pycaret[mlops]`
- `pip install pycaret[parallel]`
- `pip install pycaret[test]`
"""
# check installed version
import pycaret
pycaret.__version__
"""# 🚀 Quick start
PyCaret’s Classification Module is a supervised machine learning module that is used for classifying elements into groups. The goal is to predict the categorical class labels which are discrete and unordered.
Some common use cases include predicting customer default (Yes or No), predicting customer churn (customer will leave or stay), the disease found (positive or negative).
This module can be used for binary or multiclass problems. It provides several pre-processing features that prepare the data for modeling through the setup function. It has over 18 ready-to-use algorithms and several plots to analyze the performance of trained models.
A typical workflow in PyCaret consist of following 5 steps in this order:
## **Setup** ➡️ **Compare Models** ➡️ **Analyze Model** ➡️ **Prediction** ➡️ **Save Model**
"""
# loading sample dataset from pycaret dataset module
from pycaret.datasets import get_data
data = get_data('diabetes')
"""## Setup
This function initializes the training environment and creates the transformation pipeline. Setup function must be called before executing any other function in PyCaret. It only has two required parameters i.e. `data` and `target`. All the other parameters are optional.
"""
# import pycaret classification and init setup
from pycaret.classification import *
s = setup(data, target = 'Class variable', session_id = 123)
"""Once the setup has been successfully executed it shows the information grid containing experiment level information.
- **Session id:** A pseudo-random number distributed as a seed in all functions for later reproducibility. If no `session_id` is passed, a random number is automatically generated that is distributed to all functions.<br/>
<br/>
- **Target type:** Binary, Multiclass, or Regression. The Target type is automatically detected. <br/>
<br/>
- **Label Encoding:** When the Target variable is of type string (i.e. 'Yes' or 'No') instead of 1 or 0, it automatically encodes the label into 1 and 0 and displays the mapping (0 : No, 1 : Yes) for reference. In this tutorial, no label encoding is required since the target variable is of numeric type. <br/>
<br/>
- **Original data shape:** Shape of the original data prior to any transformations. <br/>
<br/>
- **Transformed train set shape :** Shape of transformed train set <br/>
<br/>
- **Transformed test set shape :** Shape of transformed test set <br/>
<br/>
- **Numeric features :** The number of features considered as numerical. <br/>
<br/>
- **Categorical features :** The number of features considered as categorical. <br/>
PyCaret has two set of API's that you can work with. (1) Functional (as seen above) and (2) Object Oriented API.
With Object Oriented API instead of executing functions directly you will import a class and execute methods of class.
"""
# import ClassificationExperiment and init the class
from pycaret.classification import ClassificationExperiment
exp = ClassificationExperiment()
# check the type of exp
type(exp)
# init setup on exp
exp.setup(data, target = 'Class variable', session_id = 123)
"""You can use any of the two method i.e. Functional or OOP and even switch back and forth between two set of API's. The choice of method will not impact the results and has been tested for consistency.
## Compare Models
This function trains and evaluates the performance of all the estimators available in the model library using cross-validation. The output of this function is a scoring grid with average cross-validated scores. Metrics evaluated during CV can be accessed using the `get_metrics` function. Custom metrics can be added or removed using `add_metric` and `remove_metric` function.
"""
# compare baseline models
best = compare_models()
# compare models using OOP
exp.compare_models()
"""Notice that the output between functional and OOP API is consistent. Rest of the functions in this notebook will only be shown using functional API only.
## Analyze Model
You can use the `plot_model` function to analyzes the performance of a trained model on the test set. It may require re-training the model in certain cases.
"""
# plot confusion matrix
plot_model(best, plot = 'confusion_matrix')
# plot AUC
plot_model(best, plot = 'auc')
# plot feature importance
plot_model(best, plot = 'feature')
# check docstring to see available plots
# help(plot_model)
"""An alternate to `plot_model` function is `evaluate_model`. It can only be used in Notebook since it uses ipywidget."""
evaluate_model(best)
"""___
## Prediction
The `predict_model` function returns `prediction_label` and `prediction_score` (probability of the predicted class) as new columns in dataframe. When data is `None` (default), it uses the test set (created during the setup function) for scoring.
"""
# predict on test set
holdout_pred = predict_model(best)
# show predictions df
holdout_pred.head()
"""The same function works for predicting the labels on unseen dataset. Let's create a copy of original data and drop the `Class variable`. We can then use the new data frame without labels for scoring."""
# copy data and drop Class variable
new_data = data.copy()
new_data.drop('Class variable', axis=1, inplace=True)
new_data.head()
# predict model on new_data
predictions = predict_model(best, data = new_data)
predictions.head()
"""## Save Model
Finally, you can save the entire pipeline on disk for later use, using pycaret's `save_model` function.
"""
# save pipeline
save_model(best, 'my_first_pipeline')
# load pipeline
loaded_best_pipeline = load_model('my_first_pipeline')
loaded_best_pipeline
"""# 👇 Detailed function-by-function overview
## ✅ Setup
This function initializes the experiment in PyCaret and creates the transformation pipeline based on all the parameters passed in the function. Setup function must be called before executing any other function. It takes two required parameters: `data` and `target`. All the other parameters are optional and are used for configuring data preprocessing pipeline.
"""
# init setup function
s = setup(data, target = 'Class variable', session_id = 123)
"""To access all the variables created by the setup function such as transformed dataset, random_state, etc. you can use `get_config` method."""
# check all available config
get_config()
# lets access X_train_transformed
get_config('X_train_transformed')
# another example: let's access seed
print("The current seed is: {}".format(get_config('seed')))
# now lets change it using set_config
set_config('seed', 786)
print("The new seed is: {}".format(get_config('seed')))
"""All the preprocessing configurations and experiment settings/parameters are passed into the `setup` function. To see all available parameters, check the docstring:"""
# help(setup)
# init setup with normalize = True
s = setup(data, target = 'Class variable', session_id = 123,
normalize = True, normalize_method = 'minmax')
# lets check the X_train_transformed to see effect of params passed
get_config('X_train_transformed')['Number of times pregnant'].hist()
"""Notice that all the values are between 0 and 1 - that is because we passed `normalize=True` in the `setup` function. If you don't remember how it compares to actual data, no problem - we can also access non-transformed values using `get_config` and then compare. See below and notice the range of values on x-axis and compare it with histogram above."""
get_config('X_train')['Number of times pregnant'].hist()
"""___
## ✅ Compare Models
This function trains and evaluates the performance of all estimators available in the model library using cross-validation. The output of this function is a scoring grid with average cross-validated scores. Metrics evaluated during CV can be accessed using the `get_metrics` function. Custom metrics can be added or removed using `add_metric` and `remove_metric` function.
"""
best = compare_models()
"""`compare_models` by default uses all the estimators in model library (all except models with `Turbo=False`) . To see all available models you can use the function `models()`"""
# check available models
models()
"""You can use the `include` and `exclude` parameter in the `compare_models` to train only select model or exclude specific models from training by passing the model id's in `exclude` parameter."""
compare_tree_models = compare_models(include = ['dt', 'rf', 'et', 'gbc', 'xgboost', 'lightgbm', 'catboost'])
compare_tree_models
"""The function above has return trained model object as an output. The scoring grid is only displayed and not returned. If you need access to the scoring grid you can use `pull` function to access the dataframe."""
compare_tree_models_results = pull()
compare_tree_models_results
"""By default `compare_models` return the single best performing model based on the metric defined in the `sort` parameter. Let's change our code to return 3 top models based on `Recall`."""
best_recall_models_top3 = compare_models(sort = 'Recall', n_select = 3)
# list of top 3 models by Recall
best_recall_models_top3
"""Some other parameters that you might find very useful in `compare_models` are:
- fold
- cross_validation
- budget_time
- errors
- probability_threshold
- parallel
You can check the docstring of the function for more info.
"""
# help(compare_models)
"""## ✅ Set Custom Metrics"""
# check available metrics used in CV
get_metrics()
# create a custom function
import numpy as np
def custom_metric(y, y_pred):
tp = np.where((y_pred==1) & (y==1), (100), 0)
fp = np.where((y_pred==1) & (y==0), -5, 0)
return np.sum([tp,fp])
# add metric to PyCaret
add_metric('custom_metric', 'Custom Metric', custom_metric)
# now let's run compare_models again
compare_models()
# remove custom metric
remove_metric('custom_metric')
"""## ✅ Experiment Logging
PyCaret integrates with many different type of experiment loggers (default = 'mlflow'). To turn on experiment tracking in PyCaret you can set `log_experiment` and `experiment_name` parameter. It will automatically track all the metrics, hyperparameters, and artifacts based on the defined logger.
"""
# from pycaret.classification import *
# s = setup(data, target = 'Class variable', log_experiment='mlflow', experiment_name='diabetes_experiment')
# compare models
# best = compare_models()
# start mlflow server on localhost:5000
# !mlflow ui
"""By default PyCaret uses `MLFlow` logger that can be changed using `log_experiment` parameter. Following loggers are available:
- mlflow
- wandb
- comet_ml
- dagshub
Other logging related parameters that you may find useful are:
- experiment_custom_tags
- log_plots
- log_data
- log_profile
For more information check out the docstring of the `setup` function.
"""
# help(setup)
"""## ✅ Create Model
This function trains and evaluates the performance of a given estimator using cross-validation. The output of this function is a scoring grid with CV scores by fold. Metrics evaluated during CV can be accessed using the `get_metrics` function. Custom metrics can be added or removed using `add_metric` and `remove_metric` function. All the available models can be accessed using the models function.
"""
# check all the available models
models()
# train logistic regression with default fold=10
lr = create_model('lr')
"""The function above has return trained model object as an output. The scoring grid is only displayed and not returned. If you need access to the scoring grid you can use `pull` function to access the dataframe."""
lr_results = pull()
print(type(lr_results))
lr_results
# train logistic regression with fold=3
lr = create_model('lr', fold=3)
# train logistic regression with specific model parameters
create_model('lr', C = 0.5, l1_ratio = 0.15)
# train lr and return train score as well alongwith CV
create_model('lr', return_train_score=True)
# change the probability threshold of classifier from 0.5 to 0.66
create_model('lr', probability_threshold = 0.66)
"""Some other parameters that you might find very useful in `create_model` are:
- cross_validation
- engine
- fit_kwargs
- groups
You can check the docstring of the function for more info.
"""
# help(create_model)
"""## ✅ Tune Model
This function tunes the hyperparameters of the model. The output of this function is a scoring grid with cross-validated scores by fold. The best model is selected based on the metric defined in optimize parameter. Metrics evaluated during cross-validation can be accessed using the `get_metrics` function. Custom metrics can be added or removed using `add_metric` and `remove_metric` function.
"""
# train a dt model with default params
dt = create_model('dt')
# tune hyperparameters of dt
tuned_dt = tune_model(dt)
"""Metric to optimize can be defined in `optimize` parameter (default = 'Accuracy'). Also, a custom tuned grid can be passed with `custom_grid` parameter."""
dt
# define tuning grid
dt_grid = {'max_depth' : [None, 2, 4, 6, 8, 10, 12]}
# tune model with custom grid and metric = F1
tuned_dt = tune_model(dt, custom_grid = dt_grid, optimize = 'F1')
# to access the tuner object you can set return_tuner = True
tuned_dt, tuner = tune_model(dt, return_tuner=True)
# model object
tuned_dt
# tuner object
tuner
"""The default search algorithm is `RandomizedSearchCV` from `sklearn`. This can be changed by using `search_library` and `search_algorithm` parameter."""
# tune dt using optuna
tuned_dt = tune_model(dt, search_library = 'optuna')
"""For more details on all available `search_library` and `search_algorithm` please check the docstring. Some other parameters that you might find very useful in `tune_model` are:
- choose_better
- n_iter
- early_stopping
- groups
You can check the docstring of the function for more info.
"""
# help(tune_model)
"""## ✅ Ensemble Model
This function ensembles a given estimator. The output of this function is a scoring grid with CV scores by fold. Metrics evaluated during CV can be accessed using the `get_metrics` function. Custom metrics can be added or removed using `add_metric` and `remove_metric` function.
"""
# ensemble with bagging
ensemble_model(dt, method = 'Bagging')
# ensemble with boosting
ensemble_model(dt, method = 'Boosting')
"""Some other parameters that you might find very useful in `ensemble_model` are:
- choose_better
- n_estimators
- groups
- fit_kwargs
- probability_threshold
- return_train_score
You can check the docstring of the function for more info.
"""
# help(ensemble_model)
"""## ✅ Blend Models
This function trains a Soft Voting / Majority Rule classifier for select models passed in the estimator_list parameter. The output of this function is a scoring grid with CV scores by fold. Metrics evaluated during CV can be accessed using the `get_metrics` function. Custom metrics can be added or removed using `add_metric` and `remove_metric` function.
"""
# top 3 models based on recall
best_recall_models_top3
# blend top 3 models
blend_models(best_recall_models_top3)
"""Some other parameters that you might find very useful in `blend_models` are:
- choose_better
- method
- weights
- fit_kwargs
- probability_threshold
- return_train_score
You can check the docstring of the function for more info.
"""
# help(blend_models)
"""## ✅ Stack Models
This function trains a meta-model over select estimators passed in the estimator_list parameter. The output of this function is a scoring grid with CV scores by fold. Metrics evaluated during CV can be accessed using the `get_metrics` function. Custom metrics can be added or removed using `add_metric` and `remove_metric` function.
"""
# stack models
stack_models(best_recall_models_top3)
"""Some other parameters that you might find very useful in `stack_models` are:
- choose_better
- meta_model
- method
- restack
- probability_threshold
- return_train_score
You can check the docstring of the function for more info.
"""
# help(stack_models)
"""## ✅ Plot Model
This function analyzes the performance of a trained model on the hold-out set. It may require re-training the model in certain cases.
"""
# plot class report
plot_model(best, plot = 'class_report')
# to control the scale of plot
plot_model(best, plot = 'class_report', scale = 2)
# to save the plot
plot_model(best, plot = 'class_report', save=True)
"""Some other parameters that you might find very useful in `plot_model` are:
- fit_kwargs
- plot_kwargs
- groups
- display_format
You can check the docstring of the function for more info.
"""
# help(plot_model)
"""## ✅ Interpret Model
This function analyzes the predictions generated from a trained model. Most plots in this function are implemented based on the SHAP (Shapley Additive exPlanations). For more info on this, please see https://shap.readthedocs.io/en/latest/
"""
# train lightgbm model
lightgbm = create_model('lightgbm')
# interpret summary model
interpret_model(lightgbm, plot = 'summary')
# reason plot for test set observation 1
interpret_model(lightgbm, plot = 'reason', observation = 1)
"""Some other parameters that you might find very useful in `interpret_model` are:
- plot
- feature
- use_train_data
- X_new_sample
- y_new_sample
- save
You can check the docstring of the function for more info.
"""
# help(interpret_model)
"""## ✅ Calibrate Model
This function calibrates the probability of a given model using isotonic or logistic regression. The output of this function is a scoring grid with CV scores by fold. Metrics evaluated during CV can be accessed using the `get_metrics` function. Custom metrics can be added or removed using `add_metric` and `remove_metric` function.
"""
# check calbiration of default dt
plot_model(dt, plot = 'calibration')
# calibrate default dt
calibrated_dt = calibrate_model(dt)
# check calbiration of calibrated dt
plot_model(calibrated_dt, plot = 'calibration')
"""Some other parameters that you might find very useful in `calibrate_model` are:
- calibrate_fold
- fit_kwargs
- method
- return_train_score
- groups
You can check the docstring of the function for more info.
"""
# help(calibrate_model)
"""## ✅ Get Leaderboard
This function returns the leaderboard of all models trained in the current setup.
"""
# get leaderboard
lb = get_leaderboard()
lb
# select the best model based on F1
lb.sort_values(by='F1', ascending=False)['Model'].iloc[0]
"""Some other parameters that you might find very useful in `get_leaderboard` are:
- finalize_models
- fit_kwargs
- model_only
- groups
You can check the docstring of the function for more info.
"""
# help(get_leaderboard)
"""## ✅ AutoML
This function returns the best model out of all trained models in the current setup based on the optimize parameter. Metrics evaluated can be accessed using the `get_metrics` function.
"""
automl()
"""## ✅ Check Fairness
There are many approaches to conceptualizing fairness. The check_fairness function follows the approach known as group fairness, which asks: which groups of individuals are at risk for experiencing harm. `check_fairness` provides fairness-related metrics between different groups (also called sub-population).
"""
# check fairness
check_fairness(best, sensitive_features = ['Number of times pregnant'])
"""## ✅ Dashboard
The dashboard function generates the interactive dashboard for a trained model. The dashboard is implemented using `ExplainerDashboard`. For more information check out [Explainer Dashboard.](explainerdashboard.readthedocs.io)
"""
# dashboard function
dashboard(dt, display_format ='inline')
"""## ✅Create App
This function creates a basic gradio app for inference.
"""
# create gradio app
create_app(best)
"""## ✅ Create API
This function takes an input model and creates a POST API for inference.
"""
# create api
create_api(best, api_name = 'my_first_api')
# !python my_first_api.py
# check out the .py file created with this magic command
# %load my_first_api.py
"""## ✅ Create Docker
This function creates a `Dockerfile` and `requirements.txt` for productionalizing API end-point.
"""
create_docker('my_first_api')
# check out the DockerFile file created with this magic command
# %load DockerFile
# check out the requirements file created with this magic command
# %load requirements.txt
"""## ✅ Finalize Model
This function trains a given model on the entire dataset including the hold-out set.
"""
final_best = finalize_model(best)
final_best
"""## ✅ Convert Model
This function transpiles the trained machine learning model's decision function in different programming languages such as Python, C, Java, Go, C#, etc. It is very useful if you want to deploy models into environments where you can't install your normal Python stack to support model inference.
"""
# transpiles learned function to java
print(convert_model(best, language = 'java'))
"""## ✅ Deploy Model
This function deploys the entire ML pipeline on the cloud.
**AWS:** When deploying model on AWS S3, environment variables must be configured using the command-line interface. To configure AWS environment variables, type `aws configure` in terminal. The following information is required which can be generated using the Identity and Access Management (IAM) portal of your amazon console account:
- AWS Access Key ID
- AWS Secret Key Access
- Default Region Name (can be seen under Global settings on your AWS console)
- Default output format (must be left blank)
**GCP:** To deploy a model on Google Cloud Platform ('gcp'), the project must be created using the command-line or GCP console. Once the project is created, you must create a service account and download the service account key as a JSON file to set environment variables in your local environment. Learn more about it: https://cloud.google.com/docs/authentication/production
**Azure:** To deploy a model on Microsoft Azure ('azure'), environment variables for the connection string must be set in your local environment. Go to settings of storage account on Azure portal to access the connection string required.
AZURE_STORAGE_CONNECTION_STRING (required as environment variable)
Learn more about it: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python?toc=%2Fpython%2Fazure%2FTOC.json
"""
# deploy model on aws s3
# deploy_model(best, model_name = 'my_first_platform_on_aws',
# platform = 'aws', authentication = {'bucket' : 'pycaret-test'})
# load model from aws s3
# loaded_from_aws = load_model(model_name = 'my_first_platform_on_aws', platform = 'aws',
# authentication = {'bucket' : 'pycaret-test'})
# loaded_from_aws
"""## ✅ Save / Load Model
This function saves the transformation pipeline and a trained model object into the current working directory as a pickle file for later use.
"""
# save model
save_model(best, 'my_first_model')
# load model
loaded_from_disk = load_model('my_first_model')
loaded_from_disk
"""## ✅ Save / Load Experiment
This function saves all the experiment variables on disk, allowing to later resume without rerunning the setup function.
"""
# save experiment
save_experiment('my_experiment')
# load experiment from disk
exp_from_disk = load_experiment('my_experiment', data=data)