MCPcopy Create free account
hub / github.com/Kaggle/docker-python / TestLightgbm

Class TestLightgbm

tests/test_lightgbm.py:8–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6from common import gpu_test
7
8class TestLightgbm(unittest.TestCase):
9 # Based on the "simple_example" from their documentation:
10 # https://github.com/Microsoft/LightGBM/blob/master/examples/python-guide/simple_example.py
11 def test_cpu(self):
12 lgb_train, lgb_eval = self.load_datasets()
13
14 params = {
15 'task': 'train',
16 'boosting_type': 'gbdt',
17 'objective': 'regression',
18 'metric': {'l2', 'auc'},
19 'num_leaves': 31,
20 'learning_rate': 0.05,
21 'feature_fraction': 0.9,
22 'bagging_fraction': 0.8,
23 'bagging_freq': 5,
24 'force_row_wise': True,
25 'verbose': 0
26 }
27
28 # Run only one round for faster test
29 gbm = lgb.train(params,
30 lgb_train,
31 num_boost_round=1,
32 valid_sets=lgb_eval,
33 callbacks=[lgb.early_stopping(stopping_rounds=1)])
34
35 self.assertEqual(1, gbm.best_iteration)
36
37 @gpu_test
38 def test_gpu(self):
39 lgb_train, lgb_eval = self.load_datasets()
40
41 params = {
42 'boosting_type': 'gbdt',
43 'objective': 'regression',
44 'metric': 'auc',
45 'num_leaves': 31,
46 'learning_rate': 0.05,
47 'feature_fraction': 0.9,
48 'bagging_fraction': 0.8,
49 'bagging_freq': 5,
50 'force_row_wise': True,
51 'verbose': 1,
52 'device': 'gpu'
53 }
54
55 # Run only one round for faster test
56 gbm = lgb.train(params,
57 lgb_train,
58 num_boost_round=1,
59 valid_sets=lgb_eval,
60 callbacks=[lgb.early_stopping(stopping_rounds=1)])
61
62 self.assertEqual(1, gbm.best_iteration)
63
64 def load_datasets(self):
65 df_train = pd.read_csv('/input/tests/data/lgb_train.csv', header=None, sep='\t')

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected