Skip to content

Commit c3105b8

Browse files
consistent usage of .fit in clsfn1
1 parent 8b88528 commit c3105b8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

source/classification1.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,24 +1834,24 @@ For the `y` response variable argument, we pass the `unscaled_cancer["Class"]` s
18341834
```{code-cell} ipython3
18351835
from sklearn.pipeline import make_pipeline
18361836
1837-
knn_fit = make_pipeline(preprocessor, knn).fit(
1837+
knn_pipeline = make_pipeline(preprocessor, knn)
1838+
knn_pipeline.fit(
18381839
X=unscaled_cancer,
18391840
y=unscaled_cancer["Class"]
18401841
)
1841-
1842-
knn_fit
1842+
knn_pipeline
18431843
```
18441844

18451845
As before, the fit object lists the function that trains the model. But now the fit object also includes information about
18461846
the overall workflow, including the standardization preprocessing step.
1847-
In other words, when we use the `predict` function with the `knn_fit` object to make a prediction for a new
1847+
In other words, when we use the `predict` function with the `knn_pipeline` object to make a prediction for a new
18481848
observation, it will first apply the same preprocessing steps to the new observation.
18491849
As an example, we will predict the class label of two new observations:
18501850
one with `Area = 500` and `Smoothness = 0.075`, and one with `Area = 1500` and `Smoothness = 0.1`.
18511851

18521852
```{code-cell} ipython3
18531853
new_observation = pd.DataFrame({"Area": [500, 1500], "Smoothness": [0.075, 0.1]})
1854-
prediction = knn_fit.predict(new_observation)
1854+
prediction = knn_pipeline.predict(new_observation)
18551855
prediction
18561856
```
18571857

@@ -1886,7 +1886,7 @@ asgrid = np.array(np.meshgrid(are_grid, smo_grid)).reshape(2, -1).T
18861886
asgrid = pd.DataFrame(asgrid, columns=["Area", "Smoothness"])
18871887
18881888
# use the fit workflow to make predictions at the grid points
1889-
knnPredGrid = knn_fit.predict(asgrid)
1889+
knnPredGrid = knn_pipeline.predict(asgrid)
18901890
18911891
# bind the predictions as a new column with the grid points
18921892
prediction_table = asgrid.copy()

0 commit comments

Comments
 (0)