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


Python Formatter.confusion_matrix方法代码示例

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


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

示例1: train

# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import confusion_matrix [as 别名]

#.........这里部分代码省略.........
                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)
                elif self.inputFilename == "sensorShuffled.data":
                    x1,y1 = Formatter.separate_sensor(trainContent)
                    predictContent = mySplitter.getTestContent()
                    x2,y2 = Formatter.separate_sensor(predictContent)
                elif self.inputFilename == "mushroom.data":
                    x1,y1 = Formatter.separate_mushroom(trainContent)
                    predictContent = mySplitter.getTestContent()
                    x2,y2 = Formatter.separate_mushroom(predictContent)

                clf.fit(x1,y1) #train the classifier with a labeled set
                prediction = clf.predict(x2) #predict the labels for the x2 set, and store them in a variable
                accuracy, precision, recall = Formatter.confusion_matrix(prediction, y2, output_confusion, j)
                fMeasure = Formatter.f_measure(precision,recall)
                accuracy *= 100
                precision *= 100
                recall *= 100
        
                print ("Accuracy: " + str(accuracy) + "%")
                print ("Precision: " + str(precision) + "%")
                print ("Recall: " + str(recall) + "%")
                print ("F-measure: " + str(fMeasure))
            
                fMeasureIteration.append(fMeasure)
                accuracyIteration.append(accuracy)
                precisionIteration.append(precision)
                recallIteration.append(recall)
            fMeasureList.append(fMeasureIteration)
            accuracyList.append(accuracyIteration)
            precisionList.append(precisionIteration)
            recallList.append(recallIteration)
        outputList = Formatter.takeAverage(fMeasureList)
        Formatter.writeHistogramOutput(outputList,output)
        output.close()
        output_confusion.close()
开发者ID:hagan116,项目名称:SVM-Active-Learning,代码行数:104,代码来源:svm_training.py


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