質問編集履歴
2
誤字脱字の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -76,10 +76,6 @@
|
|
76
76
|
|
77
77
|
df2 = pd.read_csv("y_train.csv")
|
78
78
|
|
79
|
-
#df2.fillna(0)
|
80
|
-
|
81
|
-
#print(df2)
|
82
|
-
|
83
79
|
x_ = df1.iloc[:, 0:6].as_matrix()
|
84
80
|
|
85
81
|
y_ = df2.iloc[:, 0:9].as_matrix()
|
@@ -101,10 +97,6 @@
|
|
101
97
|
df1 = pd.read_csv("x_test.csv")
|
102
98
|
|
103
99
|
df2 = pd.read_csv("y_test.csv")
|
104
|
-
|
105
|
-
#df2.fillna(0)
|
106
|
-
|
107
|
-
#print(df2)
|
108
100
|
|
109
101
|
x_ = df1.iloc[:, 0:6].as_matrix()
|
110
102
|
|
1
コードの追加。
test
CHANGED
File without changes
|
test
CHANGED
@@ -51,3 +51,123 @@
|
|
51
51
|
python3.6
|
52
52
|
|
53
53
|
tensorflow1.2.1
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
コードは以下の通りです。
|
58
|
+
|
59
|
+
ただし、いろいろいじっているので他のエラーを起こすかもしれません。
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
# データのインポート
|
64
|
+
|
65
|
+
import tensorflow as tf
|
66
|
+
|
67
|
+
import numpy as np
|
68
|
+
|
69
|
+
import pandas as pd
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
def train_read():
|
74
|
+
|
75
|
+
df1 = pd.read_csv("x_train.csv")
|
76
|
+
|
77
|
+
df2 = pd.read_csv("y_train.csv")
|
78
|
+
|
79
|
+
#df2.fillna(0)
|
80
|
+
|
81
|
+
#print(df2)
|
82
|
+
|
83
|
+
x_ = df1.iloc[:, 0:6].as_matrix()
|
84
|
+
|
85
|
+
y_ = df2.iloc[:, 0:9].as_matrix()
|
86
|
+
|
87
|
+
return x_,y_
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
train_x, train_y = train_read()
|
92
|
+
|
93
|
+
print(np.shape(train_x))
|
94
|
+
|
95
|
+
print(np.shape(train_y))
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
def test_read():
|
100
|
+
|
101
|
+
df1 = pd.read_csv("x_test.csv")
|
102
|
+
|
103
|
+
df2 = pd.read_csv("y_test.csv")
|
104
|
+
|
105
|
+
#df2.fillna(0)
|
106
|
+
|
107
|
+
#print(df2)
|
108
|
+
|
109
|
+
x_ = df1.iloc[:, 0:6].as_matrix()
|
110
|
+
|
111
|
+
y_ = df2.iloc[:, 0:9].as_matrix()
|
112
|
+
|
113
|
+
return x_,y_
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
test_x,test_y = test_read()
|
118
|
+
|
119
|
+
print(np.shape(test_x))
|
120
|
+
|
121
|
+
print(np.shape(test_y))
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
# モデルの作成
|
126
|
+
|
127
|
+
x = tf.placeholder(tf.float32, [None, 6])
|
128
|
+
|
129
|
+
w = tf.Variable(tf.zeros([6, 9]))
|
130
|
+
|
131
|
+
b = tf.Variable(tf.zeros([9]))
|
132
|
+
|
133
|
+
y = tf.nn.softmax(tf.matmul(x, w) + b)
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
# 損失とオプティマイザーを定義
|
138
|
+
|
139
|
+
y_ = tf.placeholder(tf.float32, [None, 9])
|
140
|
+
|
141
|
+
cross_entropy = -tf.reduce_sum(y_ * tf.log(y))
|
142
|
+
|
143
|
+
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
# 精度
|
148
|
+
|
149
|
+
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
|
150
|
+
|
151
|
+
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
# 訓練
|
156
|
+
|
157
|
+
sess = tf.Session()
|
158
|
+
|
159
|
+
sess.run(tf.global_variables_initializer())
|
160
|
+
|
161
|
+
saver = tf.train.Saver()
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
for i in range(101):
|
166
|
+
|
167
|
+
sess.run(train_step, feed_dict={x: train_x, y_: train_y})
|
168
|
+
|
169
|
+
if i % 10 == 0:
|
170
|
+
|
171
|
+
acc, cost = sess.run([accuracy, cross_entropy], feed_dict={x: test_x, y_: test_y})
|
172
|
+
|
173
|
+
print('Step: %d, Accuracy: %f, Loss: %f' % (i, acc, cost))
|