@@ -251,12 +251,13 @@ the regressor that will be used for prediction, and the transformer that will
251
251
be applied to the target variable::
252
252
253
253
>>> import numpy as np
254
- >>> from sklearn.datasets import load_boston
254
+ >>> from sklearn.datasets import fetch_california_housing
255
255
>>> from sklearn.compose import TransformedTargetRegressor
256
256
>>> from sklearn.preprocessing import QuantileTransformer
257
257
>>> from sklearn.linear_model import LinearRegression
258
258
>>> from sklearn.model_selection import train_test_split
259
- >>> X, y = load_boston(return_X_y=True)
259
+ >>> X, y = fetch_california_housing(return_X_y=True)
260
+ >>> X, y = X[:2000, :], y[:2000] # select a subset of data
260
261
>>> transformer = QuantileTransformer(output_distribution='normal')
261
262
>>> regressor = LinearRegression()
262
263
>>> regr = TransformedTargetRegressor(regressor=regressor,
@@ -265,10 +266,10 @@ be applied to the target variable::
265
266
>>> regr.fit(X_train, y_train)
266
267
TransformedTargetRegressor(...)
267
268
>>> print('R2 score: {0:.2f}'.format(regr.score(X_test, y_test)))
268
- R2 score: 0.67
269
+ R2 score: 0.61
269
270
>>> raw_target_regr = LinearRegression().fit(X_train, y_train)
270
271
>>> print('R2 score: {0:.2f}'.format(raw_target_regr.score(X_test, y_test)))
271
- R2 score: 0.64
272
+ R2 score: 0.59
272
273
273
274
For simple transformations, instead of a Transformer object, a pair of
274
275
functions can be passed, defining the transformation and its inverse mapping::
@@ -286,7 +287,7 @@ Subsequently, the object is created as::
286
287
>>> regr.fit(X_train, y_train)
287
288
TransformedTargetRegressor(...)
288
289
>>> print('R2 score: {0:.2f}'.format(regr.score(X_test, y_test)))
289
- R2 score: 0.65
290
+ R2 score: 0.51
290
291
291
292
By default, the provided functions are checked at each fit to be the inverse of
292
293
each other. However, it is possible to bypass this checking by setting
@@ -301,7 +302,7 @@ each other. However, it is possible to bypass this checking by setting
301
302
>>> regr.fit(X_train, y_train)
302
303
TransformedTargetRegressor(...)
303
304
>>> print('R2 score: {0:.2f}'.format(regr.score(X_test, y_test)))
304
- R2 score: -4.50
305
+ R2 score: -1.57
305
306
306
307
.. note ::
307
308
0 commit comments