Python “ClassificationDataSet”中的“target”有什么好处?
我试图找出Python “ClassificationDataSet”中的“target”有什么好处?,python,pybrain,Python,Pybrain,我试图找出ClassificationDataSet的参数target可以用于什么,但我仍然不清楚 我试过的 由于这不包含有关目标的信息(除了默认值为1),我查看了以下内容: 现在还不清楚,所以我看了一下: 这似乎与输出维度有关。但是不应该是target然后是nb\u classes?target参数是训练样本输出维度的维度。为了充分理解it和nb_类之间的区别,让我们看看\u converttoonefmany方法: def _convertToOneOfMany(self, bounds=(
ClassificationDataSet
的参数target
可以用于什么,但我仍然不清楚
我试过的
由于这不包含有关目标的信息(除了默认值为1),我查看了以下内容:
现在还不清楚,所以我看了一下:
这似乎与输出维度有关。但是不应该是
target
然后是nb\u classes
?target
参数是训练样本输出维度的维度。为了充分理解it和nb_类之间的区别,让我们看看\u converttoonefmany
方法:
def _convertToOneOfMany(self, bounds=(0, 1)):
"""Converts the target classes to a 1-of-k representation, retaining the
old targets as a field `class`.
To supply specific bounds, set the `bounds` parameter, which consists of
target values for non-membership and membership."""
if self.outdim != 1:
# we already have the correct representation (hopefully...)
return
if self.nClasses <= 0:
self.calculateStatistics()
oldtarg = self.getField('target')
newtarg = zeros([len(self), self.nClasses], dtype='Int32') + bounds[0]
for i in range(len(self)):
newtarg[i, int(oldtarg[i])] = bounds[1]
self.setField('target', newtarg)
self.setField('class', oldtarg)
所以输出的维度等于1,但有两个输出类:0和1。
因此,我们可以将数据更改为:
IN OUT
[0,0],(0,1)
[0,1],(1,0)
[1,0],(1,0)
[1,1],(0,1)
现在,输出的第一个参数是True
的值,第二个参数是False
的值。
这是一种常见的做法,有更多的课程,例如手写识别
希望为您清除此lite位。为什么要使用更长的输出值表示形式?
class SupervisedDataSet(DataSet):
"""SupervisedDataSets have two fields, one for input and one for the target.
"""
def __init__(self, inp, target):
"""Initialize an empty supervised dataset.
Pass `inp` and `target` to specify the dimensions of the input and
target vectors."""
DataSet.__init__(self)
if isscalar(inp):
# add input and target fields and link them
self.addField('input', inp)
self.addField('target', target)
else:
self.setField('input', inp)
self.setField('target', target)
self.linkFields(['input', 'target'])
# reset the index marker
self.index = 0
# the input and target dimensions
self.indim = self.getDimension('input')
self.outdim = self.getDimension('target')
def _convertToOneOfMany(self, bounds=(0, 1)):
"""Converts the target classes to a 1-of-k representation, retaining the
old targets as a field `class`.
To supply specific bounds, set the `bounds` parameter, which consists of
target values for non-membership and membership."""
if self.outdim != 1:
# we already have the correct representation (hopefully...)
return
if self.nClasses <= 0:
self.calculateStatistics()
oldtarg = self.getField('target')
newtarg = zeros([len(self), self.nClasses], dtype='Int32') + bounds[0]
for i in range(len(self)):
newtarg[i, int(oldtarg[i])] = bounds[1]
self.setField('target', newtarg)
self.setField('class', oldtarg)
IN OUT
[0,0],0
[0,1],1
[1,0],1
[1,1],0
IN OUT
[0,0],(0,1)
[0,1],(1,0)
[1,0],(1,0)
[1,1],(0,1)