8000 TST catch UserWarning in test_predictions for HGBT (#26312) · scikit-learn/scikit-learn@c0bac2b · GitHub
[go: up one dir, main page]

Skip to content

Commit c0bac2b

Browse files
authored
TST catch UserWarning in test_predictions for HGBT (#26312)
1 parent edfdbd0 commit c0bac2b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

sklearn/ensemble/_hist_gradient_boosting/tests/test_monotonic_contraints.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from sklearn.ensemble import HistGradientBoostingRegressor
1515
from sklearn.ensemble import HistGradientBoostingClassifier
1616
from sklearn.utils._openmp_helpers import _openmp_effective_n_threads
17+
from sklearn.utils._testing import _convert_container
1718

1819
n_threads = _openmp_effective_n_threads()
1920

@@ -212,9 +213,9 @@ def test_predictions(global_random_seed, use_feature_names):
212213
f_0 = rng.rand(n_samples) # positive correlation with y
213214
f_1 = rng.rand(n_samples) # negative correslation with y
214215
X = np.c_[f_0, f_1]
215-
if use_feature_names:
216-
pd = pytest.importorskip("pandas")
217-
X = pd.DataFrame(X, columns=["f_0", "f_1"])
216+
columns_name = ["f_0", "f_1"]
217+
constructor_name = "dataframe" if use_feature_names else "array"
218+
X = _convert_container(X, constructor_name, columns_name=columns_name)
218219

219220
noise = rng.normal(loc=0.0, scale=0.01, size=n_samples)
220221
y = 5 * f_0 + np.sin(10 * np.pi * f_0) - 5 * f_1 - np.cos(10 * np.pi * f_1) + noise
@@ -244,20 +245,24 @@ def test_predictions(global_random_seed, use_feature_names):
244245
# First feature (POS)
245246
# assert pred is all increasing when f_0 is all increasing
246247
X = np.c_[linspace, constant]
248+
X = _convert_container(X, constructor_name, columns_name=columns_name)
247249
pred = gbdt.predict(X)
248250
assert is_increasing(pred)
249251
# assert pred actually follows the variations of f_0
250252
X = np.c_[sin, constant]
253+
X = _convert_container(X, constructor_name, columns_name=columns_name)
251 8000 254
pred = gbdt.predict(X)
252255
assert np.all((np.diff(pred) >= 0) == (np.diff(sin) >= 0))
253256

254257
# Second feature (NEG)
255258
# assert pred is all decreasing when f_1 is all increasing
256259
X = np.c_[constant, linspace]
260+
X = _convert_container(X, constructor_name, columns_name=columns_name)
257261
pred = gbdt.predict(X)
258262
assert is_decreasing(pred)
259263
# assert pred actually follows the inverse variations of f_1
260264
X = np.c_[constant, sin]
265+
X = _convert_container(X, constructor_name, columns_name=columns_name)
261266
pred = gbdt.predict(X)
262267
assert ((np.diff(pred) <= 0) == (np.diff(sin) >= 0)).all()
263268

0 commit comments

Comments
 (0)
0