Ejemplo n.º 1
0
    def runClassifier(self, X_train, Y_train, X_test, Y_test):
        classalgs = {
            'Logistic_Regression': algs.LogisticRegression1(),
            'Gauassian_SVM': algs.SVM1(),
            'Logistic_Regression_weighted ': algs.LogisticRegression1wt(),
            'Gauassian_SVM_weighted': algs.SVM1wt()
        }

        for learnername, learner in classalgs.iteritems():
            print 'Running learner = ' + learnername
            learner.learn(X_train, Y_train)
            predictions = learner.predict(X_test)
            recall = util.getRecall(Y_test, predictions)
            print '\n Recall for ' + learnername + ': ' + str(recall)
            precision = util.getPrecision(Y_test, predictions)
            print '\n Precision for ' + learnername + ': ' + str(precision)
            f5_score = util.getF5(precision, recall)
            print '\n F5 Score for ' + learnername + ': ' + str(f5_score)
            AUCROC = util.getAUCROC(Y_test, predictions)
            print '\n AUC ROC Score for ' + learnername + ': ' + str(AUCROC)
            AUCROCPlotPoints = util.getAUCROCPlotPoints(Y_test, predictions)
            print('\n tpr : {0} fpr : {1} auc_roc : {2} learnername : {3}'
                  ).format(AUCROCPlotPoints[0], AUCROCPlotPoints[1],
                           AUCROCPlotPoints[2], learnername)
            self.plotGraph(AUCROCPlotPoints, learnername)
            f1_score = util.fscore(Y_test, predictions)
            print '\n f1_score for ' + learnername + ': ' + str(f1_score)
            accuracy = util.getaccuracy(Y_test, predictions)
            print 'Accuracy for ' + learnername + ': ' + str(accuracy)
	def runClassifier(self,X_train,Y_train,X_test,Y_test):
		classalgs = {
		               'Logistic_Regression' : algs.LogisticRegression1(),
		               'Gauassian_SVM' :algs.SVM1(),
		               'Logistic_Regression_weighted ' : algs.LogisticRegression1wt(),
		               'Gauassian_SVM_weighted' :algs.SVM1wt()
		            }

		for learnername, learner in classalgs.iteritems():
		    print 'Running learner = ' + learnername
		    learner.learn(X_train, Y_train)
		    predictions = learner.predict(X_test)
		    recall = util.getRecall(Y_test, predictions)
		    print '\n Recall for ' + learnername + ': ' + str(recall)
		    precision=util.getPrecision(Y_test, predictions)
		    print '\n Precision for ' + learnername + ': ' + str(precision)
		    f5_score=util.getF5(precision,recall)
		    print '\n F5 Score for ' + learnername + ': ' + str(f5_score)
		    AUCROC =util.getAUCROC(Y_test, predictions)
		    print '\n AUC ROC Score for ' + learnername + ': ' + str(AUCROC)
		    AUCROCPlotPoints =util.getAUCROCPlotPoints(Y_test, predictions)
		    print('\n tpr : {0} fpr : {1} auc_roc : {2} learnername : {3}').format(AUCROCPlotPoints[0],AUCROCPlotPoints[1],AUCROCPlotPoints[2],learnername)
		    self.plotGraph(AUCROCPlotPoints,learnername)
		    f1_score = util.fscore(Y_test, predictions)
		    print '\n f1_score for ' + learnername + ': ' + str(f1_score)
		    accuracy = util.getaccuracy(Y_test, predictions)
		    print 'Accuracy for ' + learnername + ': ' + str(accuracy)
                         #'Neural Net_64':algs.backPropogation((Xtrain.shape[1],64,1))
                          }

            accuracyD={}
            for learnername, learner in classalgs.iteritems():
                print 'Running learner = ' + learnername
                learner.learn(Xtrain, Ytrain)
                predictions = learner.predict(Xtest)
                recall = util.getRecall(Ytest, predictions)
                print '\n Recall for ' + learnername + ': ' + str(recall)
                AUCROC =util.getAUCROC(Ytest, predictions)
                print '\n AUC ROC Score for ' + learnername + ': ' + str(AUCROC)
                AUCROCPlotPoints =util.getAUCROCPlotPoints(Ytest, predictions)
                print('\n tpr : {0} fpr : {1} auc_roc : {2} learnername : {3}').format(AUCROCPlotPoints[0],AUCROCPlotPoints[1],AUCROCPlotPoints[2],learnername)
                self.plotGraph(AUCROCPlotPoints,learnername)
                f1_score = util.fscore(Ytest, predictions)
                print '\n f1_score for ' + learnername + ': ' + str(f1_score)
                accuracy = util.getaccuracy(Ytest, predictions)
                print 'Accuracy for ' + learnername + ': ' + str(accuracy)
                accuracyD[learnername]=AUCROC
            FoldAccuracy[i]=accuracyD
            i=i+1
        self.StatisticalSignificance(FoldAccuracy)

    def plotGraph(self,AUCROCPlotPoints,learnerName):
		'''
		Plot the AUC-ROC plot for each classifier.
		'''
        fpr=AUCROCPlotPoints[0]
        tpr=AUCROCPlotPoints[1]
        roc_auc= metrics.auc(fpr, tpr)