# 在这边为方便,我们将训练集拷贝一份作为预测集(不包括 admin 列)
import copy
test_data = copy.deepcopy(data)
# 预测集也要添加intercept变量
test_data['intercept'] = 1.0
# 数据中的列要跟预测时用到的列一致
predict_cols = test_data[test_data.columns[1:]]
# 进行预测,并将预测评分存入 predict 列中
predict=[]
test=np.mat(predict_cols)
for i in test:
sum=sigmoid(i*np.mat(weights))
print (sum)
if sum <= 0.5:
predict.append('0')
else:
predict.append('1')
test_data['predict']=predict
#计算预测准确率
predict_right=0
for i in range(0,400):
if int(test_data.loc[i,'admit'])==int(test_data.loc[i,'predict']):
predict_right=1+predict_right
else:
predict_right=predict_right
print ("预测准确率:")
print ("%.5f" %(predict_right/400))
#预测准确率:
#0.68250


雷达卡
京公网安备 11010802022788号







