Commit 6be7aa7a authored by Mikhail Korobov's avatar Mikhail Korobov Committed by Guolin Ke
Browse files

TST check that single-leaf trees don't cause segfaults (#852)

parent cc83cd67
...@@ -8,7 +8,7 @@ import lightgbm as lgb ...@@ -8,7 +8,7 @@ import lightgbm as lgb
import numpy as np import numpy as np
from sklearn.base import clone from sklearn.base import clone
from sklearn.datasets import (load_boston, load_breast_cancer, load_digits, from sklearn.datasets import (load_boston, load_breast_cancer, load_digits,
load_svmlight_file) load_iris, load_svmlight_file)
from sklearn.externals import joblib from sklearn.externals import joblib
from sklearn.metrics import log_loss, mean_squared_error from sklearn.metrics import log_loss, mean_squared_error
from sklearn.model_selection import GridSearchCV, train_test_split from sklearn.model_selection import GridSearchCV, train_test_split
...@@ -151,3 +151,10 @@ class TestSklearn(unittest.TestCase): ...@@ -151,3 +151,10 @@ class TestSklearn(unittest.TestCase):
self.assertEqual(len(pred_origin), len(pred_pickle)) self.assertEqual(len(pred_origin), len(pred_pickle))
for preds in zip(pred_origin, pred_pickle): for preds in zip(pred_origin, pred_pickle):
self.assertAlmostEqual(*preds, places=5) self.assertAlmostEqual(*preds, places=5)
def test_feature_importances_single_leaf(self):
clf = lgb.LGBMClassifier(n_estimators=100)
data = load_iris()
clf.fit(data.data, data.target)
importances = clf.feature_importances_
self.assertEqual(len(importances), 4)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment