defPredict(self, test_data, iter_num = 10): ''' 预测方法 ''' beta = self.Newton(iter_num) test_p = [] for i in range(len(test_data)): p = float(np.mat(test_data.iloc[i])*beta.T) p = self.Sigmoid(p) if p>=0.5: p = 1 else: p = 0 test_p.append(p return test_p
结果演示:
1 2 3 4 5 6 7 8 9 10 11 12
defTrain_Pre(self): ''' 训练集结果以及正确率 ''' input_data = self.input_data label = self.label train_p = self.Predict(input_data) T = 0 for i, j in list(zip(train_p, label)): if i == j: T += 1 true_rate = T/len(label) return train_p, true_rate