本文整理汇总了Python中LogisticRegression.LogisticRegression.getParametersAsValues方法的典型用法代码示例。如果您正苦于以下问题:Python LogisticRegression.getParametersAsValues方法的具体用法?Python LogisticRegression.getParametersAsValues怎么用?Python LogisticRegression.getParametersAsValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogisticRegression.LogisticRegression
的用法示例。
在下文中一共展示了LogisticRegression.getParametersAsValues方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evaluate_lenet5
# 需要导入模块: from LogisticRegression import LogisticRegression [as 别名]
# 或者: from LogisticRegression.LogisticRegression import getParametersAsValues [as 别名]
#.........这里部分代码省略.........
print(" Manipulating the training set")
train_set_x, train_set_y = Preprocessing.giveMeNewTraining()
n_train_batches = train_set_x.get_value(borrow=True).shape[0]
n_train_batches /= batch_size
validation_frequency = min(n_train_batches, patience / 2)
print(" Compiling new function")
learning_rate *= 0.993 #See Paper from Cican
train_model = theano.function([index], cost, updates=updates,
givens={
x: train_set_x[index * batch_size: (index + 1) * batch_size],
y: train_set_y[index * batch_size: (index + 1) * batch_size]})
print(" Finished compiling the training set")
epoch = epoch + 1
for minibatch_index in xrange(n_train_batches): #Alle einmal anfassen
iter = (epoch - 1) * n_train_batches + minibatch_index
epoch_fraction += 1.0 / float(n_train_batches)
if iter % 100 == 0:
print 'training @ iter = ', iter, ' epoch_fraction ', epoch_fraction
cost_ij = train_model(minibatch_index)
if (iter + 1) % validation_frequency == 0:
# compute zero-one loss on validation set
validation_losses = [validate_model(i) for i in xrange(n_valid_batches)]
this_validation_loss = numpy.mean(validation_losses)
# test it on the test set
test_start = time.clock();
test_losses = [test_model(i) for i in xrange(n_test_batches)]
train_costs = [train_model(i) for i in xrange(n_test_batches)]
dt = time.clock() - test_start
print'Testing %i faces in %f msec image / sec %f', batch_size * n_test_batches, dt, dt/(n_test_batches * batch_size)
test_score = numpy.mean(test_losses)
train_cost = numpy.mean(train_costs)
print('%i, %f, %f, %f, %f, 0.424242' % (epoch, this_validation_loss * 100.,test_score * 100., learning_rate, train_cost))
# if we got the best validation score until now
if this_validation_loss < best_validation_loss:
#improve patience if loss improvement is good enough
if this_validation_loss < best_validation_loss * improvement_threshold:
patience = max(patience, iter * patience_increase)
# save best validation score and iteration number
best_validation_loss = this_validation_loss
best_iter = iter
# # test it on the test set
# test_losses = [test_model(i) for i in xrange(n_test_batches)]
# test_score = numpy.mean(test_losses)
# print((' epoch %i, minibatch %i/%i, test error of best '
# 'model %f %%') %
# (epoch, minibatch_index + 1, n_train_batches,
# test_score * 100.))
# if (this_validation_loss < 0.02):
# learning_rate /= 2
# print("Decreased learning rate due to low xval error to " + str(learning_rate))
if patience <= iter:
print("--------- Finished Looping ----- earlier ")
done_looping = True
break
end_time = time.clock()
print('---------- Optimization complete -------------------------')
print('Res: ', str(topo.nkerns))
print('Res: ', learning_rate)
print('Res: Best validation score of %f %% obtained at iteration %i,' \
'with test performance %f %%' %
(best_validation_loss * 100., best_iter + 1, test_score * 100.))
print('Res: The code for file ' + os.path.split(__file__)[1] + ' ran for %.2fm' % ((end_time - start_time) / 60.))
# Oliver
if not os.path.isdir("conv_images"):
os.makedirs("conv_images")
os.chdir("conv_images")
# d = layer0.W.get_value() #e.g. (20, 1, 5, 5) number of filter, num of incomming filters, dim filter
# for i in range(0, numpy.shape(d)[0]):
# dd = d[i][0]
# rescaled = (255.0 / dd.max() * (dd - dd.min())).astype(numpy.uint8)
# img = Image.fromarray(rescaled)
# img.save('filter_l0' + str(i) + '.png')
#
# d = layer1.W.get_value() #e.g. (20, 1, 5, 5) number of filter, num of incomming filters, dim filter
# for i in range(0, numpy.shape(d)[0]):
# dd = d[i][0]
# rescaled = (255.0 / dd.max() * (dd - dd.min())).astype(numpy.uint8)
# img = Image.fromarray(rescaled)
# img.save('filter_l1' + str(i) + '.png')
state = LeNet5State(topology=topo,
convValues = [layer0.getParametersAsValues(), layer1.getParametersAsValues()],
hiddenValues = layer2.getParametersAsValues(),
logRegValues = layer3.getParametersAsValues())
print
if stateOut is not None:
pickle.dump(state, open(stateOut, 'wb') ) #Attention y is wrong
print("Saved the pickeled data-set")
return learning_rate