質問編集履歴
4
ソースコードのシンタックスハイライト
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
### 発生している問題・エラーメッセージ
|
14
14
|
|
15
|
-
---------------------------------------------------------------------------
|
15
|
+
```---------------------------------------------------------------------------
|
16
16
|
|
17
17
|
TypeError Traceback (most recent call last)
|
18
18
|
|
@@ -204,10 +204,18 @@
|
|
204
204
|
|
205
205
|
<Figure size 684x288 with 2 Axes>
|
206
206
|
|
207
|
+
```ここに言語を入力
|
208
|
+
|
209
|
+
コード
|
210
|
+
|
211
|
+
```
|
212
|
+
|
207
213
|
|
208
214
|
|
209
215
|
### 該当のソースコード
|
210
216
|
|
217
|
+
|
218
|
+
|
211
219
|
import numpy as np
|
212
220
|
|
213
221
|
import matplotlib.pyplot as plt
|
@@ -230,27 +238,23 @@
|
|
230
238
|
|
231
239
|
T = Prm_c[0] - Prm_c[1]*np.exp(-Prm_c[2]*X)\
|
232
240
|
|
233
|
-
|
241
|
+
+ 4*np.random.randn(X_n)
|
234
242
|
|
235
243
|
np.savez('ch5_data.npz', X=X, X_min=X_min, X_max=X_max, X_n=X_n, T=T)
|
236
244
|
|
237
245
|
|
238
246
|
|
239
|
-
|
240
|
-
|
241
247
|
from mpl_toolkits.mplot3d import Axes3D
|
242
248
|
|
243
249
|
|
244
250
|
|
245
251
|
def mse_line(x, t, w):
|
246
252
|
|
247
|
-
|
253
|
+
y = w[0]*x + w[1]
|
248
|
-
|
254
|
+
|
249
|
-
|
255
|
+
mse = np.mean((y - t)**2)
|
250
|
-
|
256
|
+
|
251
|
-
|
257
|
+
return mse
|
252
|
-
|
253
|
-
|
254
258
|
|
255
259
|
|
256
260
|
|
@@ -270,11 +274,11 @@
|
|
270
274
|
|
271
275
|
for i0 in range(xn):
|
272
276
|
|
273
|
-
|
277
|
+
for i1 in range(xn):
|
274
|
-
|
278
|
+
|
275
|
-
|
279
|
+
J[i1,i0] = mse_line(X, T, (x0[i0], x1[i1]))
|
276
|
-
|
277
|
-
|
280
|
+
|
281
|
+
|
278
282
|
|
279
283
|
plt.figure(figsize=(9.5, 4))
|
280
284
|
|
@@ -286,7 +290,7 @@
|
|
286
290
|
|
287
291
|
ax.plot_surface(xx0, xx1, J, rstride=10, cstride=10, alpha=0.3,
|
288
292
|
|
289
|
-
|
293
|
+
color='blue', edgecolor='black')
|
290
294
|
|
291
295
|
ax.set_xticks([-20, 0, 20])
|
292
296
|
|
@@ -300,7 +304,7 @@
|
|
300
304
|
|
301
305
|
cont = plt.contour(xx0, xx1, J, 30, colors='black',
|
302
306
|
|
303
|
-
|
307
|
+
levels=[100,1000,10000,100000])
|
304
308
|
|
305
309
|
cont.clabel(fmt='%1.0f', fontsize=8)
|
306
310
|
|
@@ -308,7 +312,11 @@
|
|
308
312
|
|
309
313
|
plt.show()
|
310
314
|
|
311
|
-
|
315
|
+
```ここに言語を入力
|
316
|
+
|
317
|
+
コード
|
318
|
+
|
319
|
+
```
|
312
320
|
|
313
321
|
### 試行錯誤したこと
|
314
322
|
|
3
エラーメッセージ、ソースコードの補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,8 +8,196 @@
|
|
8
8
|
|
9
9
|
本のコードをそのまま打ち込んでいるため、全体的にまだ意味が分かっておらず、どこを直すべきなのかもよく分かりません、、
|
10
10
|
|
11
|
+
|
12
|
+
|
11
13
|
### 発生している問題・エラーメッセージ
|
12
14
|
|
15
|
+
---------------------------------------------------------------------------
|
16
|
+
|
17
|
+
TypeError Traceback (most recent call last)
|
18
|
+
|
19
|
+
~\Downloads\anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
|
20
|
+
|
21
|
+
339 pass
|
22
|
+
|
23
|
+
340 else:
|
24
|
+
|
25
|
+
--> 341 return printer(obj)
|
26
|
+
|
27
|
+
342 # Finally look for special method names
|
28
|
+
|
29
|
+
343 method = get_real_method(obj, self.print_method)
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
~\Downloads\anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
|
34
|
+
|
35
|
+
239
|
36
|
+
|
37
|
+
240 if 'png' in formats:
|
38
|
+
|
39
|
+
--> 241 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
|
40
|
+
|
41
|
+
242 if 'retina' in formats or 'png2x' in formats:
|
42
|
+
|
43
|
+
243 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
~\Downloads\anaconda3\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
|
48
|
+
|
49
|
+
123
|
50
|
+
|
51
|
+
124 bytes_io = BytesIO()
|
52
|
+
|
53
|
+
--> 125 fig.canvas.print_figure(bytes_io, **kw)
|
54
|
+
|
55
|
+
126 data = bytes_io.getvalue()
|
56
|
+
|
57
|
+
127 if fmt == 'svg':
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
~\Downloads\anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
|
62
|
+
|
63
|
+
2210 orientation=orientation,
|
64
|
+
|
65
|
+
2211 dryrun=True,
|
66
|
+
|
67
|
+
-> 2212 **kwargs)
|
68
|
+
|
69
|
+
2213 renderer = self.figure._cachedRenderer
|
70
|
+
|
71
|
+
2214 bbox_inches = self.figure.get_tightbbox(renderer)
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
~\Downloads\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
|
76
|
+
|
77
|
+
511
|
78
|
+
|
79
|
+
512 def print_png(self, filename_or_obj, *args, **kwargs):
|
80
|
+
|
81
|
+
--> 513 FigureCanvasAgg.draw(self)
|
82
|
+
|
83
|
+
514 renderer = self.get_renderer()
|
84
|
+
|
85
|
+
515 original_dpi = renderer.dpi
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
~\Downloads\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
|
90
|
+
|
91
|
+
431 # if toolbar:
|
92
|
+
|
93
|
+
432 # toolbar.set_cursor(cursors.WAIT)
|
94
|
+
|
95
|
+
--> 433 self.figure.draw(self.renderer)
|
96
|
+
|
97
|
+
434 # A GUI class may be need to update a window using this draw, so
|
98
|
+
|
99
|
+
435 # don't forget to call the superclass.
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
~\Downloads\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
|
104
|
+
|
105
|
+
53 renderer.start_filter()
|
106
|
+
|
107
|
+
54
|
108
|
+
|
109
|
+
---> 55 return draw(artist, renderer, *args, **kwargs)
|
110
|
+
|
111
|
+
56 finally:
|
112
|
+
|
113
|
+
57 if artist.get_agg_filter() is not None:
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
~\Downloads\anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
|
118
|
+
|
119
|
+
1473
|
120
|
+
|
121
|
+
1474 mimage._draw_list_compositing_images(
|
122
|
+
|
123
|
+
-> 1475 renderer, self, artists, self.suppressComposite)
|
124
|
+
|
125
|
+
1476
|
126
|
+
|
127
|
+
1477 renderer.close_group('figure')
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
~\Downloads\anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
|
132
|
+
|
133
|
+
139 if not_composite or not has_images:
|
134
|
+
|
135
|
+
140 for a in artists:
|
136
|
+
|
137
|
+
--> 141 a.draw(renderer)
|
138
|
+
|
139
|
+
142 else:
|
140
|
+
|
141
|
+
143 # Composite any adjacent images together
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
~\Downloads\anaconda3\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py in draw(self, renderer)
|
146
|
+
|
147
|
+
296 # Then axes
|
148
|
+
|
149
|
+
297 for ax in axes:
|
150
|
+
|
151
|
+
--> 298 ax.draw(renderer)
|
152
|
+
|
153
|
+
299
|
154
|
+
|
155
|
+
300 # Then rest
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
~\Downloads\anaconda3\lib\site-packages\mpl_toolkits\mplot3d\axis3d.py in draw(self, renderer)
|
160
|
+
|
161
|
+
228
|
162
|
+
|
163
|
+
229 # code from XAxis
|
164
|
+
|
165
|
+
--> 230 majorTicks = self.get_major_ticks()
|
166
|
+
|
167
|
+
231 majorLocs = self.major.locator()
|
168
|
+
|
169
|
+
232
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
~\Downloads\anaconda3\lib\site-packages\mpl_toolkits\mplot3d\axis3d.py in get_major_ticks(self, numticks)
|
174
|
+
|
175
|
+
146
|
176
|
+
|
177
|
+
147 def get_major_ticks(self, numticks=None):
|
178
|
+
|
179
|
+
--> 148 ticks = maxis.XAxis.get_major_ticks(self, numticks)
|
180
|
+
|
181
|
+
149 for t in ticks:
|
182
|
+
|
183
|
+
150 t.tick1line.set_transform(self.axes.transData)
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
~\Downloads\anaconda3\lib\site-packages\matplotlib\axis.py in get_major_ticks(self, numticks)
|
188
|
+
|
189
|
+
1394 'get the tick instances; grow as necessary'
|
190
|
+
|
191
|
+
1395 if numticks is None:
|
192
|
+
|
193
|
+
-> 1396 numticks = len(self.get_major_locator()())
|
194
|
+
|
195
|
+
1397
|
196
|
+
|
197
|
+
1398 while len(self.majorTicks) < numticks:
|
198
|
+
|
199
|
+
|
200
|
+
|
13
201
|
TypeError: len() of unsized object
|
14
202
|
|
15
203
|
|
@@ -20,6 +208,52 @@
|
|
20
208
|
|
21
209
|
### 該当のソースコード
|
22
210
|
|
211
|
+
import numpy as np
|
212
|
+
|
213
|
+
import matplotlib.pyplot as plt
|
214
|
+
|
215
|
+
%matplotlib inline
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
np.random.seed(seed=1)
|
220
|
+
|
221
|
+
X_min = 4
|
222
|
+
|
223
|
+
X_max = 30
|
224
|
+
|
225
|
+
X_n = 16
|
226
|
+
|
227
|
+
X = 5 + 25*np.random.rand(X_n)
|
228
|
+
|
229
|
+
Prm_c = [170, 108, 0.2]
|
230
|
+
|
231
|
+
T = Prm_c[0] - Prm_c[1]*np.exp(-Prm_c[2]*X)\
|
232
|
+
|
233
|
+
+ 4*np.random.randn(X_n)
|
234
|
+
|
235
|
+
np.savez('ch5_data.npz', X=X, X_min=X_min, X_max=X_max, X_n=X_n, T=T)
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
from mpl_toolkits.mplot3d import Axes3D
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
def mse_line(x, t, w):
|
246
|
+
|
247
|
+
y = w[0]*x + w[1]
|
248
|
+
|
249
|
+
mse = np.mean((y - t)**2)
|
250
|
+
|
251
|
+
return mse
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
23
257
|
xn = 100
|
24
258
|
|
25
259
|
w0_range = [-25, 25]
|
@@ -62,6 +296,20 @@
|
|
62
296
|
|
63
297
|
|
64
298
|
|
299
|
+
plt.subplot(1,2,2)
|
300
|
+
|
301
|
+
cont = plt.contour(xx0, xx1, J, 30, colors='black',
|
302
|
+
|
303
|
+
levels=[100,1000,10000,100000])
|
304
|
+
|
305
|
+
cont.clabel(fmt='%1.0f', fontsize=8)
|
306
|
+
|
307
|
+
plt.grid(True)
|
308
|
+
|
309
|
+
plt.show()
|
310
|
+
|
311
|
+
|
312
|
+
|
65
313
|
### 試行錯誤したこと
|
66
314
|
|
67
315
|
numpy,matplotlibがimportされているか確認しました。また、figsizeなどの数値を変えたりしてみましたが、駄目でした。
|
2
試行錯誤したことの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,13 +62,9 @@
|
|
62
62
|
|
63
63
|
|
64
64
|
|
65
|
-
|
65
|
+
### 試行錯誤したこと
|
66
66
|
|
67
|
-
|
67
|
+
numpy,matplotlibがimportされているか確認しました。また、figsizeなどの数値を変えたりしてみましたが、駄目でした。
|
68
|
-
|
69
|
-
```
|
70
|
-
|
71
|
-
|
72
68
|
|
73
69
|
|
74
70
|
|
@@ -78,6 +74,8 @@
|
|
78
74
|
|
79
75
|
windows 8.1 です。
|
80
76
|
|
77
|
+
Jupyter Notebookを使っています。
|
78
|
+
|
81
79
|
|
82
80
|
|
83
81
|
初心者すぎて色々と申し訳ありません、、分かる方いらっしゃいましたらよろしくお願いいたします。
|
1
質問の題名、内容を変更しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
TypeError: len() of unsized object エラーの正し方が分かりません
|
test
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
w空間における平均二乗誤差を表示したい
|
3
|
+
w空間における平均二乗誤差を表示したいのですが、エラーが出てしまいます。
|
4
|
+
|
5
|
+
「Pythonで動かして学ぶ!新しい機械学習の教科書」を使っていて、p150と同じコードです。
|
4
6
|
|
5
7
|
|
6
8
|
|