Docs
Search
⌃K

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()
Output from pull()
1
type(results)
2
# >>> pandas.core.frame.DataFrame

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()
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)
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')
Output from get_config('X_train')
To check all accessible parameters with get_config:
1
# check all available param
2
get_config()
Variables accessible by get_config function:
  • 'USI'
  • 'X'
  • 'X_test'
  • 'X_test_transformed'
  • 'X_train'
  • 'X_train_transformed'
  • 'X_transformed'
  • 'data'
  • 'dataset'
  • 'dataset_transformed'
  • 'exp_id'
  • 'exp_name_log'
  • 'fix_imbalance'
  • 'fold_generator'
  • 'fold_groups_param'
  • 'fold_shuffle_param'
  • 'gpu_n_jobs_param'
  • 'gpu_param'
  • 'html_param'
  • 'idx'
  • 'is_multiclass'
  • 'log_plots_param'
  • 'logging_param'
  • 'memory'
  • 'n_jobs_param'
  • 'pipeline'
  • 'seed'
  • 'target_param'
  • 'test'
  • 'test_transformed'
  • 'train'
  • 'train_transformed'
  • 'variable_and_property_keys'
  • 'variables'
  • 'y'
  • 'y_test'
  • 'y_test_transformed'
  • 'y_train'
  • 'y_train_transformed'
  • 'y_transformed'

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)

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()
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)
Output from add_metric('logloss', 'Log Loss', log_loss, greater_is_better = False)
Now if you check metric container:
1
get_metrics()
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')
No Output. Let's check the metric container again.
1
get_metrics()
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)
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()
Output from get_logs()

get_current_experiment

Obtain the current experiment object and return a class. This is useful when you are using a functional API and want to move to an OOP API.
1
# loading dataset
2
from pycaret.datasets import get_data
3
data = get_data('insurance')
4
5
# init setup using functional API
6
from pycaret.regression import *
7
s = setup(data, target = 'charges', session_id = 123)
8
9
# compare models
10
best = compare_models()
11
12
# return OOP class for current functional experiment
13
reg1 = get_current_experiment()

set_current_experiment

Set the current experiment created using the OOP API to be used with the functional API.
1
# loading dataset
2
from pycaret.datasets import get_data
3
data = get_data('insurance')
4
5
# init setup using OOP API
6
from pycaret.regression import RegressionExperiment
7
reg1 = RegressionExperiment()
8
reg1.setup(data, target = 'charges', session_id = 123)
9
10
# compare models
11
best = compare_models()
12
13
# set OOP experiment as functional
14
set_current_experiment(reg1)