Skip to content

Commit 582e2c9

Browse files
committed
[ci skip] MTN Made the distinction between predictor and transformer clearer (#856) aa0fdfb
1 parent ec7b59b commit 582e2c9

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

_sources/python_scripts/02_numerical_pipeline_introduction.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,18 @@
101101
# ![Predictor fit diagram](../figures/api_diagram-predictor.fit.svg)
102102
#
103103
# In scikit-learn an object that has a `fit` method is called an **estimator**.
104+
# If the estimator additionally has :
105+
# - a `predict` method, it is called a **predictor**. Examples of predictors
106+
# are classifiers or regressors.
107+
# - a `transform` method, it is called a **transformer**. Examples of
108+
# transformers are scalers or encoders. We will see more about transformers in
109+
# the next notebook.
110+
#
104111
# The method `fit` is composed of two elements: (i) a **learning algorithm** and
105112
# (ii) some **model states**. The learning algorithm takes the training data and
106113
# training target as input and sets the model states. These model states are
107-
# later used to either predict (for classifiers and regressors) or transform
108-
# data (for transformers).
114+
# later used to either predict or transform data as explained above. See the
115+
# glossary for more detailed definitions.
109116
#
110117
# Both the learning algorithm and the type of model states are specific to each
111118
# type of model.
@@ -124,8 +131,7 @@
124131
target_predicted = model.predict(data)
125132

126133
# %% [markdown]
127-
# An estimator (an object with a `fit` method) with a `predict` method is called
128-
# a **predictor**. We can illustrate the prediction mechanism as follows:
134+
# We can illustrate the prediction mechanism as follows:
129135
#
130136
# ![Predictor predict diagram](../figures/api_diagram-predictor.predict.svg)
131137
#

_sources/python_scripts/02_numerical_pipeline_scaling.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
# We show how to apply such normalization using a scikit-learn transformer
8989
# called `StandardScaler`. This transformer shifts and scales each feature
9090
# individually so that they all have a 0-mean and a unit standard deviation.
91+
# We recall that transformers are estimators that have a `transform` method.
9192
#
9293
# We now investigate different steps used in scikit-learn to achieve such a
9394
# transformation of the data.

python_scripts/02_numerical_pipeline_introduction.html

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,11 +1070,19 @@ <h2>Fit a model and make predictions<a class="headerlink" href="#fit-a-model-and
10701070
<p>Learning can be represented as follows:</p>
10711071
<p><img alt="Predictor fit diagram" src="../_images/api_diagram-predictor.fit.svg" /></p>
10721072
<p>In scikit-learn an object that has a <code class="docutils literal notranslate"><span class="pre">fit</span></code> method is called an <strong>estimator</strong>.
1073-
The method <code class="docutils literal notranslate"><span class="pre">fit</span></code> is composed of two elements: (i) a <strong>learning algorithm</strong> and
1073+
If the estimator additionally has :</p>
1074+
<ul class="simple">
1075+
<li><p>a <code class="docutils literal notranslate"><span class="pre">predict</span></code> method, it is called a <strong>predictor</strong>. Examples of predictors
1076+
are classifiers or regressors.</p></li>
1077+
<li><p>a <code class="docutils literal notranslate"><span class="pre">transform</span></code> method, it is called a <strong>transformer</strong>. Examples of
1078+
transformers are scalers or encoders. We will see more about transformers in
1079+
the next notebook.</p></li>
1080+
</ul>
1081+
<p>The method <code class="docutils literal notranslate"><span class="pre">fit</span></code> is composed of two elements: (i) a <strong>learning algorithm</strong> and
10741082
(ii) some <strong>model states</strong>. The learning algorithm takes the training data and
10751083
training target as input and sets the model states. These model states are
1076-
later used to either predict (for classifiers and regressors) or transform
1077-
data (for transformers).</p>
1084+
later used to either predict or transform data as explained above. See the
1085+
glossary for more detailed definitions.</p>
10781086
<p>Both the learning algorithm and the type of model states are specific to each
10791087
type of model.</p>
10801088
<div class="admonition note">
@@ -1091,8 +1099,7 @@ <h2>Fit a model and make predictions<a class="headerlink" href="#fit-a-model-and
10911099
</div>
10921100
</div>
10931101
</div>
1094-
<p>An estimator (an object with a <code class="docutils literal notranslate"><span class="pre">fit</span></code> method) with a <code class="docutils literal notranslate"><span class="pre">predict</span></code> method is called
1095-
a <strong>predictor</strong>. We can illustrate the prediction mechanism as follows:</p>
1102+
<p>We can illustrate the prediction mechanism as follows:</p>
10961103
<p><img alt="Predictor predict diagram" src="../_images/api_diagram-predictor.predict.svg" /></p>
10971104
<p>To predict, a model uses a <strong>prediction function</strong> that uses the input data
10981105
together with the model states. As for the learning algorithm and the model

python_scripts/02_numerical_pipeline_scaling.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,8 @@ <h2>Model fitting with preprocessing<a class="headerlink" href="#model-fitting-w
879879
not need such preprocessing (but would not suffer from it).</p>
880880
<p>We show how to apply such normalization using a scikit-learn transformer
881881
called <code class="docutils literal notranslate"><span class="pre">StandardScaler</span></code>. This transformer shifts and scales each feature
882-
individually so that they all have a 0-mean and a unit standard deviation.</p>
882+
individually so that they all have a 0-mean and a unit standard deviation.
883+
We recall that transformers are estimators that have a <code class="docutils literal notranslate"><span class="pre">transform</span></code> method.</p>
883884
<p>We now investigate different steps used in scikit-learn to achieve such a
884885
transformation of the data.</p>
885886
<p>First, one needs to call the method <code class="docutils literal notranslate"><span class="pre">fit</span></code> in order to learn the scaling from

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)