/** * Additional preprocessing transformers (sklearn-matching semantics, camelCase * props). Everything here follows the estimator contract * (docs/estimator-contract.md): props-object constructors, `getParams()`, * `registerEstimator()` next to each class, and JSON-serializable state. * * Numerical notes: * - Quantiles use linear interpolation, matching `numpy.percentile`'s default. * - The inverse standard-normal CDF is Peter John Acklam's rational * approximation (relative error < 1.15e-9); the normal CDF uses the * Abramowitz & Stegun 7.1.26 erf approximation (abs error < 1.5e-7). * - `PowerTransformer` estimates lambda per feature by maximum likelihood * with a coarse grid scan over [-5, 5] followed by golden-section * refinement (sklearn uses scipy's Brent on a (-2, 2) bracket; both find * the same unimodal optimum to ~1e-9 on well-behaved data). */ import { BaseEstimator, TransformerBase } from '../base'; import { Params } from '../base/estimator'; /** * Inverse standard-normal CDF (Peter John Acklam's approximation, * relative error < 1.15e-9 over the full domain). */ export declare function normPpf(p: number): number; /** Standard-normal CDF via the Abramowitz & Stegun 7.1.26 erf approximation. */ export declare function normCdf(x: number): number; export interface RobustScalerProps { withCentering?: boolean; withScaling?: boolean; /** Percentile pair (qMin, qMax), 0 <= qMin < qMax <= 100. Default IQR. */ quantileRange?: [number, number]; /** Scale so that normally-distributed features get unit variance. */ unitVariance?: boolean; } /** * Scale features using statistics that are robust to outliers: remove the * median and scale by the quantile range (IQR by default). NaN values are * ignored when computing the fit statistics and pass through `transform`. */ export declare class RobustScaler extends TransformerBase { private withCentering; private withScaling; private quantileRange; private unitVariance; private centers; private scales; private fitted; constructor(props?: RobustScalerProps); getParams(): Params; fit(X: number[][]): void; private assertFittedAndShape; transform(X: number[][]): number[][]; inverseTransform(X: number[][]): number[][]; } export interface PowerTransformerProps { method?: 'yeo-johnson' | 'box-cox'; /** Apply zero-mean, unit-variance normalization after the power transform. */ standardize?: boolean; } /** * Apply a power transform featurewise to make the data more Gaussian-like. * Lambda is estimated per feature by maximizing the (Box-Cox or Yeo-Johnson) * log-likelihood with a grid scan over [-5, 5] plus golden-section * refinement. NaN values are ignored during fit and pass through transform. */ export declare class PowerTransformer extends TransformerBase { private method; private standardize; private lambdas; private means; private scales; private fitted; constructor(props?: PowerTransformerProps); getParams(): Params; private applyPower; private applyPowerInverse; /** Negative log-likelihood of `lambda` for the observed column values. */ private negativeLogLikelihood; fit(X: number[][]): void; private assertFittedAndShape; transform(X: number[][]): number[][]; inverseTransform(X: number[][]): number[][]; } export interface QuantileTransformerProps { nQuantiles?: number; outputDistribution?: 'uniform' | 'normal'; /** Maximum number of samples used to estimate the quantiles. */ subsample?: number; randomState?: number; } /** * Transform features to follow a uniform or normal distribution using * quantile information. The effective number of quantiles is silently * clamped to the number of samples (sklearn warns; we clamp silently). * NaN values are ignored during fit and pass through transform. */ export declare class QuantileTransformer extends TransformerBase { private nQuantiles; private outputDistribution; private subsample; private randomState?; private references; private quantiles; private fitted; constructor(props?: QuantileTransformerProps); getParams(): Params; fit(X: number[][]): void; private assertFittedAndShape; transform(X: number[][]): number[][]; inverseTransform(X: number[][]): number[][]; } export interface PolynomialFeaturesProps { degree?: number; /** Only interaction terms (no powers of a single feature). */ interactionOnly?: boolean; includeBias?: boolean; } /** * Generate polynomial and interaction features with sklearn's column * ordering: degree-ascending, and within each degree the lexicographic * `itertools.combinations(_with_replacement)` order. */ export declare class PolynomialFeatures extends TransformerBase { private degree; private interactionOnly; private includeBias; private nInputFeatures; private combos; private fitted; constructor(props?: PolynomialFeaturesProps); getParams(): Params; fit(X: number[][]): void; transform(X: number[][]): number[][]; /** Output feature names, e.g. ['1', 'x0', 'x1', 'x0^2', 'x0 x1', 'x1^2']. */ getFeatureNamesOut(inputNames?: string[]): string[]; } export interface KBinsDiscretizerProps { nBins?: number; encode?: 'ordinal' | 'onehot-dense'; strategy?: 'uniform' | 'quantile' | 'kmeans'; } /** * Bin continuous data into intervals. Strategies: 'uniform' (equal-width), * 'quantile' (equal-frequency, linear-interpolation percentiles), 'kmeans' * (1-D Lloyd initialized at uniform bin midpoints, like sklearn). Bin indices * are clipped to [0, nBins-1]; degenerate edges (< 1e-8 apart) are merged for * the quantile/kmeans strategies as sklearn does. Constant features collapse * to a single bin whose edges are the constant value (sklearn uses * [-inf, inf]; using the value keeps `inverseTransform` well-defined). */ export declare class KBinsDiscretizer extends TransformerBase { private nBins; private encode; private strategy; private binEdges; private nBinsPerFeature; private fitted; constructor(props?: KBinsDiscretizerProps); getParams(): Params; fit(X: number[][]): void; private ordinalIndex; transform(X: number[][]): number[][]; /** Map ordinal bin indices back to bin centers. Only for encode='ordinal'. */ inverseTransform(X: number[][]): number[][]; } export interface KNNImputerProps { nNeighbors?: number; weights?: 'uniform' | 'distance'; metric?: 'nanEuclidean'; } /** * Impute missing values (NaN) from the k nearest neighbors measured with the * nan-Euclidean metric. For each missing entry the donors are the k nearest * fit samples that have that feature observed (fewer donors are fine, as in * sklearn); when no donor exists the column mean of the fit data is used. */ export declare class KNNImputer extends TransformerBase { private nNeighbors; private weights; private metric; private fitX; private statistics; /** indices of fit features that had at least one observed value */ private validFeatures; private nFeaturesIn; private fitted; constructor(props?: KNNImputerProps); getParams(): Params; fit(X: number[][]): void; transform(X: number[][]): number[][]; } export interface LabelBinarizerProps { negLabel?: number; posLabel?: number; } /** * Binarize 1-D labels in a one-vs-all fashion. With exactly two classes the * output is a single column (sklearn behavior); with more classes it is a * one-hot matrix. Operates on 1-D arrays, so it extends BaseEstimator * directly (like LabelEncoder). */ export declare class LabelBinarizer extends BaseEstimator { private negLabel; private posLabel; private classes; private fitted; constructor(props?: LabelBinarizerProps); getParams(): Params; fit(y: number[]): void; transform(y: number[]): number[][]; fitTransform(y: number[]): number[][]; inverseTransform(Y: number[][]): number[]; } export type ElementwiseFunc = (value: number) => number; export interface FunctionTransformerProps { /** * Elementwise function, or the string name of a built-in ('log1p', * 'expm1', 'identity'). Only string names are serializable; passing a raw * function makes `toJSON()` throw (documented codec behavior). */ func?: ElementwiseFunc | string; inverseFunc?: ElementwiseFunc | string; } /** * Apply a user-supplied elementwise function as a transformer. Stateless: * `fit` is a no-op. */ export declare class FunctionTransformer extends TransformerBase { private func; private inverseFunc; constructor(props?: FunctionTransformerProps); getParams(): Params; private resolve; fit(_X: number[][]): void; transform(X: number[][]): number[][]; inverseTransform(X: number[][]): number[][]; } export interface MissingIndicatorProps { /** 'missing-only': indicator columns only for features with missing values at fit. */ features?: 'missing-only' | 'all'; } /** * Binary (0/1) indicators for missing (NaN) values. With * features='missing-only' the output has one column per feature that * contained missing values during fit (sklearn's error_on_new check for new * missing features at transform time is not implemented). */ export declare class MissingIndicator extends TransformerBase { private features; private featureIndices; private nInputFeatures; private fitted; constructor(props?: MissingIndicatorProps); getParams(): Params; fit(X: number[][]): void; transform(X: number[][]): number[][]; }