Skip to main content

Pipeline

#include <Skigen/Pipeline>

template <typename...>
class Skigen::Pipeline(steps)

Pipeline of transforms with a final estimator.

Sequentially apply a list of transforms and a final estimator. Intermediate steps of the pipeline must implement fit() and transform(). The final estimator only needs to implement fit().

The pipeline object is created via make_pipeline().

Mirrors sklearn.pipeline.Pipeline.


Parameters:

  • steps : Steps... The transformer and estimator steps (moved into the pipeline).

Attributes:

  • get : auto Access a step by compile-time index (const).

  • is_fitted : bool Check whether the pipeline has been fitted.


Methods​

fit(X, y)​

Fit all transformers and the final estimator.

Calls fit() then transform() on each intermediate step, then fit() on the final estimator with the transformed data.

Parameters:

  • X : MatrixType Training data of shape (n_samples, n_features).

  • y : YType Target values (type depends on the final estimator).

Returns:

  • result : Pipeline Reference to the fitted pipeline (*this). fit with supervised target (transformers + final estimator)

predict(X, args)​

Predict using the pipeline.

Applies transform() on all intermediate steps, then calls predict() on the final estimator.

Parameters:

  • X : MatrixType Test data of shape (n_samples, n_features).

Returns:

  • result : auto Predictions from the final estimator.

Throws:

  • std::runtime_error — if the pipeline has not been fitted. predict (transform through all steps, predict with final)

score(X, y)​

Score the pipeline on test data.

Applies transform() on all intermediate steps, then calls score() on the final estimator.

Parameters:

  • X : MatrixType Test data of shape (n_samples, n_features).

  • y : YType True target values.

Returns:

  • result : auto Score from the final estimator.

Throws:

  • std::runtime_error — if the pipeline has not been fitted. score (transform through all steps, score with final)

get()​

Access a step by compile-time index.

Returns:

  • result : auto Reference to the step.

set_param(name, value)​

Route a "<step_index>__<param>" setting to the addressed step.

Enables hyperparameter search over pipeline steps: a GridSearchCV parameter grid keyed by e.g. "1__alpha" updates alpha on step 1. The pipeline is an index-addressed tuple of steps, so the step prefix is the numeric index (sklearn addresses steps by name; Skigen's compile-time tuple has no names).


Example​

// Pipeline 1: StandardScaler → LinearRegression
// -----------------------------------------------------------------------
auto pipe1 = Skigen::make_pipeline(
Skigen::StandardScaler<double>(),
Skigen::LinearRegression<double>());

pipe1.fit(split.X_train, split.y_train);

std::cout << "=== Pipeline: Scaler → OLS ===\n";
std::cout << "R²: " << pipe1.score(split.X_test, split.y_test) << "\n\n";

// Access fitted scaler
auto& scaler = pipe1.get<0>();
std::cout << "Fitted mean: " << scaler.mean() << "\n";
std::cout << "Fitted scale: " << scaler.scale() << "\n\n";
auto pipe = Skigen::make_pipeline(
Skigen::StandardScaler<double>(),
Skigen::LinearRegression<double>());
pipe.fit(X, y);
auto y_pred = pipe.predict(X);