@@ -280,7 +280,7 @@ we call the `seed` function from the `numpy` package, and pass it any integer as
280
280
Below we use the seed number ` 1 ` . At
281
281
that point, Python will keep track of the randomness that occurs throughout the code.
282
282
For example, we can call the ` sample ` method
283
- on the series of numbers, passing the argument ` n = 10 ` to indicate that we want 10 samples.
283
+ on the series of numbers, passing the argument ` n= 10 ` to indicate that we want 10 samples.
284
284
285
285
``` {code-cell} ipython3
286
286
import numpy as np
@@ -290,7 +290,7 @@ np.random.seed(1)
290
290
291
291
nums_0_to_9 = pd.Series([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
292
292
293
- random_numbers1 = nums_0_to_9.sample(n = 10).to_numpy()
293
+ random_numbers1 = nums_0_to_9.sample(n= 10).to_numpy()
294
294
random_numbers1
295
295
```
296
296
You can see that ` random_numbers1 ` is a list of 10 numbers
@@ -299,7 +299,7 @@ we run the `sample` method again,
299
299
we will get a fresh batch of 10 numbers that also look random.
300
300
301
301
``` {code-cell} ipython3
302
- random_numbers2 = nums_0_to_9.sample(n = 10).to_numpy()
302
+ random_numbers2 = nums_0_to_9.sample(n= 10).to_numpy()
303
303
random_numbers2
304
304
```
305
305
@@ -309,12 +309,12 @@ as before---and then call the `sample` method again.
309
309
310
310
``` {code-cell} ipython3
311
311
np.random.seed(1)
312
- random_numbers1_again = nums_0_to_9.sample(n = 10).to_numpy()
312
+ random_numbers1_again = nums_0_to_9.sample(n= 10).to_numpy()
313
313
random_numbers1_again
314
314
```
315
315
316
316
``` {code-cell} ipython3
317
- random_numbers2_again = nums_0_to_9.sample(n = 10).to_numpy()
317
+ random_numbers2_again = nums_0_to_9.sample(n= 10).to_numpy()
318
318
random_numbers2_again
319
319
```
320
320
@@ -326,12 +326,12 @@ obtain a different sequence of random numbers.
326
326
327
327
``` {code-cell} ipython3
328
328
np.random.seed(4235)
329
- random_numbers = nums_0_to_9.sample(n = 10).to_numpy()
329
+ random_numbers = nums_0_to_9.sample(n= 10).to_numpy()
330
330
random_numbers
331
331
```
332
332
333
333
``` {code-cell} ipython3
334
- random_numbers = nums_0_to_9.sample(n = 10).to_numpy()
334
+ random_numbers = nums_0_to_9.sample(n= 10).to_numpy()
335
335
random_numbers
336
336
```
337
337
@@ -378,15 +378,15 @@ functions. Those functions will then use your `RandomState` to generate random n
378
378
`numpy`'s default generator. For example, we can reproduce our earlier example by using a `RandomState`
379
379
object with the `seed` value set to 1; we get the same lists of numbers once again.
380
380
```{code}
381
- rnd = np.random.RandomState(seed = 1)
382
- random_numbers1_third = nums_0_to_9.sample(n = 10, random_state = rnd).to_numpy()
381
+ rnd = np.random.RandomState(seed= 1)
382
+ random_numbers1_third = nums_0_to_9.sample(n= 10, random_state= rnd).to_numpy()
383
383
random_numbers1_third
384
384
```
385
385
```{code}
386
386
array([2, 9, 6, 4, 0, 3, 1, 7, 8, 5])
387
387
```
388
388
```{code}
389
- random_numbers2_third = nums_0_to_9.sample(n = 10, random_state = rnd).to_numpy()
389
+ random_numbers2_third = nums_0_to_9.sample(n= 10, random_state= rnd).to_numpy()
390
390
random_numbers2_third
391
391
```
392
392
```{code}
@@ -540,8 +540,8 @@ cancer_train["Class"].value_counts(normalize=True)
540
540
``` {code-cell} ipython3
541
541
:tags: [remove-cell]
542
542
543
- glue("cancer_train_b_prop", "{:0.0f}".format(cancer_train["Class"].value_counts(normalize = True)["Benign"]*100))
544
- glue("cancer_train_m_prop", "{:0.0f}".format(cancer_train["Class"].value_counts(normalize = True)["Malignant"]*100))
543
+ glue("cancer_train_b_prop", "{:0.0f}".format(cancer_train["Class"].value_counts(normalize= True)["Benign"]*100))
544
+ glue("cancer_train_m_prop", "{:0.0f}".format(cancer_train["Class"].value_counts(normalize= True)["Malignant"]*100))
545
545
```
546
546
547
547
### Preprocess the data
@@ -1620,7 +1620,7 @@ for i in range(len(ks)):
1620
1620
cancer_tune_pipe = make_pipeline(cancer_preprocessor, KNeighborsClassifier())
1621
1621
param_grid = {
1622
1622
"kneighborsclassifier__n_neighbors": range(1, 21),
1623
- } ## double check: in R textbook, it is tune_grid(..., grid = 20), so I guess it matches RandomizedSearchCV
1623
+ } ## double check: in R textbook, it is tune_grid(..., grid= 20), so I guess it matches RandomizedSearchCV
1624
1624
## instead of GridSeachCV?
1625
1625
# param_grid_rand = {
1626
1626
# "kneighborsclassifier__n_neighbors": range(1, 100),
0 commit comments