/** * Stacked generalization meta-estimators, mirroring sklearn's * `StackingClassifier` and `StackingRegressor`. * * The final estimator is trained on OUT-OF-FOLD predictions of the base * estimators: the data is split with (Stratified)KFold, each base estimator * is `clone()`d per fold, fit on the fold's training part, and its * predictions on the held-out part fill that fold's rows of the meta-feature * matrix. The base estimators themselves are then refit on the full data and * used to build meta-features at inference time. */ import { ClassifierBase, RegressorBase } from '../base'; import { BaseEstimator, Params } from '../base/estimator'; import { ClassifierLike, RegressorLike, NamedEstimator } from './voting'; export type StackMethod = 'auto' | 'predictProba' | 'decisionFunction' | 'predict'; export interface StackingClassifierProps { /** Named base estimators; addressable as `name__param` in setParams. */ estimators: NamedEstimator[]; /** * Meta-estimator fit on the out-of-fold meta-features. Defaults to * `LogisticRegression()` (binary-only in this library — pass a * multiclass-capable classifier for >2 classes). Addressable as * `finalEstimator__param`. */ finalEstimator?: ClassifierLike; /** StratifiedKFold split count for the out-of-fold predictions. */ cv?: number; /** How base estimators produce meta-features (see resolveStackMethod). */ stackMethod?: StackMethod; /** Append the original features after the meta-features. */ passthrough?: boolean; } export declare class StackingClassifier extends ClassifierBase { private estimators; private finalEstimator; private cv; private stackMethod; private passthrough; private classes; private resolvedMethods; private fitted; constructor(props: StackingClassifierProps); getParams(): Params; /** Supports own params plus `name__param` / `finalEstimator__param`. */ setParams(params: Params): this; getEstimator(name: string): BaseEstimator; get namedEstimators(): Record; getClasses(): number[]; fit(X: number[][], y: number[], sampleWeight?: number[]): void; /** Meta-features for X from the full-data base estimators. */ transform(X: number[][]): number[][]; predict(X: number[][]): number[]; predictProba(X: number[][]): number[][]; decisionFunction(X: number[][]): number[] | number[][]; private assertFitted; } export interface StackingRegressorProps { /** Named base estimators; addressable as `name__param` in setParams. */ estimators: NamedEstimator[]; /** * Meta-estimator fit on the out-of-fold predictions. Defaults to * `RidgeRegression()`. Addressable as `finalEstimator__param`. */ finalEstimator?: RegressorLike; /** KFold split count for the out-of-fold predictions. */ cv?: number; /** Append the original features after the meta-features. */ passthrough?: boolean; } export declare class StackingRegressor extends RegressorBase { private estimators; private finalEstimator; private cv; private passthrough; private fitted; constructor(props: StackingRegressorProps); getParams(): Params; /** Supports own params plus `name__param` / `finalEstimator__param`. */ setParams(params: Params): this; getEstimator(name: string): BaseEstimator; get namedEstimators(): Record; fit(X: number[][], y: number[], sampleWeight?: number[]): void; /** Meta-features for X from the full-data base estimators. */ transform(X: number[][]): number[][]; predict(X: number[][]): number[]; }