Home
Omar Hosney
PyCaret Cheat Sheet
Setup and Installation 🛠️
- Install PyCaret: Use
pip install pycaret to get started.
- Dependencies: Ensure all required packages are installed.
Data Preprocessing 📊
- Preprocess data: Utilize PyCaret's preprocessing functions for cleaning data.
- Handle missing values: Automatically impute missing values in your dataset using
setup(data, target='target_column').
- Encoding categorical data: Convert categorical columns to numeric using
setup(data, target='target_column', categorical_features=['col1', 'col2']).
Classification 📂
- Model setup: Initialize your classification model with
setup(data, target='target_column').
- Compare models: Use
best_model = compare_models() to find the best classifier.
- Create model: Build a specific model with
model = create_model('lr') for logistic regression.
- Tune model: Optimize model hyperparameters using
tuned_model = tune_model(model).
Regression 📈
- Model setup: Initialize regression with
setup(data, target='target_column').
- Compare models: Evaluate different regressors using
best_model = compare_models().
- Create model: Build a regression model with
model = create_model('lr') for linear regression.
- Tune model: Optimize model parameters with
tuned_model = tune_model(model).
Time Series ⏳
- Setup: Start with
setup(data, target='target_column', fold=3, session_id=123) for time series analysis.
- Create model: Use
model = create_model('ets') to create an exponential smoothing model.
- Forecasting: Generate forecasts with
predict_model(model, fh=10).
Clustering 🗃️
- Model setup: Prepare data for clustering with
setup(data).
- Create model: Build a clustering model with
model = create_model('kmeans').
- Evaluate clusters: Analyze cluster quality with
evaluate_model(model).
Anomaly Detection 🚨
- Setup: Initialize anomaly detection with
setup(data).
- Detect anomalies: Identify outliers using
model = create_model('iforest').
- Plot anomalies: Visualize anomalies with
plot_model(model, plot='tsne').
Model Training 🤖
- Train model: Fit your model with
model = create_model('lr').
- Tune model: Improve performance with
tuned_model = tune_model(model).
- Ensemble model: Combine models using
ensemble_model = ensemble_model(model).
Model Evaluation 📉
- Evaluate model: Use
evaluate_model(model) to assess performance.
- Interpret results: Understand model outcomes with
interpret_model(model).
- Plot model: Visualize model performance with
plot_model(model, plot='auc').
Prediction and Deployment 🚀
- Make predictions: Generate predictions with
predictions = predict_model(model, data=new_data).
- Deploy model: Deploy your model using
deploy_model(model, model_name='my_model').
- Save model: Save the trained model with
save_model(model, 'model_name').
- Load model: Load a saved model with
loaded_model = load_model('model_name').
Advanced Features 🌟
- Pipeline creation: Create pipelines for complex workflows using
from pycaret.datasets import get_data and from pycaret.classification import *.
- Custom metrics: Define and use custom metrics for evaluation with
add_metric('metric_name', 'Metric Display Name', custom_function).
- Automated ML: Leverage AutoML with PyCaret by using
best_model = automl().