Пример #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)
                         'Gauassian SVM_100' :algs.SVM(C=100),
                         #'Gauassian SVM_50' :algs.SVM(C=50),
                         #'Gauassian SVM_20' :algs.SVM(C=20),
                         #'Neural Net_4':algs.backPropogation((Xtrain.shape[1],4,1)),
                         #'Neural Net_8':algs.backPropogation((Xtrain.shape[1],8,1)),
                         #'Neural Net_16':algs.backPropogation((Xtrain.shape[1],16,1)),
                         #'Neural Net_32':algs.backPropogation((Xtrain.shape[1],32,1)),
                         #'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)