From 289a426c700ce8934a526cc456a1b1cd5c621db9 Mon Sep 17 00:00:00 2001 From: StrikerRUS Date: Fri, 18 May 2018 13:38:22 +0300 Subject: [PATCH] removed warnings about overridden categorical features --- tests/python_package_test/test_engine.py | 29 +++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/python_package_test/test_engine.py b/tests/python_package_test/test_engine.py index a4b8dc258ed8..1fc86ccc354b 100644 --- a/tests/python_package_test/test_engine.py +++ b/tests/python_package_test/test_engine.py @@ -289,23 +289,28 @@ def test_categorical_big_values_not_crash(self): lgb_train = lgb.Dataset(data, y, free_raw_data=False) lgb.train(params, lgb_train) + params['categorical_feature'] = [2, 3] self.assertRaises(ValueError, lgb.train, - params, lgb_train, categorical_feature=[2, 3]) + params, lgb_train) csr = csr_matrix(data) lgb_train = lgb.Dataset(csr, y, free_raw_data=False) + params.pop('categorical_feature') lgb.train(params, lgb_train) + params['categorical_feature'] = [2, 3] self.assertRaises(ValueError, lgb.train, - params, lgb_train, categorical_feature=[2, 3]) + params, lgb_train) csc = csc_matrix(data) lgb_train = lgb.Dataset(csc, y, free_raw_data=False) + params.pop('categorical_feature') lgb.train(params, lgb_train) + params['categorical_feature'] = [2, 3] self.assertRaises(ValueError, lgb.train, - params, lgb_train, categorical_feature=[2, 3]) + params, lgb_train) @unittest.skipIf(not IS_PANDAS_INSTALLED, 'pandas not installed') def test_categorical_big_values_not_crash_pandas(self): @@ -314,16 +319,18 @@ def test_categorical_big_values_not_crash_pandas(self): y = np.random.rand(20) params = {'objective': 'regression', - 'min_data': 1} + 'min_data': 1, + 'categorical_feature': [2, 3]} df = pd.DataFrame(data=data) lgb_train = lgb.Dataset(df, y) self.assertRaises(ValueError, lgb.train, - params, lgb_train, categorical_feature=[2, 3]) + params, lgb_train) df[2] = df[2].astype('category') lgb_train = lgb.Dataset(df, y) + params.pop('categorical_feature') lgb.train(params, lgb_train) def test_multiclass(self): @@ -548,16 +555,16 @@ def test_pandas_categorical(self): gbm0 = lgb.train(params, lgb_train, num_boost_round=10, verbose_eval=False) pred0 = list(gbm0.predict(X_test)) lgb_train = lgb.Dataset(X, y) - gbm1 = lgb.train(params, lgb_train, num_boost_round=10, verbose_eval=False, - categorical_feature=[0]) + params['categorical_feature'] = [0] + gbm1 = lgb.train(params, lgb_train, num_boost_round=10, verbose_eval=False) pred1 = list(gbm1.predict(X_test)) lgb_train = lgb.Dataset(X, y) - gbm2 = lgb.train(params, lgb_train, num_boost_round=10, verbose_eval=False, - categorical_feature=['A']) + params['categorical_feature'] = ['A'] + gbm2 = lgb.train(params, lgb_train, num_boost_round=10, verbose_eval=False) pred2 = list(gbm2.predict(X_test)) lgb_train = lgb.Dataset(X, y) - gbm3 = lgb.train(params, lgb_train, num_boost_round=10, verbose_eval=False, - categorical_feature=['A', 'B', 'C', 'D']) + params['categorical_feature'] = ['A', 'B', 'C', 'D'] + gbm3 = lgb.train(params, lgb_train, num_boost_round=10, verbose_eval=False) pred3 = list(gbm3.predict(X_test)) gbm3.save_model('categorical.model') gbm4 = lgb.Booster(model_file='categorical.model')