XClassifier
XClassifier provides transparent binary classification with real-time explainability. Unlike black-box models, you get instant insights into how predictions are made without needing surrogate models.
Overview
The XClassifier is xplainable's flagship transparent classification model. It uses a novel feature-wise ensemble approach where each feature gets its own decision tree, optimized for maximum information gain while maintaining complete interpretability.
Key Features
Inspect any prediction with one call. No surrogate fits, no Shapley sampling.
Update a single feature's tree in milliseconds — no full retrain required.
Granular control per input. Drop, refit or constrain any feature independently.
Built-in probability mapping ensures your scores mean what you think they mean.
Quick Start
Constructor Parameters
8max_depth=120.00010.0001110False1.0TrueMethods
fit()
Fits the model to the training data.
[]None'target'0.1Returns the fitted XClassifier instance.
predict()
Predicts the target class for each row.
False0.5TrueReturns a numpy array of predicted class labels.
predict_score()
Returns the raw model score (float between 0 and 1) for each row. This is the sum of feature contributions plus the base value.
Returns a 1-D numpy array of scores.
predict_proba()
Returns calibrated probabilities for each row. Requires map_calibration=True (the default) during model construction.
Returns a 1-D numpy array of probabilities (not a 2-D array like scikit-learn).
evaluate()
Returns a dictionary of classification metrics.
The returned dictionary contains:
confusion_matrix-- nested listclassification_report-- dict (same format assklearn.metrics.classification_report(..., output_dict=True))roc_aucneg_brier_loss(1 - brier_score_loss)log_losscohen_kappa
explain()
Renders an interactive Altair chart showing feature importances and per-feature contribution profiles. Takes no data input -- it visualises the fitted model's internal profile.
Requires the altair package. Install with pip install xplainable[plotting].
update_feature_params()
Updates model parameters for a subset of features without retraining from scratch. This is extremely fast because the model has already pre-computed the metadata needed for reconstruction.
All parameter arguments are optional -- only the ones you pass will be updated. If map_calibration=True was used and you pass x and y, the probability calibration map is also recalculated.
Returns the updated XClassifier instance.
- 10-100x faster than complete retraining
- Feature-specific updates for granular control
- Real-time parameter tuning in production
predict_explain()
Returns a DataFrame containing per-feature contributions, the base value, the total score, calibrated probability, and support for each row.
feature_importances (property)
Returns a dictionary mapping feature names to their normalised importance scores (based on Gini gain).
profile (property)
Returns the full model profile as a dictionary with keys 'base_value', 'numeric', and 'categorical'. Each feature maps to a list of leaf nodes with their score, mean, and frequency.
_transform()
Transforms input data into per-feature contribution scores. Primarily for internal use but useful for debugging.
Partitioned Classification
For datasets with natural segments, use PartitionedClassifier:
PartitionedClassifier provides the same predict(), predict_score(), predict_proba(), and explain() methods, automatically routing each observation to its segment's model.
Hyperparameter Optimization
Use XParamOptimiser for Bayesian hyperparameter search (classification only).
Supported Metrics
'roc-auc' (default), 'macro-f1', 'weighted-f1', 'positive-f1', 'negative-f1', 'macro-precision', 'weighted-precision', 'positive-precision', 'negative-precision', 'macro-recall', 'weighted-recall', 'positive-recall', 'negative-recall', 'accuracy', 'brier-loss', 'log-loss'
Customising the Search Space
You can fix any parameter to a single value or provide a search range as a 3-element list [start, stop, step]:
To fix a parameter instead of searching, pass a scalar value instead of a list:
Evaluation with sklearn
Since predict_proba() returns a 1-D array, use it directly with sklearn metrics:
Or use the built-in evaluate() method:
Cloud Deployment
For deploying models to the Xplainable Cloud platform, see the REST API documentation.
Best Practices
Data Preparation
- Handle missing values appropriately (set
ignore_nan=Trueif you want the model to skip NaNs during training) - Encode categorical variables using a preprocessing pipeline before training
- Remove ID columns by passing them via
id_columnsparameter infit() - Remove highly correlated features for better interpretability
Recommended Starting Configuration
Troubleshooting
Model not fitting properly
Possible causes:
- Insufficient data for the complexity
- Highly imbalanced classes
- Poor feature quality
Solutions:
- Reduce
max_depthor increasemin_leaf_size - Use class weights or resampling
- Improve feature engineering
Poor probability calibration
Solutions:
- Ensure
map_calibration=True - Use larger training dataset
- Consider probability calibration post-processing
Slow training performance
Solutions:
- Reduce
max_depthparameter - Increase
min_info_gainthreshold - Use feature selection to reduce dimensionality
Next Steps
- Explore regression models for continuous targets
- Learn about preprocessing pipelines for data preparation
- REST API — Deploy and manage models via the API