Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions autosklearn/metalearning/metafeatures/metafeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,16 @@ def _calculate(self, X, y, logger, feat_type):
kurts = []
for i in range(X.shape[1]):
if numerical[X.columns[i] if hasattr(X, "columns") else i]:
kurts.append(
scipy.stats.kurtosis(
X.iloc[:, i] if hasattr(X, "iloc") else X[:, i]
if np.isclose(
np.var(X.iloc[:, i] if hasattr(X, "iloc") else X[:, i]), 0
):
kurts.append(0)
else:
kurts.append(
scipy.stats.kurtosis(
X.iloc[:, i] if hasattr(X, "iloc") else X[:, i]
)
)
)
return kurts

def _calculate_sparse(self, X, y, logger, feat_type):
Expand All @@ -548,7 +553,10 @@ def _calculate_sparse(self, X, y, logger, feat_type):
if numerical[X.columns[i] if hasattr(X, "columns") else i]:
start = X_new.indptr[i]
stop = X_new.indptr[i + 1]
kurts.append(scipy.stats.kurtosis(X_new.data[start:stop]))
if np.isclose(np.var(X_new.data[start:stop]), 0):
kurts.append(0)
else:
kurts.append(scipy.stats.kurtosis(X_new.data[start:stop]))
return kurts


Expand Down Expand Up @@ -594,9 +602,16 @@ def _calculate(self, X, y, logger, feat_type):
skews = []
for i in range(X.shape[1]):
if numerical[X.columns[i] if hasattr(X, "columns") else i]:
skews.append(
scipy.stats.skew(X.iloc[:, i] if hasattr(X, "iloc") else X[:, i])
)
if np.isclose(
np.var(X.iloc[:, i] if hasattr(X, "iloc") else X[:, i]), 0
):
skews.append(0)
else:
skews.append(
scipy.stats.skew(
X.iloc[:, i] if hasattr(X, "iloc") else X[:, i]
)
)
return skews

def _calculate_sparse(self, X, y, logger, feat_type):
Expand All @@ -610,7 +625,10 @@ def _calculate_sparse(self, X, y, logger, feat_type):
if numerical[X.columns[i] if hasattr(X, "columns") else i]:
start = X_new.indptr[i]
stop = X_new.indptr[i + 1]
skews.append(scipy.stats.skew(X_new.data[start:stop]))
if np.isclose(np.var(X_new.data[start:stop]), 0):
skews.append(0)
else:
skews.append(scipy.stats.skew(X_new.data[start:stop]))
return skews


Expand Down
2 changes: 1 addition & 1 deletion doc/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ General

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

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

Expand Down
2 changes: 1 addition & 1 deletion doc/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ give short explanations (click the title to expand text), e.g.

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

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

Expand Down
2 changes: 1 addition & 1 deletion doc/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ Version 0.4.0
for the ensemble.
* Adds an operating system check at import and installation time to make sure
to not accidentaly run on a Windows machine.
* New examples gallery using sphinx gallery: :ref:`sphx_glr_examples`
* New examples gallery using sphinx gallery: :ref:`examples`
* Safeguard Auto-sklearn against deleting directories it did not create (Issue
`#317 <https://github.com/automl/auto-sklearn/issues/317>`_.

Expand Down
18 changes: 4 additions & 14 deletions test/test_metalearning/pyMetaLearn/test_meta_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,7 @@ def meta_train_data_transformed(request):
if request.param == "numpy":
return X_transformed, y, feat_type_transformed
elif request.param == "pandas":
dtypes = {}
for key, value in feat_type.items():
if value == "categorical":
dtypes[key] = "category"
elif value == "numerical":
dtypes[key] = "float64"
elif value == "string":
dtypes[key] = "string"
else:
raise KeyError
X_transformed = pd.DataFrame(X_transformed).astype(dtypes)
X_transformed = pd.DataFrame(X_transformed)
return X_transformed, y, feat_type_transformed
else:
raise ValueError(request.param)
Expand Down Expand Up @@ -881,10 +871,10 @@ def test_calculate_all_metafeatures_same_results_across_datatypes():
"SkewnessMean": 1.47397188548894,
"SkewnessMax": 29.916569235579203,
"SkewnessMin": -29.916569235579203,
"KurtosisSTD": 153.0563504598898,
"KurtosisMean": 56.998860939761165,
"KurtosisSTD": 152.95700852863064,
"KurtosisMean": 57.258120199020425,
"KurtosisMax": 893.0011148272025,
"KurtosisMin": -3.0,
"KurtosisMin": -1.998392219134577,
"SymbolsSum": 49,
"SymbolsSTD": 1.3679553264445183,
"SymbolsMean": 1.8846153846153846,
Expand Down
53 changes: 25 additions & 28 deletions test/test_metalearning/pyMetaLearn/test_meta_features_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,38 +338,36 @@ def test_skewnesses(sparse_data_transformed):
mf = meta_features.helper_functions["Skewnesses"](
X_transformed, y, logging.getLogger("Meta")
)
print(mf.value)
print(fixture)
np.testing.assert_allclose(mf.value, fixture)


def test_kurtosisses(sparse_data_transformed):
fixture = [
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
-3.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-1.1005836114255763,
-1.1786325509475744,
-1.23879983823279,
Expand All @@ -381,7 +379,6 @@ def test_kurtosisses(sparse_data_transformed):
mf = meta_features.helper_functions["Kurtosisses"](
X_transformed, y, logging.getLogger("Meta")
)
print(mf.value)
np.testing.assert_allclose(mf.value, fixture)


Expand Down