本文整理汇总了Python中formatter.Formatter.separate_mushroom方法的典型用法代码示例。如果您正苦于以下问题:Python Formatter.separate_mushroom方法的具体用法?Python Formatter.separate_mushroom怎么用?Python Formatter.separate_mushroom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类formatter.Formatter
的用法示例。
在下文中一共展示了Formatter.separate_mushroom方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import separate_mushroom [as 别名]
def __init__(self,inputFile):
self.file = inputFile
with open(self.file) as f:
lines = f.read().splitlines() #splitlines() gets rid of \n
f.close()
self.content = lines
self.originalLength = len(self.content)
self.testContent = []
testSize = int(.15 * self.originalLength)
for i in range(0,testSize):
self.testContent.append(self.content.pop())
labelList = []
self.attributeList = []
if self.file == "mushroom.data":
self.attributeList, labelList = Formatter.separate_mushroom(self.content)
else:
for line in self.content:
attributes = line.split(",")
attributes = attributes[:-1]
self.attributeList.append(attributes)
self.attributeList = np.array(self.attributeList, dtype=float)
示例2: train
# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import separate_mushroom [as 别名]
def train(self):
output = open(self.outputFilename,'w')
output_confusion = open("confusionMatrix.txt",'w')
accuracyList = []
precisionList = []
recallList = []
fMeasureList = []
if self.flag == "-r":
random = True
distance = False
diversity = False
probability = False
elif self.flag == "-d":
random = False
distance = True
diversity = False
probability = False
elif self.flag == "-v":
random = False
distance = False
diversity = True
probability = False
elif self.flag == "-p":
random = False
distance = False
diversity = False
probability = True
for i in range(0,5):#run 5 times to obtain an average
mySplitter = FileSplitter(self.inputFilename)
if self.inputFilename == "shuffled_magic04.data": #declare a classifier with best parameters for dataset
clf = svm.SVC(gamma=.01, C=100.0)
elif self.inputFilename == "ionosphereShuffle.txt":
clf = svm.SVC(gamma=0.10000000000000001, C=1.0)
elif self.inputFilename == "sensorShuffled.data":
clf = svm.SVC(gamma=.01, C=100.0)
elif self.inputFilename == "mushroom.data":
clf = svm.SVC(gamma=.10000000000000001, C=1.0)
trainContent = []
trainTracker = 0
accuracyIteration = []
precisionIteration = []
recallIteration = []
fMeasureIteration = []
for j in range(0,10):
trainTracker += 1
if j == 0:
trainContent.extend(mySplitter.removeInitialFive())
elif (j == 1) or (j == 2):
remainingContent = mySplitter.getContent()
if self.inputFilename == "shuffled_magic04.data":
x2, y2 = Formatter.separate_magic(remainingContent)
dec = clf.decision_function(x2)
elif self.inputFilename == "ionosphereShuffle.txt":
x2, y2 = Formatter.separate_ionosphere(remainingContent)
dec = clf.decision_function(x2)
elif self.inputFilename == "sensorShuffled.data":
x2, y2 = Formatter.separate_sensor(remainingContent)
dec = clf.decision_function(x2)
elif self.inputFilename == "mushroom.data":
x2, y2 = Formatter.separate_mushroom(remainingContent)
dec = clf.decision_function(x2)
if random == True:
trainContent.extend(mySplitter.removeRandom(.025))
elif distance == True:
trainContent.extend(mySplitter.removeClosest(dec,.025))
elif diversity == True:
trainContent.extend(mySplitter.removeBrinkers(dec,0.85,.025))
elif probability == True:
trainContent.extend(mySplitter.removeProbable(dec,.025))
else:
remainingContent = mySplitter.getContent()
if self.inputFilename == "shuffled_magic04.data":
x2, y2 = Formatter.separate_magic(remainingContent)
dec = clf.decision_function(x2)
elif self.inputFilename == "ionosphereShuffle.txt":
x2, y2 = Formatter.separate_ionosphere(remainingContent)
dec = clf.decision_function(x2)
elif self.inputFilename == "sensorShuffled.data":
x2, y2 = Formatter.separate_sensor(remainingContent)
dec = clf.decision_function(x2)
elif self.inputFilename == "mushroom.data":
x2, y2 = Formatter.separate_mushroom(remainingContent)
dec = clf.decision_function(x2)
if random == True:
trainContent.extend(mySplitter.removeRandom(.1))
elif distance == True:
trainContent.extend(mySplitter.removeClosest(dec,.1))
elif diversity == True:
trainContent.extend(mySplitter.removeBrinkers(dec,0.85,.1))
elif probability == True:
trainContent.extend(mySplitter.removeProbable(dec,.1))
if self.inputFilename == "shuffled_magic04.data":
x1,y1 = Formatter.separate_magic(trainContent) #attributes are stored in x, labels in y
predictContent = mySplitter.getTestContent()
x2,y2 = Formatter.separate_magic(predictContent)
elif self.inputFilename == "ionosphereShuffle.txt":
x1,y1 = Formatter.separate_ionosphere(trainContent)
predictContent = mySplitter.getTestContent()
x2,y2 = Formatter.separate_ionosphere(predictContent)
#.........这里部分代码省略.........