PyCaret Official
Searchโ€ฆ
Others
Other Functions in PyCaret

pull

Returns the last printed scoring grid. Use pull function after any training function to store the scoring grid in pandas.DataFrame.

Example

1
# loading dataset
2
from pycaret.datasets import get_data
3
data = get_data('diabetes')
4
โ€‹
5
# init setup
6
from pycaret.classification import *
7
clf1 = setup(data, target = 'Class variable')
8
โ€‹
9
# compare models
10
best_model = compare_models()
11
โ€‹
12
# get the scoring grid
13
results = pull()
Copied!
Output from pull()
1
type(results)
2
>>> pandas.core.frame.DataFrame
Copied!

models

Return a table containing all the models available in the imported module of the model library.

Example

1
# loading dataset
2
from pycaret.datasets import get_data
3
data = get_data('diabetes')
4
โ€‹
5
# init setup
6
from pycaret.classification import *
7
clf1 = setup(data, target = 'Class variable')
8
โ€‹
9
# check model library
10
models()
Copied!
Output from models()
If you want to see a little more information than this, you can pass internal=True.
1
# loading dataset
2
from pycaret.datasets import get_data
3
data = get_data('diabetes')
4
โ€‹
5
# init setup
6
from pycaret.classification import *
7
clf1 = setup(data, target = 'Class variable')
8
โ€‹
9
# check model library
10
models(internal = True)
Copied!
Output from models(internal = True)

get_config

This function retrieves the global variables created when initializing the setup function.

Example

1
# load dataset
2
from pycaret.datasets import get_data
3
data = get_data('diabetes')
4
โ€‹
5
# init setup
6
from pycaret.classification import *
7
clf1 = setup(data, target = 'Class variable')
8
โ€‹
9
# get X_train
10
get_config('X_train')
Copied!
Output from get_config('X_train')
Variables accessible by get_config function:
  • X: Transformed dataset (X)
  • y: Transformed dataset (y)
  • X_train: Transformed train dataset (X)
  • X_test: Transformed test/holdout dataset (X)
  • y_train: Transformed train dataset (y)
  • y_test: Transformed test/holdout dataset (y)
  • seed: random state set through session_id
  • prep_pipe: Transformation pipeline
  • fold_shuffle_param: shuffle parameter used in Kfolds
  • n_jobs_param: n_jobs parameter used in model training
  • html_param: html_param configured through setup
  • create_model_container: results grid storage container
  • master_model_container: model storage container
  • display_container: results display container
  • exp_name_log: Name of experiment
  • logging_param: log_experiment param
  • log_plots_param: log_plots param
  • USI: Unique session ID parameter
  • fix_imbalance_param: fix_imbalance param
  • fix_imbalance_method_param: fix_imbalance_method param
  • data_before_preprocess: data before preprocessing
  • target_param: name of target variable
  • gpu_param: use_gpu param configured through setup
  • fold_generator: CV splitter configured in fold_strategy
  • fold_param: fold params defined in the setup
  • fold_groups_param: fold groups defined in the setup
  • stratify_param: stratify parameter defined in the setup

set_config

This function resets the global variables.

Example

1
# load dataset
2
from pycaret.datasets import get_data
3
data = get_data('diabetes')
4
โ€‹
5
# init setup
6
from pycaret.classification import *
7
clf1 = setup(data, target = 'Class variable', session_id = 123)
8
โ€‹
9
# reset environment seed
10
set_config('seed', 999)
Copied!

get_metrics

Returns the table of all the available metrics in the metric container. All these metrics are used for cross-validation.
1
# load dataset
2
from pycaret.datasets import get_data
3
data = get_data('diabetes')
4
โ€‹
5
# init setup
6
from pycaret.classification import *
7
clf1 = setup(data, target = 'Class variable', session_id = 123)
8
โ€‹
9
# get metrics
10
get_metrics()
Copied!
Output from get_metrics()

add_metric

Adds a custom metric to the metric container.
1
# load dataset
2
from pycaret.datasets import get_data
3
data = get_data('diabetes')
4
โ€‹
5
# init setup
6
from pycaret.classification import *
7
clf1 = setup(data, target = 'Class variable', session_id = 123)
8
โ€‹
9
# add metric
10
from sklearn.metrics import log_loss
11
add_metric('logloss', 'Log Loss', log_loss, greater_is_better = False)
Copied!
Output from add_metric('logloss', 'Log Loss', log_loss, greater_is_better = False)
Now if you check metric container:
1
get_metrics()
Copied!
Output from get_metrics() (after adding log loss metric)

remove_metric

Removes a metric from the metric container.
1
# remove metric
2
remove_metric('logloss')
Copied!
No Output. Let's check the metric container again.
1
get_metrics()
Copied!
Output from get_metrics() (after removing log loss metric)

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.

Example

1
# load dataset
2
from pycaret.datasets import get_data
3
data = get_data('diabetes')
4
โ€‹
5
# init setup
6
from pycaret.classification import *
7
clf1 = setup(data, target = 'Class variable')
8
โ€‹
9
# compare models
10
top5 = compare_models(n_select = 5)
11
โ€‹
12
# tune models
13
tuned_top5 = [tune_model(i) for i in top5]
14
โ€‹
15
# ensemble models
16
bagged_top5 = [ensemble_model(i) for i in tuned_top5]
17
โ€‹
18
# blend models
19
blender = blend_models(estimator_list = top5)
20
โ€‹
21
# stack models
22
stacker = stack_models(estimator_list = top5)
23
โ€‹
24
# automl
25
best = automl(optimize = 'Recall')
26
print(best)
Copied!
Output from print(best)

get_logs

Returns a table of experiment logs. Only works when log_experiment = True when initializing the setup function.

Example

1
# load dataset
2
from pycaret.datasets import get_data
3
data = get_data('diabetes')
4
โ€‹
5
# init setup
6
from pycaret.classification import *
7
clf1 = setup(data, target = 'Class variable', log_experiment = True, experiment_name = 'diabetes1')
8
โ€‹
9
# compare models
10
top5 = compare_models()
11
โ€‹
12
# check ML logs
13
get_logs()
Copied!
Output from get_logs()

get_system_logs

Read and print logs.log file from current active directory.

Example

1
# loading dataset
2
from pycaret.datasets import get_data
3
data = get_data('diabetes')
4
โ€‹
5
# init setup
6
from pycaret.classification import *
7
clf1 = setup(data, target = 'Class variable', session_id = 123)
8
โ€‹
9
# check system logs
10
from pycaret.utils import get_system_logs
11
get_system_logs()
Copied!