3.3 Practical Exercises for Chapter 3
These exercises will help you practice automating data preprocessing with Scikit-learn’s Pipeline and FeatureUnion classes. Each exercise includes a solution with code for guidance.
Exercise 1: Building a Simple Pipeline with Standard Scaling and Logistic Regression
Create a pipeline that applies Standard Scaling to the numeric features Age and Income, and then uses Logistic Regression to classify a target variable Churn.
Load the dataset and split it into features (X) and target (y).
Create a pipeline with StandardScaler and LogisticRegression.
Train the pipeline and evaluate it on the test set.
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model ...