Skip to content

Commit

Permalink
Improve xgboost test. (#949)
Browse files Browse the repository at this point in the history
- Add assertion.
- Stopped using deprecated label encoder (removes the following warning: https://paste.googleplex.com/6273615185051648)
  • Loading branch information
rosbo committed Feb 2, 2021
1 parent eadd3e1 commit f3951d4
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tests/test_xgboost.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import unittest

import numpy as np
import xgboost

from distutils.version import StrictVersion
from sklearn import datasets
from xgboost import XGBClassifier

class TestXGBoost(unittest.TestCase):
Expand All @@ -12,8 +12,15 @@ def test_version(self):
self.assertGreaterEqual(StrictVersion(xgboost.__version__), StrictVersion("1.2.1"))

def test_classifier(self):
boston = datasets.load_boston()
X, y = boston.data, boston.target
X_train = np.random.random((100, 28))
y_train = np.random.randint(10, size=(100, 1))
X_test = np.random.random((100, 28))
y_test = np.random.randint(10, size=(100, 1))

xgb1 = XGBClassifier(n_estimators=3)
xgb1.fit(X[0:70],y[0:70])
xgb1 = XGBClassifier(n_estimators=3, use_label_encoder=False)
xgb1.fit(
X_train, y_train,
eval_set=[(X_train, y_train), (X_test, y_test)],
eval_metric='mlogloss',
)
self.assertIn("validation_0", xgb1.evals_result())

0 comments on commit f3951d4

Please sign in to comment.