COSC 3430 · Artificial Intelligence

Pipeline Workbench

Every scikit-learn class plays one or more of three roles: estimator (fit()), transformer (transform()), predictor (predict()). Take six classes apart one by one, then chain them into a Pipeline and see what each step learns and passes on. The data are eleven real districts from the housing training and test sets of class.

0The data

Two features and the target median_house_value. One training district has no total_bedrooms (NaN), as in the full data set.

X_train, y_train (8 districts)
X_test, y_test (3 districts)

1One object, up close

Pick a class. Its hyperparameters exist as soon as you create the object; its learned parameters (names ending in _) appear only after fit(). Call the methods and watch the session below, including the errors.

Class
Hyperparameter to try
Fit and transform on
Call
get_params() — hyperparameters
learned parameters (vars ending in _)

2Build a pipeline

Add steps in order. A Pipeline calls fit_transform() on every step but the last and hands the output on; the last step only gets fit(). So every step before the last must be a transformer, and the pipeline takes on the role of its last step.

Start from
Add a step


    
Call

What to take away

Built to accompany COSC 3430 (Artificial Intelligence), the scikit-learn API and end-to-end ML project, parts 7 and 8. Data: eight districts from the California housing training set and three from the test set of class (stratified split, random_state=42). Every number is computed live in the browser with the same formulas scikit-learn uses, and was checked against scikit-learn 1.7; arrays are shown rounded to four decimals.