Exemple #1
0
 def getTimeOfEvaluation(self, X, Y):
     plotX = []
     plotY = []
     i = 0
     while (i < 8):
         plotX.append(i)
         startTime = time.time()
         print("Start training using logistic regression")
         model = MLModel.LogisticRegressionModel(X, Y, X, Y)
         model.fit(0.1**(7 - i))
         timeUsed = time.time() - startTime
         plotY.append(timeUsed)
         i = i + 1
     plt.plot(plotX, plotY, c='r', label='logistic regression')
     plt.xlabel("i such that learningRate = 0.1^(7-i)")
     plt.ylabel("RunningTime(second)")
     plt.title("Performance of LogisticRegression based on learningRate")
     plt.show()
Exemple #2
0
 def validate(self, X, Y, k, isLogisticRegression, learningRate):
     (row, col) = X.shape
     numOfSection = int(row / k)
     totalAcc = 0.0
     for a in range(0, k):
         i = a * numOfSection
         Xbefore = []
         Ybefore = []
         if i == 0:
             Xbefore = X[0:0, 0:0]
             Ybefore = Y[0:0]
         else:
             Xbefore = X[0:i - 1, 0:col]
             Ybefore = Y[0:i - 1]
         subX = X[i:i + numOfSection - 1, 0:col]
         subY = Y[i:i + numOfSection - 1]
         Xafter = X[i + numOfSection:row, 0:col]
         Yafter = Y[i + numOfSection:row]
         XConc = []
         YConc = []
         if i == 0:
             Xconc = Xafter
             Yconc = Yafter
         else:
             Xconc = np.concatenate((Xbefore, Xafter))
             Yconc = np.concatenate((Ybefore, Yafter))
         #Use to test the accuracy value from sci-kit
         model = None
         if (isLogisticRegression):
             print("Start training using logistic regression")
             model = MLModel.LogisticRegressionModel(
                 Xconc, Yconc, subX, subY)
             model.fit(learningRate)
         else:
             print("Start training using gaussian naive bayes")
             model = MLModel.GaussianNaiveBayes(Xconc, Yconc, subX, subY)
             model.fit()
         targetY = model.predict(subX)
         acc = model.evaluate_acc(subY, targetY)
         #print("Accuracy is " + str(acc))
         totalAcc = totalAcc + acc
     return (totalAcc / float(k))