v4 Create & Train PipelineΒΆ
View code on GitHub Get the Video Course
ProgressΒΆ
What's NewΒΆ
| File | Change |
|---|---|
utils/ | Implemented create_ - ColumnTransformer |
utils/ | Implemented create_ - sklearn Pipeline |
utils/ | Exports create_, create_ |
p3_ | Added STEP 3 (create) + STEP 4 (train) |
New FunctionsΒΆ
# utils/data_utils.py
def create_preprocessor(categorical_cols, numerical_cols):
"""ColumnTransformer: OneHotEncoder + StandardScaler."""
# utils/model_utils.py
def create_pipeline(categorical_cols, numerical_cols, model_params=None):
"""Build sklearn Pipeline = preprocessor + LogisticRegression."""
Key Concept: Why Pipeline?ΒΆ
WITHOUT Pipeline (bad): WITH Pipeline (good):
βββββββββββββββββββββ βββββββββββββββββββββ
encoder.fit(X_train) pipeline.fit(X_train, y_train)
X_train_enc = encoder.transform(...) pipeline.predict(X_test)
scaler.fit(X_train_enc) # That's it! One object does everything.
X_train_scaled = scaler.transform(...)
model.fit(X_train_scaled, y_train)
# Easy to leak data, hard to deploy
Pipeline = one object that handles preprocessing + model. Works with MLflow, KServe, SageMaker out of the box.
How to RunΒΆ
Terminal
cd v4_create_and_train_pipeline_ccfd-project/
# PRE-REQUISITE: Generate data first
python p1_01_generate_initial_dataset.py
# Run training script
python p3_01_train_model_baseline.py
Expected Output:
STEP 1: Loading Data
Loaded 10,000 transactions from data/credit_card_transactions_latest.csv
STEP 2: Splitting Data
Split: 8,000 train | 2,000 test
STEP 3: Creating Pipeline
Pipeline created:
1. Preprocessor (OneHotEncoder + StandardScaler)
2. Model (LogisticRegression)
STEP 4: Training Pipeline
Training pipeline on raw data...
Training complete!
Next VersionΒΆ
v5 β Implement print_metrics() - evaluate the trained model with technical AND business metrics.
Prefer to learn by watching?
The video course builds this whole project with you on screen, step by step.
Back to 04 A Train Baseline Model v3 Split Train/Test Next: v5 Evaluate and Metrics
π New Course