8000 DOC Use california data in compose.rst (#16871) · scikit-learn/scikit-learn@30788de · GitHub
[go: up one dir, main page]

Skip to content 10000

Commit 30788de

Browse files
authored
DOC Use california data in compose.rst (#16871)
1 parent 1986c89 commit 30788de

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

doc/modules/compose.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,13 @@ the regressor that will be used for prediction, and the transformer that will
251251
be applied to the target variable::
252252

253253
>>> import numpy as np
254-
>>> from sklearn.datasets import load_boston
254+
>>> from sklearn.datasets import fetch_california_housing
255255
>>> from sklearn.compose import TransformedTargetRegressor
256256
>>> from sklearn.preprocessing import QuantileTransformer
257257
>>> from sklearn.linear_model import LinearRegression
258258
>>> 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
260261
>>> transformer = QuantileTransformer(output_distribution='normal')
261262
>>> regressor = LinearRegression()
262263
>>> regr = TransformedTargetRegressor(regressor=regressor,
@@ -265,10 +266,10 @@ be applied to the target variable::
265266
>>> regr.fit(X_train, y_train)
266267
TransformedTargetRegressor(...)
267268
>>> print('R2 score: {0:.2f}'.format(regr.score(X_test, y_test)))
268-
R2 score: 0.67
269+
R2 score: 0.61
269270
>>> raw_target_regr = LinearRegression().fit(X_train, y_train)
270271
>>> print('R2 score: {0:.2f}'.format(raw_target_regr.score(X_test, y_test)))
271-
R2 score: 0.64
272+
R2 score: 0.59
272273

273274
For simple transformations, instead of a Transformer object, a pair of
274275
functions can be passed, defining the transformation and its inverse mapping::
@@ -286,7 +287,7 @@ Subsequently, the object is created as::
286287
>>> regr.fit(X_train, y_train)
287288
TransformedTargetRegressor(...)
288289
>>> print('R2 score: {0:.2f}'.format(regr.score(X_test, y_test)))
289-
R2 score: 0.65
290+
R2 score: 0.51
290291

291292
By default, the provided functions are checked at each fit to be the inverse of
292293
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
301302
>>> regr.fit(X_train, y_train)
302303
TransformedTargetRegressor(...)
303304
>>> print('R2 score: {0:.2f}'.format(regr.score(X_test, y_test)))
304-
R2 score: -4.50
305+
R2 score: -1.57
305306

306307
.. note::
307308

0 commit comments

Comments
 (0)
0