当前位置: 首页>>代码示例>>Python>>正文


Python DataSet.addLabel方法代码示例

本文整理汇总了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];
开发者ID:SUYONGJIAN,项目名称:adaboost,代码行数:39,代码来源:naiveSampler.py


注:本文中的dataset.DataSet.addLabel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。