本文整理匯總了Python中net.Net.classify方法的典型用法代碼示例。如果您正苦於以下問題:Python Net.classify方法的具體用法?Python Net.classify怎麽用?Python Net.classify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.Net
的用法示例。
在下文中一共展示了Net.classify方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: BackProp
# 需要導入模塊: from net import Net [as 別名]
# 或者: from net.Net import classify [as 別名]
class BackProp(Learner):
def __init__(self, meta, layers=[], rate=.05, target=None, momentum=None, trans=None, wrange=100):
Learner.__init__(self, meta, target)
inputs = len(self.meta.names()) - 1
_, possible = self.meta[self.target]
self.outputs = possible
self.net = Net([inputs] + layers + [len(possible)], rate=rate, momentum=momentum, wrange=wrange, trans=trans)
def state(self):
return [x.copy() for x in self.net.weights]
def use_state(self, state):
self.net.weights = state
def classify(self, data):
output = self.net.classify(data)
# print 'result'
# print output
# print 'result', output, self.outputs
return self.outputs[output[-1].argmax()]
def validate(self, data, real):
output = self.net.classify(data)[-1]
label = self.outputs[output.argmax()]
target = n.zeros(len(self.outputs))
target[self.outputs.index(real)] = 1
squerr = (target - output)**2
return label, squerr.mean()
def train(self, data, target):
output = n.zeros(len(self.outputs))
# print self.outputs, target
output[self.outputs.index(target)] = 1
if LOG:
print 'training'
print 'data', data
print 'expected', output
print 'weights'
for level in self.net.weights:
print ' ', level
err = self.net.train(data, output)
return err