本文整理汇总了Python中dataset.DataSet.addLabel方法的典型用法代码示例。如果您正苦于以下问题:Python DataSet.addLabel方法的具体用法?Python DataSet.addLabel怎么用?Python DataSet.addLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dataset.DataSet
的用法示例。
在下文中一共展示了DataSet.addLabel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sample
# 需要导入模块: from dataset import DataSet [as 别名]
# 或者: from dataset.DataSet import addLabel [as 别名]
def sample(self,inputDataSet,sampleWeights):
""" sampels a given data set with respect to the given sample weights"""
print "sampling started"
sampledDataSet=DataSet()
indexMap= dict()
cumulativeWeights=copy.deepcopy(sampleWeights)
sampledDataSet.numberOfAttributes = inputDataSet.numberOfAttributes
sampledDataSet.attributeType = inputDataSet.attributeType
#calculate the cumulative weights
for i in range(len(sampleWeights)):
if(i!=0):
cumulativeWeights[i]=cumulativeWeights[i-1]+cumulativeWeights[i];
#generate a sample of the same size as the input dataset
for i in range(len(sampleWeights)):
rand=random.random()
#generate a random number and find which bin it belongs to and add the instance corresponding to that bin to the new data set
for j in range(len(sampleWeights)):
if j < len (sampleWeights) - 1:
if(cumulativeWeights[j] < rand and cumulativeWeights[j+1] > rand):
sampledDataSet.addInstance(inputDataSet.getInstance(j-1));
sampledDataSet.addLabel (inputDataSet.getLabelForIndex(j-1))
indexMap[sampledDataSet.numberOfInstances - 1]=j-1;
# print "Adding point %s to sample"%(j)
else:
continue
else:
if(cumulativeWeights[j] < rand ):
sampledDataSet.addInstance(inputDataSet.getInstance(j-1));
sampledDataSet.addLabel (inputDataSet.getLabelForIndex(j-1))
indexMap[sampledDataSet.numberOfInstances - 1]=j-1;
# print "Adding point %s to sample"%(j)
print "Size of sample:%s"%(sampledDataSet.numberOfInstances)
print "sampling finished"
return [sampledDataSet,indexMap];