@@ -1834,24 +1834,24 @@ For the `y` response variable argument, we pass the `unscaled_cancer["Class"]` s
1834
1834
``` {code-cell} ipython3
1835
1835
from sklearn.pipeline import make_pipeline
1836
1836
1837
- knn_fit = make_pipeline(preprocessor, knn).fit(
1837
+ knn_pipeline = make_pipeline(preprocessor, knn)
1838
+ knn_pipeline.fit(
1838
1839
X=unscaled_cancer,
1839
1840
y=unscaled_cancer["Class"]
1840
1841
)
1841
-
1842
- knn_fit
1842
+ knn_pipeline
1843
1843
```
1844
1844
1845
1845
As before, the fit object lists the function that trains the model. But now the fit object also includes information about
1846
1846
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
1848
1848
observation, it will first apply the same preprocessing steps to the new observation.
1849
1849
As an example, we will predict the class label of two new observations:
1850
1850
one with ` Area = 500 ` and ` Smoothness = 0.075 ` , and one with ` Area = 1500 ` and ` Smoothness = 0.1 ` .
1851
1851
1852
1852
``` {code-cell} ipython3
1853
1853
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)
1855
1855
prediction
1856
1856
```
1857
1857
@@ -1886,7 +1886,7 @@ asgrid = np.array(np.meshgrid(are_grid, smo_grid)).reshape(2, -1).T
1886
1886
asgrid = pd.DataFrame(asgrid, columns=["Area", "Smoothness"])
1887
1887
1888
1888
# use the fit workflow to make predictions at the grid points
1889
- knnPredGrid = knn_fit .predict(asgrid)
1889
+ knnPredGrid = knn_pipeline .predict(asgrid)
1890
1890
1891
1891
# bind the predictions as a new column with the grid points
1892
1892
prediction_table = asgrid.copy()
0 commit comments