featrs
Feature engineering library for Rust, inspired by scikit-learn.
Built on Polars — all transformations operate natively on DataFrame and preserve column names.
Installation
[]
= "0.3"
Quick start
use *;
let mut scaler = new;
scaler.fit?;
let scaled = scaler.transform?;
Features
| Category | Component | Description |
|---|---|---|
| Scaling | StandardScaler |
Z-score normalization (mean 0, variance 1) |
MinMaxScaler |
Scale to [0, 1] or custom range |
|
RobustScaler |
Scale using median and IQR (outlier-robust) | |
| Normalization | Normalizer |
Row-wise L1, L2, or Max normalization |
Binarizer |
Threshold-based binarization | |
| Encoding | OneHotEncoder |
Create binary dummy columns for categories |
LabelEncoder |
Encode labels as 0..n_classes-1 integers |
|
OrdinalEncoder |
Per-column category → integer encoding | |
CyclicalEncoder |
Sin/cos encoding for cyclical features (hour, month) | |
FeatureHasher |
Hash strings into a fixed number of buckets | |
| Imputation | SimpleImputer |
Fill nulls with mean, median, mode, or constant |
MissingIndicator |
Binary columns marking where values were missing | |
| Feature Generation | PolynomialFeatures |
Generate polynomial and interaction features |
Lagger |
Create lag features for time-series forecasting | |
RollingAggregator |
Rolling window mean, std, min, max, sum | |
Difference |
Differencing (x[t] - x[t-1]) and percentage change |
|
| Pipeline | Pipeline |
Sequentially chain multiple transformers |
ColumnTransformer |
Apply different transformers to different columns | |
| Selection | VarianceThreshold |
Remove low-variance features |
SelectKBest |
Select top-k features by statistical test (ANOVA F) | |
| Auto | AutoTypeDetector |
Auto-detect column types and apply default transforms |
Examples
StandardScaler
use *;
let mut scaler = new;
scaler.fit?;
let scaled = scaler.transform?;
Pipeline
use *;
let mut pipeline = new?;
pipeline.fit?;
let result = pipeline.transform?;
ColumnTransformer
use *;
let ct = new;
PolynomialFeatures (builder pattern)
use *;
let pf = builder
.degree
.include_bias
.interaction_only
.build?;
Feature Selection
use *;
let mut vt = new;
vt.fit?;
let filtered = vt.transform?;
let mut skb = new;
skb.fit?;
let selected = skb.transform?;
Time Series — Lag Features
use *;
let mut lagger = new;
lagger.fit?;
let lagged = lagger.transform?; // adds sales_lag_1, sales_lag_7, ...
Time Series — Rolling Windows
use *;
use RollingFn;
let mut rolling = new;
rolling.fit?;
let result = rolling.transform?; // adds price_mean_7
Time Series — Differencing
use *;
let mut diff = diff;
diff.fit?;
let result = diff.transform?; // adds sales_diff_1
let mut pct = pct_change;
pct.fit?;
let result = pct.transform?; // adds price_pct_1
Cyclical Encoding
use *;
let mut enc = new;
enc.fit?;
let result = enc.transform?; // adds hour_sin, hour_cos
Feature Hasher
use *;
let mut fh = new;
fh.fit?;
let hashed = fh.transform?; // 100 hashed columns
Missing Indicator
use *;
let mut ind = all;
ind.fit?;
let marked = ind.transform?; // adds {col}_missing where nulls exist
Auto-Type Detection
use *;
let mut atd = new
.cat_threshold // one-hot if < 30 unique values
.hash_buckets; // hash to 200 buckets otherwise
atd.fit?;
let result = atd.transform?;
Resources
Star History
License
MIT