import { BaseEstimator, Params } from '../base/estimator'; import type { FeatureData } from '../data'; export type PipelineStep = readonly [name: string, estimator: BaseEstimator]; type Last = T extends readonly [...unknown[], infer L] ? L : T extends readonly (infer E)[] ? E : never; type StepEstimator = T extends readonly [string, infer E] ? E : never; type TransformerOutput = T extends { transform(X: never): infer O; } ? Extract : FeatureData; /** Output type of the final step when it is a transformer. */ export type PipelineOutput = TransformerOutput>>; export interface PipelineProps { /** Ordered [name, estimator] pairs; all but the last must be transformers. */ steps: TSteps; } /** * Chain of transformers with a final estimator, mirroring sklearn's * `Pipeline`. Nested params are addressable as `step__param` in `setParams` * (and therefore in grid search): `pipe.setParams({ svc__C: 10 })`. */ export declare class Pipeline extends BaseEstimator { private steps; constructor(props: PipelineProps); getParams(): Params; /** Supports both own params and nested `step__param` addressing. */ setParams(params: Params): this; getStep(name: string): BaseEstimator; get namedSteps(): Record; private get finalStep(); /** Fit all transformers, transforming the data through, then fit the final estimator. */ fit(X: FeatureData, y?: number[], sampleWeight?: number[]): void; private fitIntermediate; private applyIntermediate; predict(X: FeatureData): number[]; predictProba(X: FeatureData): number[][]; /** Transform through every step (requires the final step to be a transformer too). */ transform(X: FeatureData): PipelineOutput; fitTransform(X: FeatureData, y?: number[]): PipelineOutput; score(X: FeatureData, y: number[]): number; } /** `makePipeline(new StandardScaler(), new SVC())` — names derived from class names. */ type NamedSteps = { readonly [K in keyof T]: readonly [name: string, estimator: T[K]]; }; export declare function makePipeline(...estimators: T): Pipeline>; export {};