You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Ch02-statlearn-lab.Rmd
+4-3Lines changed: 4 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -836,7 +836,7 @@ A[1:4:2,0:3:2]
836
836
837
837
838
838
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
840
840
are treated differently by `numpy`.
841
841
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.
842
842
@@ -889,7 +889,8 @@ A[np.array([0,1,0,1])]
889
889
890
890
```
891
891
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`.
The symbol `&` computes an element-wise *and* operation.
1153
1154
As another example, suppose that we want to retrieve all `Ford` and `Datsun`
1154
1155
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
Copy file name to clipboardExpand all lines: Ch03-linreg-lab.Rmd
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -102,7 +102,7 @@ matrices (also called design matrices) using the `ModelSpec()` transform from `
102
102
103
103
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
104
104
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),
106
106
`age` (proportion of owner-occupied units built prior to 1940), and `lstat` (percent of
107
107
households with low socioeconomic status). We will use `statsmodels` for this
108
108
task, a `Python` package that implements several commonly used
@@ -252,7 +252,7 @@ We can produce confidence intervals for the predicted values.
252
252
new_predictions.conf_int(alpha=0.05)
253
253
254
254
```
255
-
Prediction intervals are computing by setting `obs=True`:
255
+
Prediction intervals are computed by setting `obs=True`:
256
256
257
257
```{python}
258
258
new_predictions.conf_int(obs=True, alpha=0.05)
@@ -286,7 +286,7 @@ def abline(ax, b, m):
286
286
```
287
287
A few things are illustrated above. First we see the syntax for defining a function:
288
288
`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
290
290
`m` is the slope of the desired line. Other plotting options can be passed on to
291
291
`ax.plot` by including additional optional arguments as follows:
292
292
@@ -539,7 +539,7 @@ and `lstat`.
539
539
540
540
The function `anova_lm()` can take more than two nested models
541
541
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
543
543
there is no previous model with which to compare the first.
Copy file name to clipboardExpand all lines: Ch05-resample-lab.Rmd
+9-8Lines changed: 9 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -88,7 +88,7 @@ fit is $23.62$.
88
88
89
89
We can also estimate the validation error for
90
90
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.
92
92
93
93
```{python}
94
94
def evalMSE(terms,
@@ -195,7 +195,7 @@ object with the appropriate `fit()`, `predict()`,
195
195
and `score()` methods, an
196
196
array of features `X` and a response `Y`.
197
197
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
199
199
corresponding to the total number of observations, which results in
200
200
leave-one-out cross-validation (LOOCV). The `cross_validate()` function produces a dictionary with several components;
201
201
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)
243
243
244
244
```
245
245
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
248
248
polynomial fits of degrees one to five.
249
249
250
250
```{python}
@@ -264,7 +264,7 @@ cv_error
264
264
```
265
265
Notice that the computation time is much shorter than that of LOOCV.
266
266
(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
268
268
availability of the formula~(\ref{Ch5:eq:LOOCVform}) for LOOCV;
269
269
however, the generic `cross_validate()` function does not make
270
270
use of this formula.) We still see little evidence that using cubic
@@ -273,8 +273,9 @@ using a quadratic fit.
273
273
274
274
275
275
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.
278
279
279
280
```{python}
280
281
validation = ShuffleSplit(n_splits=1,
@@ -511,7 +512,7 @@ standard formulas given in
511
512
rely on certain assumptions. For example,
512
513
they depend on the unknown parameter $\sigma^2$, the noise
513
514
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
515
516
correct, the estimate for $\sigma^2$ does. We see
516
517
{in Figure~\ref{Ch3:polyplot} on page~\pageref{Ch3:polyplot}} that there is
517
518
a non-linear relationship in the data, and so the residuals from a
Copy file name to clipboardExpand all lines: Ch06-varselect-lab.Rmd
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -334,7 +334,7 @@ The function `fit_path()` returns a list whose values include the fitted coeffic
334
334
path[3]
335
335
336
336
```
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`.
338
338
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.
339
339
340
340
## Ridge Regression and the Lasso
@@ -913,6 +913,6 @@ ax.set_ylim([50000,250000]);
913
913
```
914
914
915
915
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.
0 commit comments