Skip to content

Instantly share code, notes, and snippets.

FROM python:3.7-slim
WORKDIR /app
ADD . /app
RUN apt-get update && apt-get install -y libgomp1
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# import classification module
from pycaret.classification import *
# init setup
clf1 = setup(data, target = 'name-of-target')
# train logistic regression model
lr = create_model('lr') #lr is the id of the model
# check the model library to see all models
# select and finalize the best model in the active run
best_model = automl() #returns the best model based on CV score
# select and finalize the best model based on 'F1' on hold_out set
best_model_holdout = automl(optimize = 'F1', use_holdout = True)
# save model
save_model(model, 'c:/path-to-directory/model-name')
# load model
# import libraries
import pandas as pd
import sys
# define command line parameters
data = sys.argv[1]
target = sys.argv[2]
# load data (replace this part with your own script)
from pycaret.datasets import get_data
# import classification module
from pycaret.classification import *
# init setup
clf1 = setup(data, target = 'name-of-target', log_experiment = True, experiment_name = 'exp-name-here')
# compare models
best = compare_models()
# start mlflow server on localhost:5000 (when using notebook)
# import classification module
from pycaret.classification import *
# init setup
clf1 = setup(data, target = 'name-of-target')
# train a decision tree model
dt = create_model('dt')
# tune hyperparameters of decision tree
# Import module
from pycaret.classification import *
# Initialize setup (when using Notebook environment)
clf1 = setup(data, target = 'target-variable')
# Initialize setup (outside of Notebook environment)
clf1 = setup(data, target = 'target-variable', html = False)
# Initialize setup (When using remote execution such as Kaggle / GitHub actions / CI-CD pipelines)
# train a catboost model
catboost = create_model('catboost')
# predict on holdout set (when no data is passed)
pred_holdout = predict_model(catboost)
# predict on new dataset
new_data = pd.read_csv('new-data.csv')
pred_new = predict_model(catboost, data = new_data)
predict_model(xgboost, probability_threshold=0.2)
tuned_lda = tune_model(model='lda', supervised_target='status', estimator='xgboost')