Skip to content

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

data Scaling Source #

Population z-score, unit-range, or median/IQR feature scaling.

Instances

Instances details
Show Scaling Source # 
Instance details

Defined in HMath.MachineLearning.Preprocessing

Eq Scaling Source # 
Instance details

Defined in HMath.MachineLearning.Preprocessing

Methods

(==) :: Scaling -> Scaling -> Bool #

(/=) :: Scaling -> Scaling -> Bool #

Scaler

data Scaler Source #

Immutable training-feature centers and nonzero scales; constant columns use scale one.

Instances

Instances details
Show Scaler Source # 
Instance details

Defined in HMath.MachineLearning.Preprocessing

Eq Scaler Source # 
Instance details

Defined in HMath.MachineLearning.Preprocessing

Methods

(==) :: Scaler -> Scaler -> Bool #

(/=) :: Scaler -> Scaler -> Bool #

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.

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.

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.

Instances

Instances details
Show Imputation Source # 
Instance details

Defined in HMath.MachineLearning.Preprocessing

Eq Imputation Source # 
Instance details

Defined in HMath.MachineLearning.Preprocessing

Imputer

data Imputer Source #

Fitted replacement values; an imputer never learns from rows passed to impute.

Instances

Instances details
Show Imputer Source # 
Instance details

Defined in HMath.MachineLearning.Preprocessing

Eq Imputer Source # 
Instance details

Defined in HMath.MachineLearning.Preprocessing

Methods

(==) :: Imputer -> Imputer -> Bool #

(/=) :: Imputer -> Imputer -> Bool #

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

data Encoder a Source #

Sorted distinct training categories with stable zero-based integer codes.

Instances

Instances details
Show a => Show (Encoder a) Source # 
Instance details

Defined in HMath.MachineLearning.Preprocessing

Methods

showsPrec :: Int -> Encoder a -> ShowS #

show :: Encoder a -> String #

showList :: [Encoder a] -> ShowS #

Eq a => Eq (Encoder a) Source # 
Instance details

Defined in HMath.MachineLearning.Preprocessing

Methods

(==) :: Encoder a -> Encoder a -> Bool #

(/=) :: Encoder a -> Encoder a -> Bool #

UnknownCategory

data UnknownCategory Source #

Whether a previously unseen category fails or produces an all-zero one-hot row.

Constructors

RejectUnknown 
ZeroUnknown 

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

data Fold Source #

Disjoint indices into the original dataset. No estimator is fitted here.

Constructors

Fold 

Fields

Instances

Instances details
Show Fold Source # 
Instance details

Defined in HMath.MachineLearning.Preprocessing

Methods

showsPrec :: Int -> Fold -> ShowS #

show :: Fold -> String #

showList :: [Fold] -> ShowS #

Eq Fold Source # 
Instance details

Defined in HMath.MachineLearning.Preprocessing

Methods

(==) :: Fold -> Fold -> Bool #

(/=) :: Fold -> Fold -> Bool #

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.

randomSearch

randomSearch :: Word64 -> Int -> [p] -> [Fold] -> (p -> Fold -> Either MathError Double) -> Either MathError (p, Double) Source #

Sample count distinct candidates from a finite set, then evaluate the supplied folds. Lower loss wins.