質問編集履歴
3
間違っていた点の修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
kerasでcsvデータを
|
1
|
+
kerasでcsvデータを正規化する
|
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
---
|
4
4
|
|
5
|
-
kerasでcsvデータを学習ができるように
|
5
|
+
kerasでcsvデータを学習ができるように正規化したいと思っています。しかしいろいろ検索をかけてはみたのですがよくわかりませんでした。なのでcsvデータを正規化する方法を教えていただきたいです。
|
6
6
|
|
7
7
|
以下の画像は使用したcsvデータです
|
8
8
|
|
@@ -16,25 +16,11 @@
|
|
16
16
|
|
17
17
|
import keras
|
18
18
|
|
19
|
-
import math
|
20
|
-
|
21
19
|
import pandas as pd
|
22
|
-
|
23
|
-
import numpy as np
|
24
|
-
|
25
|
-
import matplotlib.pyplot as plt
|
26
|
-
|
27
|
-
from keras import models
|
28
|
-
|
29
|
-
from keras import layers
|
30
|
-
|
31
|
-
from keras import optimizers
|
32
20
|
|
33
21
|
from pandas import Series,DataFrame
|
34
22
|
|
35
23
|
from keras.utils import to_categorical
|
36
|
-
|
37
|
-
from keras.optimizers import RMSprop
|
38
24
|
|
39
25
|
|
40
26
|
|
@@ -48,47 +34,13 @@
|
|
48
34
|
|
49
35
|
|
50
36
|
|
51
|
-
#
|
37
|
+
#正規化
|
52
38
|
|
53
39
|
k_data=k_data.values
|
54
40
|
|
55
41
|
k_data = k_data.astype(np.float)
|
56
42
|
|
57
43
|
k_label = keras.utils.to_categorical(k_label,25)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
#モデルの定義
|
62
|
-
|
63
|
-
model=models.Sequential()
|
64
|
-
|
65
|
-
model.add(layers.Dense(60,activation='relu',input_shape=(28*28,)))
|
66
|
-
|
67
|
-
model.add(layers.Dense(60,activation='relu'))
|
68
|
-
|
69
|
-
model.add(layers.Dense(60,activation='relu'))
|
70
|
-
|
71
|
-
model.add(layers.Dense(25,activation='softmax'))
|
72
|
-
|
73
|
-
model.compile(optimizer=optimizers.RMSprop(lr=0.01),loss='mse',metrics=['accuracy'])
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
#検証データセットの設定
|
78
|
-
|
79
|
-
data_val=k_data[:5000]
|
80
|
-
|
81
|
-
partial_k_data=k_data[5000:]
|
82
|
-
|
83
|
-
label_val=k_label[:5000]
|
84
|
-
|
85
|
-
partial_k_label=k_label[5000:]
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
#モデルの訓練
|
90
|
-
|
91
|
-
history=model.fit(partial_k_data,partial_k_label,epochs=20,batch_size=200,validation_data=(data_val,label_val))
|
92
44
|
|
93
45
|
|
94
46
|
|
@@ -103,14 +55,6 @@
|
|
103
55
|
print('k_label')
|
104
56
|
|
105
57
|
print(k_label)
|
106
|
-
|
107
|
-
print('----------')
|
108
|
-
|
109
|
-
results=model.evaluate(data_val,label_val)
|
110
|
-
|
111
|
-
print('results')
|
112
|
-
|
113
|
-
print(results)
|
114
58
|
|
115
59
|
```
|
116
60
|
|
@@ -146,10 +90,4 @@
|
|
146
90
|
|
147
91
|
[0. 0. 0. ... 0. 1. 0.]]
|
148
92
|
|
149
|
-
----------
|
150
|
-
|
151
|
-
results
|
152
|
-
|
153
|
-
[0.07694398815631867, 0.03819999843835831]
|
154
|
-
|
155
93
|
```
|
2
足りない点を補った
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
kerasで
|
1
|
+
kerasでcsvデータを用いた学習
|
test
CHANGED
File without changes
|
1
足りない点を補った
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,19 +16,31 @@
|
|
16
16
|
|
17
17
|
import keras
|
18
18
|
|
19
|
+
import math
|
20
|
+
|
19
21
|
import pandas as pd
|
20
22
|
|
21
23
|
import numpy as np
|
24
|
+
|
25
|
+
import matplotlib.pyplot as plt
|
26
|
+
|
27
|
+
from keras import models
|
28
|
+
|
29
|
+
from keras import layers
|
30
|
+
|
31
|
+
from keras import optimizers
|
22
32
|
|
23
33
|
from pandas import Series,DataFrame
|
24
34
|
|
25
35
|
from keras.utils import to_categorical
|
26
36
|
|
37
|
+
from keras.optimizers import RMSprop
|
27
38
|
|
28
39
|
|
40
|
+
|
41
|
+
#csv読み込み
|
42
|
+
|
29
43
|
sign_train = pd.read_csv("sign_mnist_train.csv",sep=",",header=0)
|
30
|
-
|
31
|
-
|
32
44
|
|
33
45
|
k_data=DataFrame(sign_train.drop("label",axis=1))
|
34
46
|
|
@@ -36,17 +48,69 @@
|
|
36
48
|
|
37
49
|
|
38
50
|
|
51
|
+
#ベクトル化
|
52
|
+
|
53
|
+
k_data=k_data.values
|
54
|
+
|
39
55
|
k_data = k_data.astype(np.float)
|
40
56
|
|
41
57
|
k_label = keras.utils.to_categorical(k_label,25)
|
42
58
|
|
43
59
|
|
44
60
|
|
61
|
+
#モデルの定義
|
62
|
+
|
63
|
+
model=models.Sequential()
|
64
|
+
|
65
|
+
model.add(layers.Dense(60,activation='relu',input_shape=(28*28,)))
|
66
|
+
|
67
|
+
model.add(layers.Dense(60,activation='relu'))
|
68
|
+
|
69
|
+
model.add(layers.Dense(60,activation='relu'))
|
70
|
+
|
71
|
+
model.add(layers.Dense(25,activation='softmax'))
|
72
|
+
|
73
|
+
model.compile(optimizer=optimizers.RMSprop(lr=0.01),loss='mse',metrics=['accuracy'])
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
#検証データセットの設定
|
78
|
+
|
79
|
+
data_val=k_data[:5000]
|
80
|
+
|
81
|
+
partial_k_data=k_data[5000:]
|
82
|
+
|
83
|
+
label_val=k_label[:5000]
|
84
|
+
|
85
|
+
partial_k_label=k_label[5000:]
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
#モデルの訓練
|
90
|
+
|
91
|
+
history=model.fit(partial_k_data,partial_k_label,epochs=20,batch_size=200,validation_data=(data_val,label_val))
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
#結果表示
|
96
|
+
|
97
|
+
print('k_data')
|
98
|
+
|
45
99
|
print(k_data)
|
46
100
|
|
47
101
|
print('----------')
|
48
102
|
|
103
|
+
print('k_label')
|
104
|
+
|
49
105
|
print(k_label)
|
106
|
+
|
107
|
+
print('----------')
|
108
|
+
|
109
|
+
results=model.evaluate(data_val,label_val)
|
110
|
+
|
111
|
+
print('results')
|
112
|
+
|
113
|
+
print(results)
|
50
114
|
|
51
115
|
```
|
52
116
|
|
@@ -56,29 +120,21 @@
|
|
56
120
|
|
57
121
|
```
|
58
122
|
|
59
|
-
|
123
|
+
k_data
|
60
124
|
|
125
|
+
[[107. 118. ... 203. 202.]
|
61
126
|
|
127
|
+
[155. 157. ... 135. 149.]
|
62
128
|
|
63
|
-
|
129
|
+
...
|
64
130
|
|
131
|
+
[177. 181. ... 87. 93.]
|
65
132
|
|
66
|
-
|
67
|
-
155.0 157.0 ... 135.0 149.0
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
... ... ... ... ...
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
179.
|
133
|
+
[179. 180. ... 209. 215.]]
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
[27455 roes × 784 columns]
|
80
134
|
|
81
135
|
----------
|
136
|
+
|
137
|
+
k_label
|
82
138
|
|
83
139
|
[[0. 0. 0. ... 0. 0. 0.]
|
84
140
|
|
@@ -90,4 +146,10 @@
|
|
90
146
|
|
91
147
|
[0. 0. 0. ... 0. 1. 0.]]
|
92
148
|
|
149
|
+
----------
|
150
|
+
|
151
|
+
results
|
152
|
+
|
153
|
+
[0.07694398815631867, 0.03819999843835831]
|
154
|
+
|
93
155
|
```
|