Skip to content

Commit 132bda1

Browse files
Errata fixes (#45)
* fixes to Rmd from Daniela's errata
1 parent 6d7e405 commit 132bda1

8 files changed

Lines changed: 25 additions & 23 deletions

Ch02-statlearn-lab.Rmd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ A[1:4:2,0:3:2]
836836

837837

838838
Why are we able to retrieve a submatrix directly using slices but not using lists?
839-
Its because they are different `Python` types, and
839+
It's because they are different `Python` types, and
840840
are treated differently by `numpy`.
841841
Slices can be used to extract objects from arbitrary sequences, such as strings, lists, and tuples, while the use of lists for indexing is more limited.
842842

@@ -889,7 +889,8 @@ A[np.array([0,1,0,1])]
889889
890890
```
891891

892-
By contrast, `keep_rows` retrieves only the second and fourth rows of `A` --- i.e. the rows for which the Boolean equals `TRUE`.
892+
By contrast, `keep_rows` retrieves only the second and fourth rows of `A` --- i.e. the rows for which the Boolean equals `True`.
893+
893894

894895
```{python}
895896
A[keep_rows]
@@ -1152,7 +1153,7 @@ Auto_re.loc[lambda df: (df['year'] > 80) & (df['mpg'] > 30),
11521153
The symbol `&` computes an element-wise *and* operation.
11531154
As another example, suppose that we want to retrieve all `Ford` and `Datsun`
11541155
cars with `displacement` less than 300. We check whether each `name` entry contains either the string `ford` or `datsun` using the `str.contains()` method of the `index` attribute of
1155-
of the dataframe:
1156+
the dataframe:
11561157

11571158
```{python}
11581159
Auto_re.loc[lambda df: (df['displacement'] < 300)

Ch03-linreg-lab.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ matrices (also called design matrices) using the `ModelSpec()` transform from `
102102

103103
We will use the `Boston` housing data set, which is contained in the `ISLP` package. The `Boston` dataset records `medv` (median house value) for $506$ neighborhoods
104104
around Boston. We will build a regression model to predict `medv` using $13$
105-
predictors such as `rmvar` (average number of rooms per house),
105+
predictors such as `rm` (average number of rooms per house),
106106
`age` (proportion of owner-occupied units built prior to 1940), and `lstat` (percent of
107107
households with low socioeconomic status). We will use `statsmodels` for this
108108
task, a `Python` package that implements several commonly used
@@ -252,7 +252,7 @@ We can produce confidence intervals for the predicted values.
252252
new_predictions.conf_int(alpha=0.05)
253253
254254
```
255-
Prediction intervals are computing by setting `obs=True`:
255+
Prediction intervals are computed by setting `obs=True`:
256256

257257
```{python}
258258
new_predictions.conf_int(obs=True, alpha=0.05)
@@ -286,7 +286,7 @@ def abline(ax, b, m):
286286
```
287287
A few things are illustrated above. First we see the syntax for defining a function:
288288
`def funcname(...)`. The function has arguments `ax, b, m`
289-
where `ax` is an axis object for an exisiting plot, `b` is the intercept and
289+
where `ax` is an axis object for an existing plot, `b` is the intercept and
290290
`m` is the slope of the desired line. Other plotting options can be passed on to
291291
`ax.plot` by including additional optional arguments as follows:
292292

@@ -539,7 +539,7 @@ and `lstat`.
539539

540540
The function `anova_lm()` can take more than two nested models
541541
as input, in which case it compares every successive pair of models.
542-
That also explains why their are `NaN`s in the first row above, since
542+
That also explains why there are `NaN`s in the first row above, since
543543
there is no previous model with which to compare the first.
544544

545545

Ch05-resample-lab.Rmd

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fit is $23.62$.
8888

8989
We can also estimate the validation error for
9090
higher-degree polynomial regressions. We first provide a function `evalMSE()` that takes a model string as well
91-
as a training and test set and returns the MSE on the test set.
91+
as training and test sets and returns the MSE on the test set.
9292

9393
```{python}
9494
def evalMSE(terms,
@@ -195,7 +195,7 @@ object with the appropriate `fit()`, `predict()`,
195195
and `score()` methods, an
196196
array of features `X` and a response `Y`.
197197
We also included an additional argument `cv` to `cross_validate()`; specifying an integer
198-
$K$ results in $K$-fold cross-validation. We have provided a value
198+
$k$ results in $k$-fold cross-validation. We have provided a value
199199
corresponding to the total number of observations, which results in
200200
leave-one-out cross-validation (LOOCV). The `cross_validate()` function produces a dictionary with several components;
201201
we simply want the cross-validated test score here (MSE), which is estimated to be 24.23.
@@ -243,8 +243,8 @@ np.add.outer(A, B)
243243
244244
```
245245

246-
In the CV example above, we used $K=n$, but of course we can also use $K<n$. The code is very similar
247-
to the above (and is significantly faster). Here we use `KFold()` to partition the data into $K=10$ random groups. We use `random_state` to set a random seed and initialize a vector `cv_error` in which we will store the CV errors corresponding to the
246+
In the CV example above, we used $k=n$, but of course we can also use $k<n$. The code is very similar
247+
to the above (and is significantly faster). Here we use `KFold()` to partition the data into $k=10$ random groups. We use `random_state` to set a random seed and initialize a vector `cv_error` in which we will store the CV errors corresponding to the
248248
polynomial fits of degrees one to five.
249249

250250
```{python}
@@ -264,7 +264,7 @@ cv_error
264264
```
265265
Notice that the computation time is much shorter than that of LOOCV.
266266
(In principle, the computation time for LOOCV for a least squares
267-
linear model should be faster than for $K$-fold CV, due to the
267+
linear model should be faster than for $k$-fold CV, due to the
268268
availability of the formula~(\ref{Ch5:eq:LOOCVform}) for LOOCV;
269269
however, the generic `cross_validate()` function does not make
270270
use of this formula.) We still see little evidence that using cubic
@@ -273,8 +273,9 @@ using a quadratic fit.
273273

274274

275275
The `cross_validate()` function is flexible and can take
276-
different splitting mechanisms as an argument. For instance, one can use the `ShuffleSplit()` funtion to implement
277-
the validation set approach just as easily as K-fold cross-validation.
276+
different splitting mechanisms as an argument. For instance, one can use the `ShuffleSplit()`
277+
function to implement
278+
the validation set approach just as easily as $k$-fold cross-validation.
278279

279280
```{python}
280281
validation = ShuffleSplit(n_splits=1,
@@ -511,7 +512,7 @@ standard formulas given in
511512
rely on certain assumptions. For example,
512513
they depend on the unknown parameter $\sigma^2$, the noise
513514
variance. We then estimate $\sigma^2$ using the RSS. Now although the
514-
formula for the standard errors do not rely on the linear model being
515+
formulas for the standard errors do not rely on the linear model being
515516
correct, the estimate for $\sigma^2$ does. We see
516517
{in Figure~\ref{Ch3:polyplot} on page~\pageref{Ch3:polyplot}} that there is
517518
a non-linear relationship in the data, and so the residuals from a

Ch06-varselect-lab.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ The function `fit_path()` returns a list whose values include the fitted coeffic
334334
path[3]
335335
336336
```
337-
In the example above, we see that at the fourth step in the path, we have two nonzero coefficients in `'B'`, corresponding to the value $0.114$ for the penalty parameter `lambda_0`.
337+
In the example above, we see that at the fourth step in the path, we have two nonzero coefficients in `'B'`, corresponding to the value $0.0114$ for the penalty parameter `lambda_0`.
338338
We could make predictions using this sequence of fits on a validation set as a function of `lambda_0`, or with more work using cross-validation.
339339

340340
## Ridge Regression and the Lasso
@@ -913,6 +913,6 @@ ax.set_ylim([50000,250000]);
913913
```
914914

915915
CV error is minimized at 12,
916-
though there is little noticable difference between this point and a much lower number like 2 or 3 components.
916+
though there is little noticeable difference between this point and a much lower number like 2 or 3 components.
917917

918918

Ch08-baggboost-lab.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ grid.fit(X_train, High_train)
223223
grid.best_score_
224224
225225
```
226-
Let’s take a look at the pruned true.
226+
Let’s take a look at the pruned tree.
227227

228228
```{python}
229229
ax = subplots(figsize=(12, 12))[1]
@@ -509,7 +509,7 @@ np.mean((y_test - y_hat_boost)**2)
509509
```
510510

511511

512-
In this case, using $\lambda=0.2$ leads to a almost the same test MSE
512+
In this case, using $\lambda=0.2$ leads to almost the same test MSE
513513
as when using $\lambda=0.001$.
514514

515515

Ch09-svm-lab.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ roc_curve = RocCurveDisplay.from_estimator # shorthand
4242
We now use the `SupportVectorClassifier()` function (abbreviated `SVC()`) from `sklearn` to fit the support vector
4343
classifier for a given value of the parameter `C`. The
4444
`C` argument allows us to specify the cost of a violation to
45-
the margin. When the `cost` argument is small, then the margins
45+
the margin. When the `C` argument is small, then the margins
4646
will be wide and many support vectors will be on the margin or will
4747
violate the margin. When the `C` argument is large, then the
4848
margins will be narrow and there will be few support vectors on the

Ch10-deeplearning-lab.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ img_preds = resnet_model(imgs)
11371137
Let’s look at the predicted probabilities for each of the top 3 choices. First we compute
11381138
the probabilities by applying the softmax to the logits in `img_preds`. Note that
11391139
we have had to call the `detach()` method on the tensor `img_preds` in order to convert
1140-
it to our a more familiar `ndarray`.
1140+
it to a more familiar `ndarray`.
11411141

11421142
```{python}
11431143
img_probs = np.exp(np.asarray(img_preds.detach()))

Ch12-unsup-lab.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
In this lab we demonstrate PCA and clustering on several datasets.
1111
As in other labs, we import some of our libraries at this top
1212
level. This makes the code more readable, as scanning the first few
13-
lines of the notebook tell us what libraries are used in this
13+
lines of the notebook tells us what libraries are used in this
1414
notebook.
1515

1616
```{python}
@@ -837,7 +837,7 @@ ax.axhline(140, c='r', linewidth=4);
837837
838838
```
839839

840-
The `axhline()` function draws a horizontal line line on top of any
840+
The `axhline()` function draws a horizontal line on top of any
841841
existing set of axes. The argument `140` plots a horizontal
842842
line at height 140 on the dendrogram; this is a height that
843843
results in four distinct clusters. It is easy to verify that the

0 commit comments

Comments
 (0)