Skip to content

Commit 3b3e694

Browse files
authored
Update code for latest scipy and sphinx-gallery (#1551)
* Make meta-feature computation compatible with scipy 1.9 * Also fix doc for latest sphinx-gallery
1 parent 193d661 commit 3b3e694

File tree

6 files changed

+59
-54
lines changed

6 files changed

+59
-54
lines changed

autosklearn/metalearning/metafeatures/metafeatures.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,16 @@ def _calculate(self, X, y, logger, feat_type):
530530
kurts = []
531531
for i in range(X.shape[1]):
532532
if numerical[X.columns[i] if hasattr(X, "columns") else i]:
533-
kurts.append(
534-
scipy.stats.kurtosis(
535-
X.iloc[:, i] if hasattr(X, "iloc") else X[:, i]
533+
if np.isclose(
534+
np.var(X.iloc[:, i] if hasattr(X, "iloc") else X[:, i]), 0
535+
):
536+
kurts.append(0)
537+
else:
538+
kurts.append(
539+
scipy.stats.kurtosis(
540+
X.iloc[:, i] if hasattr(X, "iloc") else X[:, i]
541+
)
536542
)
537-
)
538543
return kurts
539544

540545
def _calculate_sparse(self, X, y, logger, feat_type):
@@ -548,7 +553,10 @@ def _calculate_sparse(self, X, y, logger, feat_type):
548553
if numerical[X.columns[i] if hasattr(X, "columns") else i]:
549554
start = X_new.indptr[i]
550555
stop = X_new.indptr[i + 1]
551-
kurts.append(scipy.stats.kurtosis(X_new.data[start:stop]))
556+
if np.isclose(np.var(X_new.data[start:stop]), 0):
557+
kurts.append(0)
558+
else:
559+
kurts.append(scipy.stats.kurtosis(X_new.data[start:stop]))
552560
return kurts
553561

554562

@@ -594,9 +602,16 @@ def _calculate(self, X, y, logger, feat_type):
594602
skews = []
595603
for i in range(X.shape[1]):
596604
if numerical[X.columns[i] if hasattr(X, "columns") else i]:
597-
skews.append(
598-
scipy.stats.skew(X.iloc[:, i] if hasattr(X, "iloc") else X[:, i])
599-
)
605+
if np.isclose(
606+
np.var(X.iloc[:, i] if hasattr(X, "iloc") else X[:, i]), 0
607+
):
608+
skews.append(0)
609+
else:
610+
skews.append(
611+
scipy.stats.skew(
612+
X.iloc[:, i] if hasattr(X, "iloc") else X[:, i]
613+
)
614+
)
600615
return skews
601616

602617
def _calculate_sparse(self, X, y, logger, feat_type):
@@ -610,7 +625,10 @@ def _calculate_sparse(self, X, y, logger, feat_type):
610625
if numerical[X.columns[i] if hasattr(X, "columns") else i]:
611626
start = X_new.indptr[i]
612627
stop = X_new.indptr[i + 1]
613-
skews.append(scipy.stats.skew(X_new.data[start:stop]))
628+
if np.isclose(np.var(X_new.data[start:stop]), 0):
629+
skews.append(0)
630+
else:
631+
skews.append(scipy.stats.skew(X_new.data[start:stop]))
614632
return skews
615633

616634

doc/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ General
1313

1414
We provide examples on using *auto-sklearn* for multiple use cases ranging from
1515
simple classification to advanced uses such as feature importance, parallel runs
16-
and customization. They can be found in the :ref:`sphx_glr_examples`.
16+
and customization. They can be found in the :ref:`examples`.
1717

1818
.. collapse:: <b>What type of tasks can auto-sklearn tackle?</b>
1919

doc/manual.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ give short explanations (click the title to expand text), e.g.
1313

1414
We provide examples on using *auto-sklearn* for multiple use cases ranging from
1515
simple classification to advanced uses such as feature importance, parallel runs
16-
and customization. They can be found in the :ref:`sphx_glr_examples`.
16+
and customization. They can be found in the :ref:`examples`.
1717

1818
.. collapse:: <b>Material from talks and presentations</b>
1919

doc/releases.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ Version 0.4.0
657657
for the ensemble.
658658
* Adds an operating system check at import and installation time to make sure
659659
to not accidentaly run on a Windows machine.
660-
* New examples gallery using sphinx gallery: :ref:`sphx_glr_examples`
660+
* New examples gallery using sphinx gallery: :ref:`examples`
661661
* Safeguard Auto-sklearn against deleting directories it did not create (Issue
662662
`#317 <https://github.com/automl/auto-sklearn/issues/317>`_.
663663

test/test_metalearning/pyMetaLearn/test_meta_features.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,7 @@ def meta_train_data_transformed(request):
148148
if request.param == "numpy":
149149
return X_transformed, y, feat_type_transformed
150150
elif request.param == "pandas":
151-
dtypes = {}
152-
for key, value in feat_type.items():
153-
if value == "categorical":
154-
dtypes[key] = "category"
155-
elif value == "numerical":
156-
dtypes[key] = "float64"
157-
elif value == "string":
158-
dtypes[key] = "string"
159-
else:
160-
raise KeyError
161-
X_transformed = pd.DataFrame(X_transformed).astype(dtypes)
151+
X_transformed = pd.DataFrame(X_transformed)
162152
return X_transformed, y, feat_type_transformed
163153
else:
164154
raise ValueError(request.param)
@@ -881,10 +871,10 @@ def test_calculate_all_metafeatures_same_results_across_datatypes():
881871
"SkewnessMean": 1.47397188548894,
882872
"SkewnessMax": 29.916569235579203,
883873
"SkewnessMin": -29.916569235579203,
884-
"KurtosisSTD": 153.0563504598898,
885-
"KurtosisMean": 56.998860939761165,
874+
"KurtosisSTD": 152.95700852863064,
875+
"KurtosisMean": 57.258120199020425,
886876
"KurtosisMax": 893.0011148272025,
887-
"KurtosisMin": -3.0,
877+
"KurtosisMin": -1.998392219134577,
888878
"SymbolsSum": 49,
889879
"SymbolsSTD": 1.3679553264445183,
890880
"SymbolsMean": 1.8846153846153846,

test/test_metalearning/pyMetaLearn/test_meta_features_sparse.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -338,38 +338,36 @@ def test_skewnesses(sparse_data_transformed):
338338
mf = meta_features.helper_functions["Skewnesses"](
339339
X_transformed, y, logging.getLogger("Meta")
340340
)
341-
print(mf.value)
342-
print(fixture)
343341
np.testing.assert_allclose(mf.value, fixture)
344342

345343

346344
def test_kurtosisses(sparse_data_transformed):
347345
fixture = [
348-
-3.0,
349-
-3.0,
350-
-3.0,
351-
-3.0,
352-
-3.0,
353-
-3.0,
354-
-3.0,
355-
-3.0,
356-
-3.0,
357-
-3.0,
358-
-3.0,
359-
-3.0,
360-
-3.0,
361-
-3.0,
362-
-3.0,
363-
-3.0,
364-
-3.0,
365-
-3.0,
366-
-3.0,
367-
-3.0,
368-
-3.0,
369-
-3.0,
370-
-3.0,
371-
-3.0,
372-
-3.0,
346+
0.0,
347+
0.0,
348+
0.0,
349+
0.0,
350+
0.0,
351+
0.0,
352+
0.0,
353+
0.0,
354+
0.0,
355+
0.0,
356+
0.0,
357+
0.0,
358+
0.0,
359+
0.0,
360+
0.0,
361+
0.0,
362+
0.0,
363+
0.0,
364+
0.0,
365+
0.0,
366+
0.0,
367+
0.0,
368+
0.0,
369+
0.0,
370+
0.0,
373371
-1.1005836114255763,
374372
-1.1786325509475744,
375373
-1.23879983823279,
@@ -381,7 +379,6 @@ def test_kurtosisses(sparse_data_transformed):
381379
mf = meta_features.helper_functions["Kurtosisses"](
382380
X_transformed, y, logging.getLogger("Meta")
383381
)
384-
print(mf.value)
385382
np.testing.assert_allclose(mf.value, fixture)
386383

387384

0 commit comments

Comments
 (0)