Skip to content

Commit df23170

Browse files
author
xuming06
committed
update xgboost demo. xuming 20180130
1 parent dd3c217 commit df23170

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

19xgboost/basic_xgb.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
import pandas as pd
88
import xgboost as xgb
9+
from sklearn.metrics import classification_report
910

1011

1112
class XGB(object):
@@ -77,5 +78,14 @@ def test_model(self, test_data):
7778
print('pred:', preds[:10])
7879
total_count = int(len(preds))
7980
right_count = sum(1 for i in range(len(preds)) if int(preds[i] > 0.5) == labels[i])
81+
out_preds = []
82+
for i in range(len(preds)):
83+
if float(preds[i]) > 0.5:
84+
out_preds.append(1)
85+
else:
86+
out_preds.append(0)
87+
target_names = ['risk', 'norisk']
88+
report = classification_report(labels, out_preds, target_names=target_names)
89+
print(report)
8090

81-
print('Xgb test: total_count, right_count, pred:', total_count, right_count, right_count/total_count)
91+
print('Xgb test: total_count, right_count, pred:', total_count, right_count, right_count / total_count)

0 commit comments

Comments
 (0)