Skip to content

Commit 1a580d4

Browse files
committed
Pushing the docs to dev/ for branch: master, commit c5706e6ff03a9f3c105b2c1b7f972527e664b3c1
1 parent 3daa4bd commit 1a580d4

File tree

580 files changed

+1139
-1165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

580 files changed

+1139
-1165
lines changed
-95 Bytes
Binary file not shown.
-88 Bytes
Binary file not shown.

dev/_downloads/plot_transformed_target.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"cell_type": "markdown",
5252
"metadata": {},
5353
"source": [
54-
"A synthetic random regression problem is generated. The targets ``y`` are\nmodified by: (i) translating all targets such that all entries are\nnon-negative and (ii) applying an exponential function to obtain non-linear\ntargets which cannot be fitted using a simple linear model.\n\nTherefore, a logarithmic and an exponential function will be used to\ntransform the targets before training a linear regression model and using it\nfor prediction.\n\n"
54+
"A synthetic random regression problem is generated. The targets ``y`` are\nmodified by: (i) translating all targets such that all entries are\nnon-negative and (ii) applying an exponential function to obtain non-linear\ntargets which cannot be fitted using a simple linear model.\n\nTherefore, a logarithmic (`np.log1p`) and an exponential function\n(`np.expm1`) will be used to transform the targets before training a linear\nregression model and using it for prediction.\n\n"
5555
]
5656
},
5757
{
@@ -62,7 +62,7 @@
6262
},
6363
"outputs": [],
6464
"source": [
65-
"def log_transform(x):\n return np.log(x + 1)\n\n\ndef exp_transform(x):\n return np.exp(x) - 1\n\n\nX, y = make_regression(n_samples=10000, noise=100, random_state=0)\ny = np.exp((y + abs(y.min())) / 200)\ny_trans = log_transform(y)"
65+
"X, y = make_regression(n_samples=10000, noise=100, random_state=0)\ny = np.exp((y + abs(y.min())) / 200)\ny_trans = np.log1p(y)"
6666
]
6767
},
6868
{
@@ -98,7 +98,7 @@
9898
},
9999
"outputs": [],
100100
"source": [
101-
"f, (ax0, ax1) = plt.subplots(1, 2, sharey=True)\n\nregr = RidgeCV()\nregr.fit(X_train, y_train)\ny_pred = regr.predict(X_test)\n\nax0.scatter(y_test, y_pred)\nax0.plot([0, 2000], [0, 2000], '--k')\nax0.set_ylabel('Target predicted')\nax0.set_xlabel('True Target')\nax0.set_title('Ridge regression \\n without target transformation')\nax0.text(100, 1750, r'$R^2$=%.2f, MAE=%.2f' % (\n r2_score(y_test, y_pred), median_absolute_error(y_test, y_pred)))\nax0.set_xlim([0, 2000])\nax0.set_ylim([0, 2000])\n\nregr_trans = TransformedTargetRegressor(regressor=RidgeCV(),\n func=log_transform,\n inverse_func=exp_transform)\nregr_trans.fit(X_train, y_train)\ny_pred = regr_trans.predict(X_test)\n\nax1.scatter(y_test, y_pred)\nax1.plot([0, 2000], [0, 2000], '--k')\nax1.set_ylabel('Target predicted')\nax1.set_xlabel('True Target')\nax1.set_title('Ridge regression \\n with target transformation')\nax1.text(100, 1750, r'$R^2$=%.2f, MAE=%.2f' % (\n r2_score(y_test, y_pred), median_absolute_error(y_test, y_pred)))\nax1.set_xlim([0, 2000])\nax1.set_ylim([0, 2000])\n\nf.suptitle(\"Synthetic data\", y=0.035)\nf.tight_layout(rect=[0.05, 0.05, 0.95, 0.95])"
101+
"f, (ax0, ax1) = plt.subplots(1, 2, sharey=True)\n\nregr = RidgeCV()\nregr.fit(X_train, y_train)\ny_pred = regr.predict(X_test)\n\nax0.scatter(y_test, y_pred)\nax0.plot([0, 2000], [0, 2000], '--k')\nax0.set_ylabel('Target predicted')\nax0.set_xlabel('True Target')\nax0.set_title('Ridge regression \\n without target transformation')\nax0.text(100, 1750, r'$R^2$=%.2f, MAE=%.2f' % (\n r2_score(y_test, y_pred), median_absolute_error(y_test, y_pred)))\nax0.set_xlim([0, 2000])\nax0.set_ylim([0, 2000])\n\nregr_trans = TransformedTargetRegressor(regressor=RidgeCV(),\n func=np.log1p,\n inverse_func=np.expm1)\nregr_trans.fit(X_train, y_train)\ny_pred = regr_trans.predict(X_test)\n\nax1.scatter(y_test, y_pred)\nax1.plot([0, 2000], [0, 2000], '--k')\nax1.set_ylabel('Target predicted')\nax1.set_xlabel('True Target')\nax1.set_title('Ridge regression \\n with target transformation')\nax1.text(100, 1750, r'$R^2$=%.2f, MAE=%.2f' % (\n r2_score(y_test, y_pred), median_absolute_error(y_test, y_pred)))\nax1.set_xlim([0, 2000])\nax1.set_ylim([0, 2000])\n\nf.suptitle(\"Synthetic data\", y=0.035)\nf.tight_layout(rect=[0.05, 0.05, 0.95, 0.95])"
102102
]
103103
},
104104
{

dev/_downloads/plot_transformed_target.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,13 @@
4040
# non-negative and (ii) applying an exponential function to obtain non-linear
4141
# targets which cannot be fitted using a simple linear model.
4242
#
43-
# Therefore, a logarithmic and an exponential function will be used to
44-
# transform the targets before training a linear regression model and using it
45-
# for prediction.
46-
47-
48-
def log_transform(x):
49-
return np.log(x + 1)
50-
51-
52-
def exp_transform(x):
53-
return np.exp(x) - 1
54-
43+
# Therefore, a logarithmic (`np.log1p`) and an exponential function
44+
# (`np.expm1`) will be used to transform the targets before training a linear
45+
# regression model and using it for prediction.
5546

5647
X, y = make_regression(n_samples=10000, noise=100, random_state=0)
5748
y = np.exp((y + abs(y.min())) / 200)
58-
y_trans = log_transform(y)
49+
y_trans = np.log1p(y)
5950

6051
###############################################################################
6152
# The following illustrate the probability density functions of the target
@@ -103,8 +94,8 @@ def exp_transform(x):
10394
ax0.set_ylim([0, 2000])
10495

10596
regr_trans = TransformedTargetRegressor(regressor=RidgeCV(),
106-
func=log_transform,
107-
inverse_func=exp_transform)
97+
func=np.log1p,
98+
inverse_func=np.expm1)
10899
regr_trans.fit(X_train, y_train)
109100
y_pred = regr_trans.predict(X_test)
110101

dev/_downloads/scikit-learn-docs.pdf

-23.3 KB
Binary file not shown.
-239 Bytes
-239 Bytes
62 Bytes
62 Bytes
-190 Bytes

0 commit comments

Comments
 (0)