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


Python Factory.getClassAttribute方法代码示例

本文整理汇总了Python中Factory.Factory.getClassAttribute方法的典型用法代码示例。如果您正苦于以下问题:Python Factory.getClassAttribute方法的具体用法?Python Factory.getClassAttribute怎么用?Python Factory.getClassAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Factory.Factory的用法示例。


在下文中一共展示了Factory.getClassAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DataSet

# 需要导入模块: from Factory import Factory [as 别名]
# 或者: from Factory.Factory import getClassAttribute [as 别名]
class DataSet(object):
	"""
	DataSet

	Data structure used to load in .gla files, train, and test data using various classifiers.
	"""

	def __init__(self, fileIn = None):
		self.name		 = None

		self.attributes  = None
		self.examples	 = None
		self.initialize(fileIn = fileIn)

	def convert(self, data):
		return [self.attributes.get(i).getValue(d.replace('#', '')) for i,d in enumerate(data.split())]

	def initialize(self, fileIn = None):
		fin = open(fileIn, 'r')
		read = [line for line in fin.read().splitlines() if len(line) > 0]
		fin.close()

		self.attributes = Factory().construct([line for line in read if len(line) > 0 and line[0] == '@'])
		self.examples 	= Factory().construct([line for line in read if len(line) > 0 and line[0] == '#'], self.attributes)
		self.name 		= read[0]

	def getName(self):
		return self.name

	def setName(self, name):
		self.name = name

	def getAttributeNames(self):
		return [self.attributes.get(a).getName() for a in self.attributes.data]

	def getAttributeTypes(self):
		return [self.attributes.get(a).getType() for a in self.attributes.data]

	def getAttribute(self, attribute = None):
		return self.attributes.get(attribute)

	def getAttributes(self, unit = None):
		if 	 unit == 0: return self.attributes.data.keys()
		elif unit == 1: return self.attributes.data.values()
		else:			return self.attributes

	def getClasses(self, unit = 1):
		return self.attributes.getClassAttribute().getValues()

	def getExample(self, n = None):
		return self.examples.getExamples(n)

	def getExamples(self):
		return self.examples

	def getExamplesWithValue(self, a, v, c = 0):
		"""
			a:	indicates the attribute index
			v:	indicates the attribute value
			c:	indicates the attribute class/label
		"""
		if a == -1:
			return [e.getValue() + [e.getLabel()] for e in self.examples.getExamples(c) if e.getLabel() == v]
		return [e.getValue() + [e.getLabel()] for e in self.examples.getExamples(c) if e.getValue(a) == v]

	def getType(self, i):
		if type(i) == type(str()):
			labels = [self.attributes[k].name for k in self.attributes.keys()]
			i = labels.index(i)
		return self.attributes.get(i).getType()

	def isNumeric(self, i):
		if self.getType(i) in ['n', 'num', 'number', 'numeric']:
			return True
		return False

	def getSize(self, of = 'a'):
		if of in [0, 'a', 'at', 'attr', 'attribute', 'attributes']: return len(self.getAttributes(0))
		if of in [1, 'e', 'ex', 'exam', 'example', 'examples']: 	return len(self.getExamples())

	def getValues(self, attribute = None):
		return self.attributes.get(attribute).getValues()

	def getTrainTestSet(self, p = .6):
		examples = self.getExamples()
		n = int(len(examples) * p)
		s = sample(examples, n)
		
		train = ExampleSet()
		tests = ExampleSet()

		for example in examples:
			if example in s: 			train.add(example)
			elif example not in train: 	tests.add(example)

		return train, tests


	def getTrainValidateTestSet(self, p = .6, v = .5):
		examples = self.getExamples()
#.........这里部分代码省略.........
开发者ID:gabastil,项目名称:pyClassifiers,代码行数:103,代码来源:DataSet.py


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