Skip to content

Commit b7ff321

Browse files
committed
Cleaned charts/data handling; fixed outdated norm.rvs() parameterization
1 parent 7f1428c commit b7ff321

File tree

6 files changed

+42
-48
lines changed

6 files changed

+42
-48
lines changed

‎ch11/Makefile‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

‎ch11/demo_corr.py‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
importscipy
1313
fromscipy.statsimportnorm, pearsonr
1414

15-
DATA_DIR=os.path.join("..", "data")
16-
CHART_DIR=os.path.join("..", "charts")
15+
fromutilsimportCHART_DIR
1716

1817

1918
def_plot_correlation_func(x, y):
@@ -39,19 +38,19 @@ def plot_correlation_demo():
3938
x=np.arange(0, 10, 0.2)
4039

4140
pylab.subplot(221)
42-
y=0.5*x+norm.rvs(1, loc=0, scale=.01, size=len(x))
41+
y=0.5*x+norm.rvs(1, scale=.01, size=len(x))
4342
_plot_correlation_func(x, y)
4443

4544
pylab.subplot(222)
46-
y=0.5*x+norm.rvs(1, loc=0, scale=.1, size=len(x))
45+
y=0.5*x+norm.rvs(1, scale=.1, size=len(x))
4746
_plot_correlation_func(x, y)
4847

4948
pylab.subplot(223)
50-
y=0.5*x+norm.rvs(1, loc=0, scale=1, size=len(x))
49+
y=0.5*x+norm.rvs(1, scale=1, size=len(x))
5150
_plot_correlation_func(x, y)
5251

5352
pylab.subplot(224)
54-
y=norm.rvs(1, loc=0, scale=10, size=len(x))
53+
y=norm.rvs(1, scale=10, size=len(x))
5554
_plot_correlation_func(x, y)
5655

5756
pylab.autoscale(tight=True)
@@ -66,19 +65,19 @@ def plot_correlation_demo():
6665
x=np.arange(-5, 5, 0.2)
6766

6867
pylab.subplot(221)
69-
y=0.5*x**2+norm.rvs(1, loc=0, scale=.01, size=len(x))
68+
y=0.5*x**2+norm.rvs(1, scale=.01, size=len(x))
7069
_plot_correlation_func(x, y)
7170

7271
pylab.subplot(222)
73-
y=0.5*x**2+norm.rvs(1, loc=0, scale=.1, size=len(x))
72+
y=0.5*x**2+norm.rvs(1, scale=.1, size=len(x))
7473
_plot_correlation_func(x, y)
7574

7675
pylab.subplot(223)
77-
y=0.5*x**2+norm.rvs(1, loc=0, scale=1, size=len(x))
76+
y=0.5*x**2+norm.rvs(1, scale=1, size=len(x))
7877
_plot_correlation_func(x, y)
7978

8079
pylab.subplot(224)
81-
y=0.5*x**2+norm.rvs(1, loc=0, scale=10, size=len(x))
80+
y=0.5*x**2+norm.rvs(1, scale=10, size=len(x))
8281
_plot_correlation_func(x, y)
8382

8483
pylab.autoscale(tight=True)

‎ch11/demo_mds.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
fromsklearnimportlinear_model, manifold, decomposition, datasets
1515
logistic=linear_model.LogisticRegression()
1616

17-
18-
CHART_DIR=os.path.join("..", "charts")
17+
fromutilsimportCHART_DIR
1918

2019
np.random.seed(3)
2120

‎ch11/demo_mi.py‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
importnumpyasnp
1212
fromscipy.statsimportnorm, entropy
1313

14-
DATA_DIR=os.path.join("..", "data")
15-
CHART_DIR=os.path.join("..", "charts")
14+
fromutilsimportCHART_DIR
1615

1716

1817
defmutual_info(x, y, bins=10):
@@ -73,19 +72,19 @@ def plot_mi_demo():
7372
x=np.arange(0, 10, 0.2)
7473

7574
pylab.subplot(221)
76-
y=0.5*x+norm.rvs(1, loc=0, scale=.01, size=len(x))
75+
y=0.5*x+norm.rvs(1, scale=.01, size=len(x))
7776
_plot_mi_func(x, y)
7877

7978
pylab.subplot(222)
80-
y=0.5*x+norm.rvs(1, loc=0, scale=.1, size=len(x))
79+
y=0.5*x+norm.rvs(1, scale=.1, size=len(x))
8180
_plot_mi_func(x, y)
8281

8382
pylab.subplot(223)
84-
y=0.5*x+norm.rvs(1, loc=0, scale=1, size=len(x))
83+
y=0.5*x+norm.rvs(1, scale=1, size=len(x))
8584
_plot_mi_func(x, y)
8685

8786
pylab.subplot(224)
88-
y=norm.rvs(1, loc=0, scale=10, size=len(x))
87+
y=norm.rvs(1, scale=10, size=len(x))
8988
_plot_mi_func(x, y)
9089

9190
pylab.autoscale(tight=True)
@@ -100,19 +99,19 @@ def plot_mi_demo():
10099
x=np.arange(-5, 5, 0.2)
101100

102101
pylab.subplot(221)
103-
y=0.5*x**2+norm.rvs(1, loc=0, scale=.01, size=len(x))
102+
y=0.5*x**2+norm.rvs(1, scale=.01, size=len(x))
104103
_plot_mi_func(x, y)
105104

106105
pylab.subplot(222)
107-
y=0.5*x**2+norm.rvs(1, loc=0, scale=.1, size=len(x))
106+
y=0.5*x**2+norm.rvs(1, scale=.1, size=len(x))
108107
_plot_mi_func(x, y)
109108

110109
pylab.subplot(223)
111-
y=0.5*x**2+norm.rvs(1, loc=0, scale=1, size=len(x))
110+
y=0.5*x**2+norm.rvs(1, scale=1, size=len(x))
112111
_plot_mi_func(x, y)
113112

114113
pylab.subplot(224)
115-
y=0.5*x**2+norm.rvs(1, loc=0, scale=10, size=len(x))
114+
y=0.5*x**2+norm.rvs(1, scale=10, size=len(x))
116115
_plot_mi_func(x, y)
117116

118117
pylab.autoscale(tight=True)

‎ch11/demo_pca.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
logistic=linear_model.LogisticRegression()
1717

1818

19-
CHART_DIR=os.path.join("..", "charts")
19+
fromutilsimportCHART_DIR
2020

2121
np.random.seed(3)
2222

2323
x1=np.arange(0, 10, .2)
24-
x2=x1+np.random.normal(loc=0, scale=1, size=len(x1))
24+
x2=x1+np.random.normal(scale=1, size=len(x1))
2525

2626

2727
defplot_simple_demo_1():
@@ -35,7 +35,7 @@ def plot_simple_demo_1():
3535
pylab.ylabel("$X_2$")
3636

3737
x1=np.arange(0, 10, .2)
38-
x2=x1+np.random.normal(loc=0, scale=1, size=len(x1))
38+
x2=x1+np.random.normal(scale=1, size=len(x1))
3939

4040
good= (x1>5) | (x2>5)
4141
bad=~good
@@ -89,7 +89,7 @@ def plot_simple_demo_2():
8989
pylab.ylabel("$X_2$")
9090

9191
x1=np.arange(0, 10, .2)
92-
x2=x1+np.random.normal(loc=0, scale=1, size=len(x1))
92+
x2=x1+np.random.normal(scale=1, size=len(x1))
9393

9494
good=x1>x2
9595
bad=~good

‎ch11/utils.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This code is supporting material for the book
2+
# Building Machine Learning Systems with Python
3+
# by Willi Richert and Luis Pedro Coelho
4+
# published by PACKT Publishing
5+
#
6+
# It is made available under the MIT License
7+
8+
importos
9+
10+
DATA_DIR=os.path.join(
11+
os.path.dirname(os.path.realpath(__file__)), "data")
12+
13+
CHART_DIR=os.path.join(
14+
os.path.dirname(os.path.realpath(__file__)), "charts")
15+
16+
fordin [DATA_DIR, CHART_DIR]:
17+
ifnotos.path.exists(d):
18+
os.mkdir(d)
19+

0 commit comments

Comments
(0)