Understand the idea
Two different transformations serve two different roles. The outer StandardScaler prepares input measurements X. TransformedTargetRegressor learns a separate scale for y within each fitting population, then reverses that target scale automatically when predict returns. Wine quality predictions and RMSE use quality-score points; the Apply electricity workflow uses kWh.
What the syntax does
model.named_steps['model']- The model step is the target wrapper.
- After model
.fit, transformer_ is its fitted target scaler; mean_ records the fitting target mean. - This is separate from the outer input scaler.
- The prepare step contains fitted preparation; model contains the prediction estimator.
- A ColumnTransformer also exposes its named_transformers_ when inspecting encoded categories.
TransformedTargetRegressor(regressor=MLPRegressor(...), transformer=StandardScaler())- Transforms outcomes for fitting and returns predictions in the original units.
- transformer acts on the target; regressor names the prediction recipe.
- Keep both transformations within every fit.
- Wine predictions return
quality-score points; household predictions return kWh. - Compare actual and predicted values in the same named unit.
Supplied for this practice
These objects are prepared afresh before your editor runs.
X- Feature dataframe for the declared population, preserving row indices.
X = df.drop(columns=['quality', 'wine_type']) y- Target series, aligned with
X.y = df.quality X_train/X_test/y_train/y_test- Training feature rows from the declared split. Final-test feature rows from the declared split. Training targets, aligned with
X_train. Final-test targets, aligned withX_test.X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) model- An unfitted recipe is supplied; construction has not learned parameters. Fit it here only when the task requests fitting.
model = Pipeline([('scale', StandardScaler()), ('model', TransformedTargetRegressor(regressor=MLPRegressor(hidden_layer_sizes=(24,), max_iter=800, early_stopping=True, tol=0.001, random_state=42), transformer=StandardScaler()))])
Outputs you create
answer- The requested result, with the values, labels and row order described by this task.
fixed acidity | volatile acidity | citric acid | residual sugar | chlorides | free sulfur dioxide | total sulfur dioxide | density | pH | sulphates | alcohol | quality | wine_type |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 5.3 | 0.32 | 0.12 | 6.6 | 0.043 | 22 | 141 | 0.9937 | 3.36 | 0.6 | 10.4 | 6 | white |
| 6.4 | 0.3 | 0.27 | 4.4 | 0.055 | 17 | 135 | 0.9925 | 3.23 | 0.44 | 12.2 | 6 | white |
| 6.5 | 0.22 | 0.32 | 2.2 | 0.028 | 36 | 92 | 0.99076 | 3.27 | 0.59 | 11.9 | 7 | white |
| 8 | 0.24 | 0.48 | 6.8 | 0.047 | 13 | 134 | 0.99616 | 3.23 | 0.7 | 10 | 5 | white |
| 8.9 | 0.29 | 0.35 | 1.9 | 0.067 | 25 | 57 | 0.997 | 3.18 | 1.36 | 10.3 | 6 | red |
| 6.6 | 0.21 | 0.39 | 2.3 | 0.041 | 31 | 102 | 0.99221 | 3.22 | 0.58 | 10.9 | 7 | white |
| 8.8 | 0.24 | 0.54 | 2.5 | 0.083 | 25 | 57 | 0.9983 | 3.39 | 0.54 | 9.2 | 5 | red |
| 5.4 | 0.15 | 0.32 | 2.5 | 0.037 | 10 | 51 | 0.98878 | 3.04 | 0.58 | 12.6 | 6 | white |
- Fit the supplied feature pipeline and target wrapper.
answerHints
Think: The target wrapper learns a separate transformation of y during fit.
Tools: TransformedTargetRegressor and its fitted transformer_.
Approach: Fit the full supplied recipe and inspect the target transformer’s learned mean.
Explained solution
model.fit(X_train,y_train)
answer=model.named_steps['model'].transformer_.mean_
The target scale is learned from training outcomes within the wrapper, rather than globally before validation.