PyCaret Explained: The Low-Code Machine Learning Package That Trains 20+ Models in 3 Lines
BrainyTools Editor
Tech Contributor at BrainyTools

How citizen data scientists, students, and analysts bridge the gap between no-code tools and Python without memorizing complex library syntax.
When non-technical professionals or students decide to peek beyond drag-and-drop apps and try Python for machine learning, they usually run into a frustrating wall. In standard machine learning libraries like scikit-learn, training and comparing five different models requires writing 100+ lines of boilerplate code: manually filling missing values, one-hot encoding text categories, scaling numbers, splitting train/test sets, importing five separate algorithm classes, and writing loops to compute evaluation metrics.
PyCaret (created by Moez Ali) was designed specifically to eliminate that complexity. It is an open-source, low-code machine learning package that wraps scikit-learn, XGBoost, LightGBM, CatBoost, and Optuna behind plain-English commands.
If you can copy and paste three short lines into a free Google Colab notebook—or even integrate PyCaret inside Power BI—you can automatically clean a spreadsheet, train more than 20 machine learning algorithms, and rank them on a color-coded leaderboard in under a minute.
Why PyCaret Is Built for "Citizen Data Scientists"
A Citizen Data Scientist is someone whose primary job is outside software engineering—such as a financial analyst, healthcare researcher, marketing manager, or university student—who uses data to make decisions.
PyCaret caters to this audience by automating the tedious 80% of machine learning:
- Automated Data Preprocessing (
setup): When you hand PyCaret a raw spreadsheet, it automatically detects which columns are numbers, text categories, or dates; fills in missing values; converts text categories into numbers; and splits your data into training and testing sets. - Instant Model Tournament (
compare_models): Instead of guessing whether a Decision Tree, Random Forest, or Logistic Regression is best for your data, one command trains 20+ algorithms using 10-fold cross-validation and highlights the winner in yellow. - One-Word Visual Plots (
plot_model): Generate feature importance charts, confusion matrices, or error plots with a single command.
The Entire 3-Line Machine Learning Workflow
Let us look at a complete, working example. Suppose you have a CSV spreadsheet called customers.csv and you want to predict the column Purchased (Yes or No).
Whether you run this in a free Google Colab browser tab (which requires zero installation on your computer) or locally, here is the entire script:
# Install once in Google Colab: !pip install pycaret
import pandas as pd
from pycaret.classification import setup, compare_models, evaluate_model
# Load your spreadsheet
data = pd.read_csv("customers.csv")
# Line 1: Automatically clean, encode, and split the dataset
s = setup(data, target="Purchased", session_id=123)
# Line 2: Train and compare 20+ machine learning models automatically
best_model = compare_models()
# Line 3: Open an interactive point-and-click dashboard to inspect charts
evaluate_model(best_model)
That is it—no math formulas, no manual for loops, and no complex data transformations.
What Happens at Each Step?
[1. setup()] ──────────► [2. compare_models()] ──────────► [3. tune_model() / predict_model()]
• Imputes missing rows • Trains 20+ ML algorithms • Optimizes top model accuracy
• Encodes categories • Runs 10-fold cross-validation • Scores new unseen spreadsheets
• Splits Train / Test • Highlights top metrics in table
Step 1: setup() — Your Automated Data Assistant
When setup(data, target="Purchased") runs, PyCaret prints an interactive summary table showing you:
- How many rows and columns were detected.
- How it handled missing values (by default, replacing missing numbers with the mean and missing text with the mode). If you want to understand how mean, median, mode, and standard deviation behave on your raw numbers before modeling, you can test a sample column in our Statistics Calculator and Standard Deviation Calculator.
Step 2: compare_models() — The Algorithm Leaderboard
Seconds after running compare_models(), PyCaret outputs a clean leaderboard table sorted by accuracy (or any metric you choose):
| Model | Accuracy | AUC | Recall | Prec. | F1 | TT (Sec) |
|---|---|---|---|---|---|---|
Light Gradient Boosting (lightgbm) |
0.8740 | 0.9210 | 0.8150 | 0.8420 | 0.8283 | 0.18 |
Random Forest Classifier (rf) |
0.8690 | 0.9140 | 0.8010 | 0.8390 | 0.8195 | 0.42 |
Extra Trees Classifier (et) |
0.8610 | 0.9050 | 0.7950 | 0.8280 | 0.8111 | 0.35 |
Logistic Regression (lr) |
0.8240 | 0.8710 | 0.7420 | 0.7810 | 0.7610 | 0.08 |
Decision Tree Classifier (dt) |
0.7980 | 0.7850 | 0.7310 | 0.7400 | 0.7354 | 0.04 |
The best score in every column is automatically highlighted in yellow, and the variable best_model now holds the winning trained algorithm.
Step 3: evaluate_model() — Point-and-Click Visual Diagnostics
When you run evaluate_model(best_model) inside a notebook, PyCaret displays an row of clickable buttons (Feature Importance, Confusion Matrix, AUC, Decision Boundary, Prediction Error). Clicking any button renders the chart immediately—letting you visually see which spreadsheet columns had the biggest impact on the AI's decisions.
Modules Available in PyCaret
PyCaret uses the exact same 3-line pattern across five different types of data problems:
pycaret.classification: Predict categories (Yes/No,Spam/Not Spam,Plan A/B/C).pycaret.regression: Predict continuous numbers (House Price,Monthly Sales,Energy Usage).pycaret.clustering: Group similar customers or items automatically when you have no target labels.pycaret.anomaly: Spot unusual transactions, sensor spikes, or potential fraud in a spreadsheet.pycaret.time_series: Forecast future daily, weekly, or monthly trends from historical dates.
Conclusion
If you have ever wanted the power and flexibility of Python's machine learning ecosystem without spending months studying programming syntax, PyCaret is the ideal bridge. With just three readable commands, you can benchmark over 20 industry-standard algorithms on your own datasets and make data-driven predictions with confidence.