質問編集履歴
2
予測用のコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -133,3 +133,45 @@
|
|
133
133
|
|
134
134
|
|
135
135
|
```
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
予測用のコード
|
140
|
+
|
141
|
+
```python
|
142
|
+
|
143
|
+
from keras.models import load_model
|
144
|
+
|
145
|
+
import numpy as np
|
146
|
+
|
147
|
+
import csv
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
test_data=[]
|
152
|
+
|
153
|
+
with open('test.csv') as f:
|
154
|
+
|
155
|
+
reader = csv.reader(f)
|
156
|
+
|
157
|
+
for row in reader:
|
158
|
+
|
159
|
+
test_data.append(row)
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
test_data1 = np.array(test_data,dtype=np.float64)
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
model = load_model("model.h5")
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
result = model.predict_classes(test_data1)
|
174
|
+
|
175
|
+
print(result)
|
176
|
+
|
177
|
+
```
|
1
修正後のソースコードを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -79,3 +79,57 @@
|
|
79
79
|
model.fit(train_data1,train_label1, epochs=300, validation_split=0.1)
|
80
80
|
|
81
81
|
```
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
修正後のソースコード
|
86
|
+
|
87
|
+
```python
|
88
|
+
|
89
|
+
# Sequentialモデル使用(Sequentialモデルはレイヤを順に重ねたモデル)
|
90
|
+
|
91
|
+
model = Sequential()
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
model.add(Dense(1900, activation='relu', input_shape = ( 950, )))
|
96
|
+
|
97
|
+
model.add(Dropout(0.5))
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
model.add(Dense(500, activation='relu'))
|
102
|
+
|
103
|
+
model.add(Dropout(0.5))
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
model.add(Dense(1, activation='linear'))
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
# モデルをコンパイル
|
112
|
+
|
113
|
+
model.compile(loss="mean_squared_error", optimizer="sgd", metrics=["accuracy"])
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
model.summary()
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
#訓練
|
122
|
+
|
123
|
+
model.fit(train_data1,train_label1, epochs=300, validation_split=0.1)
|
124
|
+
|
125
|
+
model.save('model.h5')
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
score = model.evaluate(test_data1, test_result1)
|
130
|
+
|
131
|
+
print("正解率: %.2f%%" % (score[1] * 100))
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
```
|