teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追記

2021/05/29 14:56

投稿

hayataka2049
hayataka2049

スコア30939

answer CHANGED
@@ -1,1 +1,25 @@
1
- 恒常関数の場合、何段重ねても線形写像しか作れないことになります。
1
+ 恒常関数の場合、何段重ねても線形写像しか作れないことになります。
2
+
3
+
4
+ ---
5
+
6
+ ```python
7
+ import numpy as np
8
+ import matplotlib.pyplot as plt
9
+ from sklearn.neural_network import MLPRegressor
10
+
11
+ X = np.linspace(0, 2*np.pi, num=100).reshape(-1, 1)
12
+ y = np.sin(X).ravel()
13
+
14
+ plt.plot(X.ravel(), y, label="true")
15
+ for hls in [(25, ), (50, ), (25, 25), (50, 50)]:
16
+ mlp = MLPRegressor(hidden_layer_sizes=hls, activation="relu",
17
+ max_iter=2000)
18
+ mlp.fit(X, y)
19
+ y_pred = mlp.predict(X)
20
+ plt.plot(X.ravel(), y_pred, label=f"pred hidden_layer_sizes:{hls}")
21
+ plt.legend()
22
+ plt.show()
23
+ ```
24
+
25
+ ![イメージ説明](2349f8c0a61414b249030e8529e3e575.png)