forked from shibing624/python-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_variant.py
More file actions
67 lines (53 loc) · 1.65 KB
/
test_variant.py
File metadata and controls
67 lines (53 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
# Author: XuMing <[email protected]>
# Data: 18/1/25
# Brief:
import unittest
from util import load_data, load_lr_data
from lr import LR
from basic_xgb import XGB
train_file = "./data/train.demo.txt"
test_file = "./data/test.demo.txt"
ngram_range = (1, 2)
model_path = './data/'
xgb_model_name = model_path + 'xgb.model'
lr_model_name = model_path + 'lr.model'
class ATest(unittest.TestCase):
"""Test Case for classification
"""
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
pass
def test_init(self):
print("test_init")
"""测试初始化函数,捕捉异常"""
data_x = load_data(train_file)
self.assertEqual(len(data_x) > 0, True)
def model_train(self, train_file):
train_data = load_data(train_file)
# xgboost
print('train a single xgb model...')
xgb_clf = XGB(xgb_model_name)
xgb_clf.train_model(train_data)
print('train a single xgb model done.\n')
# lr
print('train a single lr model...')
lr_clf = LR(lr_model_name)
x, y = load_lr_data(train_file, '\t')
lr_clf.train_model(x, y)
print('train a single LR model done.\n')
def model_test(self, test_file):
test_data = load_data(test_file)
xgb_clf = XGB(xgb_model_name)
xgb_clf.test_model(test_data)
lr_clf = LR(lr_model_name)
x, y = load_lr_data(test_file, '\t')
lr_clf.test_model(x, y)
def test_models(self):
self.model_train(train_file)
self.model_test(test_file)
if __name__ == '__main__':
unittest.main()