xRFM: Scalable and interpretable kernel methods for tabular data
Project description
xRFM - Recursive Feature Machines optimized for tabular data
xRFM is a scalable implementation of Recursive Feature Machines (RFMs) optimized for tabular data. This library provides both the core RFM algorithm and a tree-based extension (xRFM) that enables efficient processing of large datasets through recursive data splitting.
Core Components
xRFM/
├── xrfm/
│ ├── xrfm.py # Main xRFM class (tree-based)
│ ├── tree_utils.py # Tree manipulation utilities
│ └── rfm_src/
│ ├── recursive_feature_machine.py # Base RFM class
│ ├── kernels.py # Kernel implementations
│ ├── eigenpro.py # EigenPro optimization
│ ├── utils.py # Utility functions
│ ├── svd.py # SVD operations
│ └── gpu_utils.py # GPU memory management
├── examples/ # Usage examples
└── setup.py # Package configuration
Installation
pip install xrfm
Development Installation
git clone https://github.com/dmbeaglehole/xRFM.git
cd xRFM
pip install -e .
Quick Start
Basic Usage
import torch
from xrfm import xRFM
from sklearn.model_selection import train_test_split
# Create synthetic data
def target_function(X):
return torch.cat([
(X[:, 0] > 0)[:, None],
(X[:, 1] < 0.5)[:, None]
], dim=1).float()
# Setup device and model
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = xRFM(device=device, tuning_metric='mse')
# Generate data
n_samples = 2000
n_features = 100
X = torch.randn(n_samples, n_features, device=device)
y = target_function(X)
X_trainval, X_test, y_trainval, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
X_train, X_val, y_train, y_val = train_test_split(X_trainval, y_trainval, test_size=0.2, random_state=0)
model.fit(X_train, y_train, X_val, y_val)
y_pred_test = model.predict(X_test)
Custom Configuration
# Custom RFM parameters
rfm_params = {
'model': {
'kernel': 'l2', # Kernel type
'bandwidth': 5.0, # Kernel bandwidth
'exponent': 1.0, # Kernel exponent
'diag': False, # Diagonal Mahalanobis matrix
'bandwidth_mode': 'constant'
},
'fit': {
'reg': 1e-3, # Regularization parameter
'iters': 5, # Number of iterations
'M_batch_size': 1000, # Batch size for AGOP
'verbose': True, # Verbose output
'early_stop_rfm': True # Early stopping
}
}
# Initialize model with custom parameters
model = xRFM(
rfm_params=rfm_params,
device=device,
min_subset_size=10000, # Minimum subset size for splitting
tuning_metric='accuracy', # Tuning metric
split_method='top_vector_agop_on_subset' # Splitting strategy
)
File Structure
Core Files
| File | Description |
|---|---|
xrfm/xrfm.py |
Main xRFM class implementing tree-based recursive splitting |
xrfm/rfm_src/recursive_feature_machine.py |
Base RFM class with core algorithm |
xrfm/rfm_src/kernels.py |
Kernel implementations (Laplace, Product Laplace, etc.) |
xrfm/rfm_src/eigenpro.py |
EigenPro optimization for large-scale training |
xrfm/rfm_src/utils.py |
Utility functions for matrix operations and metrics |
xrfm/rfm_src/svd.py |
SVD utilities for kernel computations |
xrfm/rfm_src/gpu_utils.py |
GPU memory management utilities |
xrfm/tree_utils.py |
Tree manipulation and parameter extraction utilities |
Example Files
| File | Description |
|---|---|
examples/test.py |
Simple regression example with synthetic data |
examples/covertype.py |
Forest cover type classification example |
API Reference
Main Classes
xRFM
Tree-based Recursive Feature Machine for scalable learning.
Constructor Parameters:
rfm_params(dict): Parameters for base RFM modelsmin_subset_size(int, default=60000): Minimum subset size for splittingmax_depth(int, default=None): Maximum tree depthdevice(str, default=None): Computing device ('cpu' or 'cuda')tuning_metric(str, default='mse'): Metric for model tuningsplit_method(str): Data splitting strategy
Key Methods:
fit(X, y, X_val, y_val): Train the modelpredict(X): Make predictionspredict_proba(X): Predict class probabilitiesscore(X, y): Evaluate model performance
RFM
Base Recursive Feature Machine implementation.
Constructor Parameters:
kernel(str or Kernel): Kernel type or kernel objectiters(int, default=5): Number of training iterationsbandwidth(float, default=10.0): Kernel bandwidthdevice(str, default=None): Computing devicetuning_metric(str, default='mse'): Evaluation metric
Available Kernels
| Kernel | String ID | Description |
|---|---|---|
LaplaceKernel |
'laplace', 'l2' |
Standard Laplace kernel |
LightLaplaceKernel |
'l2_high_dim', 'l2_light' |
Memory-efficient Laplace kernel |
ProductLaplaceKernel |
'product_laplace', 'l1' |
Product of Laplace kernels |
SumPowerLaplaceKernel |
'sum_power_laplace', 'l1_power' |
Sum of powered Laplace kernels |
Splitting Methods
| Method | Description |
|---|---|
'top_vector_agop_on_subset' |
Use top eigenvector of AGOP matrix |
'random_agop_on_subset' |
Use random eigenvector of AGOP matrix |
'top_pc_agop_on_subset' |
Use top principal component of AGOP |
'random_pca' |
Use vector sampled from Gaussian distribution with covariance $X^\top X$ |
'linear' |
Use linear regression coefficients |
'fixed_vector' |
Use fixed projection vector |
Tuning Metrics
| Metric | Description | Task Type |
|---|---|---|
'mse' |
Mean Squared Error | Regression |
'accuracy' |
Classification Accuracy | Classification |
'auc' |
Area Under ROC Curve | Classification |
'f1' |
F1 Score | Classification |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xrfm-0.3.0.tar.gz.
File metadata
- Download URL: xrfm-0.3.0.tar.gz
- Upload date:
- Size: 40.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f37ca5947871069bb1f4abe18843de76fa874b86f84b83d43b3f59f030f5072
|
|
| MD5 |
cda79d73ce4d090b33392525b37f2bce
|
|
| BLAKE2b-256 |
60bec23ca0b5e96a74b644b06288001e801e049f7621f8a6c31fe08d9170f848
|
File details
Details for the file xrfm-0.3.0-py3-none-any.whl.
File metadata
- Download URL: xrfm-0.3.0-py3-none-any.whl
- Upload date:
- Size: 43.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0faa5f9b7eaa03d74f5875f492a89eaecc02ec10e0060463aa139db2d459c09
|
|
| MD5 |
094aea1023951a09e451f16248ca8839
|
|
| BLAKE2b-256 |
6f4673fdb89aacf2a4ce2a1fefdcbaf6cdd47423e52ea8a794802e1fe376cd43
|