Skip to content

Commit d1caac3

Browse files
authored
Merge pull request #2 from mbrukman/update-python-from-notebook
Re-generate Python code from IPython notebooks
2 parents 8e5c2d2 + 6aade64 commit d1caac3

File tree

14 files changed

+111
-35
lines changed

14 files changed

+111
-35
lines changed

ch03/ch03.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def loss_0(z):
283283

284284
plt.ylim(0.0, 5.1)
285285
plt.xlim([0, 1])
286-
plt.xlabel('$\sigma$(z)')
286+
plt.xlabel('$\sigma(z)$')
287287
plt.ylabel('L(w, b)')
288288
plt.legend(loc='best')
289289
plt.tight_layout()

ch04/ch04.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@
448448

449449

450450

451+
451452
LogisticRegression(penalty='l1')
452453

453454

ch07/ch07.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,3 +890,8 @@ def get_params(self, deep=True):
890890

891891

892892

893+
894+
895+
896+
897+

ch08/ch08.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ def get_minibatch(doc_stream, size):
700700

701701

702702
n_top_words = 5
703-
feature_names = count.get_feature_names()
703+
feature_names = count.get_feature_names_out()
704704

705705
for topic_idx, topic in enumerate(lda.components_):
706706
print(f'Topic {(topic_idx + 1)}:')

ch09/ch09.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,3 +877,8 @@ def mean_absolute_deviation(data):
877877

878878

879879

880+
881+
882+
883+
884+

ch13/ch13_part1.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,8 @@ def predict(self, x):
579579

580580

581581

582+
583+
584+
585+
586+

ch13/ch13_part3_lightning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969

7070
class MultiLayerPerceptron(pl.LightningModule):
71-
def __init__(self,image_shape=(1, 28, 28), hidden_units=(32, 16)):
71+
def __init__(self, image_shape=(1, 28, 28), hidden_units=(32, 16)):
7272
super().__init__()
7373

7474
# new PL attributes:

ch13/ch13_part4_ignite.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# coding: utf-8
22

33

4+
import sys
5+
from python_environment_check import check_packages
46
import torch
57
import torch.nn as nn
68
from torch.utils.data import DataLoader
@@ -11,6 +13,37 @@
1113
from ignite.handlers import Checkpoint, DiskSaver
1214
from ignite.contrib.handlers import TensorboardLogger, global_step_from_engine
1315

16+
17+
18+
19+
20+
21+
# # Machine Learning with PyTorch and Scikit-Learn
22+
# # -- Code Examples
23+
24+
# ## Package version checks
25+
26+
# Add folder to path in order to load from the check_packages.py script:
27+
28+
29+
30+
sys.path.insert(0, '..')
31+
32+
33+
# Check recommended package versions:
34+
35+
36+
37+
38+
39+
d = {
40+
'numpy': '1.21.2',
41+
'matplotlib': '3.4.3',
42+
'sklearn': '1.0',
43+
}
44+
check_packages(d)
45+
46+
1447
# # Chapter 13: Going Deeper -- the Mechanics of PyTorch
1548

1649
# **Big thanks and credit to Victor Fomin for creating and helping with the original draft of this section!**

ch15/ch15_part2.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,3 @@ def forward(self, text, lengths):
410410

411411

412412

413-
414-
415-
416-
417-

ch15/ch15_part3.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def __getitem__(self, idx):
179179

180180
class RNN(nn.Module):
181181
def __init__(self, vocab_size, embed_dim, rnn_hidden_size):
182-
super(RNN, self).__init__()
182+
super().__init__()
183183
self.embedding = nn.Embedding(vocab_size, embed_dim)
184184
self.rnn_hidden_size = rnn_hidden_size
185185
self.rnn = nn.LSTM(embed_dim, rnn_hidden_size,
@@ -365,8 +365,3 @@ def sample(model, starting_str,
365365

366366

367367

368-
369-
370-
371-
372-

0 commit comments

Comments
 (0)