def Eval(self, test): Y_pred = self.PredictLabel(test.X) # Y_pred = self.PredictLabel(test,len(test)) ev = Eval(Y_pred, test.Y) # ev = Eval(Y_pred.pred, test.Y) return [ev.Accuracy(), ev.EvalPrecition(), ev.EvalRecall()]
plt.show() ''' print("Log Probability of first 10 review") nb = NaiveBayes(traindata, float(sys.argv[2])) for i in range(10): res = nb.PredictProb(testdata, i) print(i, res) print("Predict Label with Threshold") precition = [] recall = [] for i in np.arange(0.1, 1.0, 0.1): pred = nb.PredictLabelTh(testdata, i) ev = Eval(pred, testdata.Y) precition.append(ev.EvalPrecition()) recall.append(ev.EvalRecall()) # ev = Eval(Y_pred.pred, test.Y) print('Threshold:', i, ' Accuracy: ', ev.Accuracy(), ' Precition: ', ev.EvalPrecition(), ' Recall: ', ev.EvalRecall()) ''' # Create some mock data t = recall data1 = precition data2 = np.arange(0.05, 1.0, 0.05) fig, ax1 = plt.subplots() color = 'tab:blue' ax1.set_xlabel('Recall') ax1.set_ylabel('Precition', color=color) ax1.plot(t, data1, color=color) ax1.tick_params(axis='y', labelcolor=color)