PyCaret is a Python library that simplifies machine-learning workflows through consistent, low-code wrappers for preprocessing, feature engineering, modeling, clustering, time-series analysis, and outlier detection. It is especially useful for quickly preparing tabular data and comparing or assembling models. section 7.3
For outlier detection, PyCaret wraps a subset of PyOD detectors with a consistent interface. A typical workflow calls setup(), create_model(), and predict_model(); the resulting dataframe adds Anomaly and Anomaly Score columns. Binary labels are derived from detector scores using the selected contamination level. section 7.3
The setup() stage supplies much of PyCaret’s practical value:
- Generate polynomial and interaction features, including squared features, to expose differences that original variables may hide. section 7.3
- Create grouped feature sets while retaining the original variables. section 7.3
- Remove detected outliers through a setup option when that workflow is appropriate. section 7.3
- Integrate with MLFlow and support autoML and ensemble-building workflows. section 7.3
KNN anomaly detection
Install PyCaret, load or create test data, initialize anomaly detection with setup(data=df), create a KNN model with create_model('knn'), and score rows using predict_model(model=knn, data=df).
