pipeline¶
Full experiment pipeline with train/test evaluation.
pipeline
¶
@module: sce.pipeline @depends: sklearn, sce.config, sce.engine @exports: fit_context_pipeline, create_sce_pipeline @paper_ref: Section 6 (Implementation) @data_flow: raw_df -> sce_features -> model -> predictions
create_sce_pipeline
¶
Create a scikit-learn pipeline with SCE feature engineering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ContextConfig
|
SCE configuration |
required |
model
|
Optional[BaseEstimator]
|
Optional model to add at the end (e.g., XGBoost, LightGBM) |
None
|
Returns:
| Type | Description |
|---|---|
Pipeline
|
sklearn Pipeline with SCE transformer and optional model |
Example
from sklearn.ensemble import RandomForestRegressor from sce import ContextConfig, create_sce_pipeline
config = ContextConfig(categorical_cols=["region", "city"], target_col="price") pipeline = create_sce_pipeline(config, model=RandomForestRegressor()) X_train = train_df.drop(columns=["price"]) y_train = train_df["price"] pipeline.fit(X_train, y_train)
Note
The SCE step augments the feature matrix, but it does not encode raw string columns for downstream estimators. If your model cannot consume string-valued columns directly, encode or preprocess them before fitting the final model.
Source code in sce/pipeline.py
fit_context_pipeline
¶
fit_context_pipeline(df: DataFrame, config: ContextConfig, model: Optional[BaseEstimator] = None, **fit_params: Any) -> Pipeline
Convenience function to fit a complete SCE pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Training dataframe |
required |
config
|
ContextConfig
|
SCE configuration |
required |
model
|
Optional[BaseEstimator]
|
Optional model to include |
None
|
**fit_params
|
Any
|
Additional parameters for model fitting |
{}
|
Returns:
| Type | Description |
|---|---|
Pipeline
|
Fitted pipeline |