HMath.MachineLearning.Preprocessing¶
Module index · Numerical conventions
Description
Fitted preprocessing and index-based splits. Fit on training rows before transforming validation/test rows. Unknown categories are rejected unless explicitly mapped to an all-zero vector. Sample quantiles interpolate between order statistics; constant features use scale one and transform to zero.
On this page¶
| API | Purpose |
|---|---|
| Scaling | Population z-score, unit-range, or median/IQR feature scaling. |
| Standardize | Declaration and type contract below. |
| MinMax | Declaration and type contract below. |
| RobustScale | Declaration and type contract below. |
| Scaler | Immutable training-feature centers and nonzero scales; constant columns use scale one. |
| fitScaler | Estimate one center and scale per training feature. |
| transform | Apply training centers/scales to rows with the original feature count; no state is updated. |
| inverseTransform | Undo a fitted affine scaler, including its constant-feature convention. |
| QuantileTransformer | Sorted training samples retained separately for each feature. |
| fitQuantileTransformer | Fit empirical feature quantiles using training rows only. |
| quantileTransform | Map values to [0,1]. |
| inverseQuantileTransform | Interpolate training order statistics at probabilities in [0,1]. |
| PowerTransform | Box-Cox or Yeo-Johnson with a caller-selected finite power lambda; lambda is not estimated. |
| BoxCox | Declaration and type contract below. |
| YeoJohnson | Declaration and type contract below. |
| powerTransform | Apply the selected power to features. |
| inversePowerTransform | Invert the selected power, rejecting values outside the transform range. |
| Imputation | Training-column mean, median, or a finite constant for NaN-valued observations. |
| MeanImpute | Declaration and type contract below. |
| MedianImpute | Declaration and type contract below. |
| ConstantImpute | Declaration and type contract below. |
| Imputer | Fitted replacement values; an imputer never learns from rows passed to impute. |
| fitImputer | Treat NaN as missing and reject infinities. |
| impute | Replace NaN with fitted training values while preserving observed entries and row order. |
| Encoder | Sorted distinct training categories with stable zero-based integer codes. |
| UnknownCategory | Whether a previously unseen category fails or produces an all-zero one-hot row. |
| RejectUnknown | Declaration and type contract below. |
| ZeroUnknown | Declaration and type contract below. |
| fitEncoder | Learn sorted category levels from a nonempty training label vector. |
| labelEncode | Map known categories to zero-based codes; unseen categories fail. |
| labelDecode | Recover categories from checked integer codes. |
| oneHotEncode | Emit one column per sorted training category under the explicit unknown-category policy. |
| Fold | Disjoint indices into the original dataset. |
| Fold | Declaration and type contract below. |
| trainingIndices | Zero-based original row indices assigned to training in this fold. |
| validationIndices | Zero-based original row indices held out for validation in this fold. |
| trainTestSplit | Seeded split of n row indices. |
| kFold | Partition n shuffled indices into k nonempty validation folds; each row is held out exactly once. |
| stratifiedKFold | Round-robin each shuffled class across k folds. |
| gridSearch | Minimize a user-supplied validation loss, evaluated independently for every candidate/fold. |
| randomSearch | Sample count distinct candidates from a finite set, then evaluate the supplied folds. |
Documentation
Scaling
Population z-score, unit-range, or median/IQR feature scaling.
Constructors
| Standardize | |
| MinMax | |
| RobustScale |
Scaler
Immutable training-feature centers and nonzero scales; constant columns use scale one.
fitScaler
fitScaler :: Scaling -> Dataset -> Either MathError Scaler Source #
Estimate one center and scale per training feature. Empty/ragged or nonfinite data fail.
transform
transform :: Scaler -> Dataset -> Either MathError Dataset Source #
Apply training centers/scales to rows with the original feature count; no state is updated.
inverseTransform
inverseTransform :: Scaler -> Dataset -> Either MathError Dataset Source #
Undo a fitted affine scaler, including its constant-feature convention.
QuantileTransformer
data QuantileTransformer Source #
Sorted training samples retained separately for each feature.
Instances
| Show QuantileTransformer Source # | |
Defined in HMath.MachineLearning.Preprocessing Methods showsPrec :: Int -> QuantileTransformer -> ShowS # show :: QuantileTransformer -> String # showList :: [QuantileTransformer] -> ShowS # | |
| Eq QuantileTransformer Source # | |
Defined in HMath.MachineLearning.Preprocessing Methods (==) :: QuantileTransformer -> QuantileTransformer -> Bool # (/=) :: QuantileTransformer -> QuantileTransformer -> Bool # | |
fitQuantileTransformer
fitQuantileTransformer :: Dataset -> Either MathError QuantileTransformer Source #
Fit empirical feature quantiles using training rows only.
quantileTransform
quantileTransform :: QuantileTransformer -> Dataset -> Either MathError Dataset Source #
Map values to [0,1]. Ties use their average rank and values outside training extrema clamp.
inverseQuantileTransform
inverseQuantileTransform :: QuantileTransformer -> Dataset -> Either MathError Dataset Source #
Interpolate training order statistics at probabilities in [0,1].
PowerTransform
data PowerTransform Source #
Box-Cox or Yeo-Johnson with a caller-selected finite power lambda; lambda is not estimated.
Constructors
| BoxCox Double | |
| YeoJohnson Double |
Instances
| Show PowerTransform Source # | |
Defined in HMath.MachineLearning.Preprocessing Methods showsPrec :: Int -> PowerTransform -> ShowS # show :: PowerTransform -> String # showList :: [PowerTransform] -> ShowS # | |
| Eq PowerTransform Source # | |
Defined in HMath.MachineLearning.Preprocessing Methods (==) :: PowerTransform -> PowerTransform -> Bool # (/=) :: PowerTransform -> PowerTransform -> Bool # | |
powerTransform
powerTransform :: PowerTransform -> Dataset -> Either MathError Dataset Source #
Apply the selected power to features. Box-Cox requires positive values; Yeo-Johnson allows signs.
inversePowerTransform
inversePowerTransform :: PowerTransform -> Dataset -> Either MathError Dataset Source #
Invert the selected power, rejecting values outside the transform range.
Imputation
data Imputation Source #
Training-column mean, median, or a finite constant for NaN-valued observations.
Constructors
| MeanImpute | |
| MedianImpute | |
| ConstantImpute Double |
Instances
| Show Imputation Source # | |
Defined in HMath.MachineLearning.Preprocessing Methods showsPrec :: Int -> Imputation -> ShowS # show :: Imputation -> String # showList :: [Imputation] -> ShowS # | |
| Eq Imputation Source # | |
Defined in HMath.MachineLearning.Preprocessing | |
Imputer
Fitted replacement values; an imputer never learns from rows passed to impute.
fitImputer
fitImputer :: Imputation -> Dataset -> Either MathError Imputer Source #
Treat NaN as missing and reject infinities. All-missing columns require ConstantImpute.
impute
impute :: Imputer -> Dataset -> Either MathError Dataset Source #
Replace NaN with fitted training values while preserving observed entries and row order.
Encoder
Sorted distinct training categories with stable zero-based integer codes.
UnknownCategory
data UnknownCategory Source #
Whether a previously unseen category fails or produces an all-zero one-hot row.
Constructors
| RejectUnknown | |
| ZeroUnknown |
Instances
| Show UnknownCategory Source # | |
Defined in HMath.MachineLearning.Preprocessing Methods showsPrec :: Int -> UnknownCategory -> ShowS # show :: UnknownCategory -> String # showList :: [UnknownCategory] -> ShowS # | |
| Eq UnknownCategory Source # | |
Defined in HMath.MachineLearning.Preprocessing Methods (==) :: UnknownCategory -> UnknownCategory -> Bool # (/=) :: UnknownCategory -> UnknownCategory -> Bool # | |
fitEncoder
fitEncoder :: Ord a => [a] -> Either MathError (Encoder a) Source #
Learn sorted category levels from a nonempty training label vector.
labelEncode
labelEncode :: Eq a => Encoder a -> [a] -> Either MathError [Int] Source #
Map known categories to zero-based codes; unseen categories fail.
labelDecode
labelDecode :: Encoder a -> [Int] -> Either MathError [a] Source #
Recover categories from checked integer codes.
oneHotEncode
oneHotEncode :: Eq a => UnknownCategory -> Encoder a -> [a] -> Either MathError Dataset Source #
Emit one column per sorted training category under the explicit unknown-category policy.
Fold
Disjoint indices into the original dataset. No estimator is fitted here.
Constructors
| Fold | |
Fields
| |
Instances
trainTestSplit
trainTestSplit :: Word64 -> Double -> Int -> Either MathError Fold Source #
Seeded split of n row indices. The fraction denotes test rows, rounded and clamped to [1,n-1].
kFold
kFold :: Word64 -> Int -> Int -> Either MathError [Fold] Source #
Partition n shuffled indices into k nonempty validation folds; each row is held out exactly once.
stratifiedKFold
stratifiedKFold :: Ord a => Word64 -> Int -> [a] -> Either MathError [Fold] Source #
Round-robin each shuffled class across k folds. Every class needs at least k observations.
gridSearch
gridSearch :: [p] -> [Fold] -> (p -> Fold -> Either MathError Double) -> Either MathError (p, Double) Source #
Minimize a user-supplied validation loss, evaluated independently for every candidate/fold. The callback receives only the split indices, so it can fit preprocessing/model state inside each fold. Ties preserve candidate order.