Skip to content

change: fix list serialization for 1P algos #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 11, 2019
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
8 changes: 7 additions & 1 deletion src/sagemaker/amazon/hyperparameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# language governing permissions and limitations under the License.
from __future__ import absolute_import

import json


class Hyperparameter(object):
"""An algorithm hyperparameter with optional validation. Implemented as a python
Expand Down Expand Up @@ -67,4 +69,8 @@ def serialize_all(obj):
"""Return all non-None ``hyperparameter`` values on ``obj`` as a ``dict[str,str].``"""
if "_hyperparameters" not in dir(obj):
return {}
return {k: str(v) for k, v in obj._hyperparameters.items() if v is not None}
return {
k: json.dumps(v) if isinstance(v, list) else str(v)
for k, v in obj._hyperparameters.items()
if v is not None
}
3 changes: 3 additions & 0 deletions tests/integ/test_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from __future__ import absolute_import

import gzip
import json
import os
import pickle
import sys
Expand Down Expand Up @@ -52,6 +53,7 @@ def test_kmeans(sagemaker_session):
kmeans.half_life_time_size = 1
kmeans.epochs = 1
kmeans.center_factor = 1
kmeans.eval_metrics = ["ssd", "msd"]

assert kmeans.hyperparameters() == dict(
init_method=kmeans.init_method,
Expand All @@ -63,6 +65,7 @@ def test_kmeans(sagemaker_session):
epochs=str(kmeans.epochs),
extra_center_factor=str(kmeans.center_factor),
k=str(kmeans.k),
eval_metrics=json.dumps(kmeans.eval_metrics),
force_dense="True",
)

Expand Down
1 change: 1 addition & 0 deletions tests/integ/test_randomcutforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_randomcutforest(sagemaker_session):
train_instance_type="ml.c4.xlarge",
num_trees=50,
num_samples_per_tree=20,
eval_metrics=["accuracy", "precision_recall_fscore"],
sagemaker_session=sagemaker_session,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_all_hyperparameters(sagemaker_session):
half_life_time_size="0",
epochs="10",
extra_center_factor="2",
eval_metrics="['msd', 'ssd']",
eval_metrics='["msd", "ssd"]',
force_dense="True",
)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_randomcutforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_all_hyperparameters(sagemaker_session):
assert randomcutforest.hyperparameters() == dict(
num_samples_per_tree=str(NUM_SAMPLES_PER_TREE),
num_trees=str(NUM_TREES),
eval_metrics="{}".format(EVAL_METRICS),
eval_metrics='["accuracy", "precision_recall_fscore"]',
)


Expand Down