MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / fit

Method fit

unsupervised_class2/autoencoder_tf.py:130–167  ·  view source on GitHub ↗
(self, X, Y, Xtest, Ytest, pretrain=True, epochs=1, batch_sz=100)

Source from the content-addressed store, hash-verified

128 self.prediction = tf.argmax(input=logits, axis=1)
129
130 def fit(self, X, Y, Xtest, Ytest, pretrain=True, epochs=1, batch_sz=100):
131 N = len(X)
132
133 # greedy layer-wise training of autoencoders
134 pretrain_epochs = 1
135 if not pretrain:
136 pretrain_epochs = 0
137
138 current_input = X
139 for ae in self.hidden_layers:
140 ae.fit(current_input, epochs=pretrain_epochs)
141
142 # create current_input for the next layer
143 current_input = ae.transform(current_input)
144
145 n_batches = N // batch_sz
146 costs = []
147 print("supervised training...")
148 for i in range(epochs):
149 print("epoch:", i)
150 X, Y = shuffle(X, Y)
151 for j in range(n_batches):
152 Xbatch = X[j*batch_sz:(j*batch_sz + batch_sz)]
153 Ybatch = Y[j*batch_sz:(j*batch_sz + batch_sz)]
154 self.session.run(
155 self.train_op,
156 feed_dict={self.X: Xbatch, self.Y: Ybatch}
157 )
158 c, p = self.session.run(
159 (self.cost, self.prediction),
160 feed_dict={self.X: Xtest, self.Y: Ytest
161 })
162 error = error_rate(p, Ytest)
163 if j % 10 == 0:
164 print("j / n_batches:", j, "/", n_batches, "cost:", c, "error:", error)
165 costs.append(c)
166 plt.plot(costs)
167 plt.show()
168
169 def forward(self, X):
170 current_input = X

Callers 1

test_pretraining_dnnFunction · 0.95

Calls 3

error_rateFunction · 0.90
transformMethod · 0.45
runMethod · 0.45

Tested by 1

test_pretraining_dnnFunction · 0.76