Pipeline
A compile-time pipeline that chains transformers and a final estimator into a single object. All step types are verified at compile time using C++ template metaprogramming — incompatible steps produce a compile error rather than a runtime failure.
Semantics
For a pipeline with transformers and a final estimator :
Fitting — each transformer is fit and transforms the data sequentially before the estimator is fit:
Prediction — data passes through each transformer's transform, then the estimator's predict:
This ensures that the same preprocessing applied during training is automatically applied during prediction, preventing train/test skew.
Mirrors sklearn.pipeline.Pipeline.
Construction
auto pipe = Skigen::make_pipeline(step1, step2, ..., estimator);
Or explicitly:
Skigen::Pipeline<StandardScaler<>, PCA<>, LinearRegression<>> pipe(scaler, pca, model);
Methods
| Method | Description |
|---|---|
fit(X, y) | Fit all steps sequentially |
predict(X) | Transform through all steps, then predict |
score(X, y) | Transform and score |
get<I>() | Access step at index I |
Example
#include <Skigen/Pipeline>
#include <Skigen/Preprocessing>
#include <Skigen/LinearModel>
auto pipe = Skigen::make_pipeline(
Skigen::StandardScaler<>(),
Skigen::LinearRegression<>()
);
pipe.fit(X_train, y_train);
std::cout << "R²: " << pipe.score(X_test, y_test) << "\n";
// Access fitted scaler
auto& scaler = pipe.get<0>();
std::cout << "Mean: " << scaler.mean() << "\n";