Skip to content

Fix kmeans max_iterations hyperparameter #199

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 4 commits into from
May 31, 2018
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
9 changes: 7 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
CHANGELOG
=========

1.3.dev1
========

* bug-fix: Estimators: Change max_iterations hyperparameter key for KMeans

1.3.0
=======
=====

* feature: Add chainer

1.2.5
========
=====

* bug-fix: Change module names to string type in __all__
* feature: Save training output files in local mode
Expand Down
2 changes: 1 addition & 1 deletion src/sagemaker/amazon/kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class KMeans(AmazonAlgorithmEstimatorBase):

k = hp('k', gt(1), 'An integer greater-than 1', int)
init_method = hp('init_method', isin('random', 'kmeans++'), 'One of "random", "kmeans++"', str)
max_iterations = hp('local_lloyd_max_iterations', gt(0), 'An integer greater-than 0', int)
max_iterations = hp('local_lloyd_max_iter', gt(0), 'An integer greater-than 0', int)
tol = hp('local_lloyd_tol', (ge(0), le(1)), 'An float in [0, 1]', float)
num_trials = hp('local_lloyd_num_trials', gt(0), 'An integer greater-than 0', int)
local_init_method = hp('local_lloyd_init_method', isin('random', 'kmeans++'), 'One of "random", "kmeans++"', str)
Expand Down
30 changes: 28 additions & 2 deletions tests/integ/test_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,27 @@ def test_kmeans(sagemaker_session):
k=10, sagemaker_session=sagemaker_session, base_job_name='test-kmeans')

kmeans.init_method = 'random'
kmeans.max_iterators = 1
kmeans.max_iterations = 1
kmeans.tol = 1
kmeans.num_trials = 1
kmeans.local_init_method = 'kmeans++'
kmeans.half_life_time_size = 1
kmeans.epochs = 1
kmeans.center_factor = 1

assert kmeans.hyperparameters() == dict(
init_method=kmeans.init_method,
local_lloyd_max_iter=str(kmeans.max_iterations),
local_lloyd_tol=str(kmeans.tol),
local_lloyd_num_trials=str(kmeans.num_trials),
local_lloyd_init_method=kmeans.local_init_method,
half_life_time_size=str(kmeans.half_life_time_size),
epochs=str(kmeans.epochs),
extra_center_factor=str(kmeans.center_factor),
k=str(kmeans.k),
force_dense='True',
)

kmeans.fit(kmeans.record_set(train_set[0][:100]))

endpoint_name = name_from_base('kmeans')
Expand Down Expand Up @@ -80,14 +93,27 @@ def test_async_kmeans(sagemaker_session):
k=10, sagemaker_session=sagemaker_session, base_job_name='test-kmeans')

kmeans.init_method = 'random'
kmeans.max_iterators = 1
kmeans.max_iterations = 1
kmeans.tol = 1
kmeans.num_trials = 1
kmeans.local_init_method = 'kmeans++'
kmeans.half_life_time_size = 1
kmeans.epochs = 1
kmeans.center_factor = 1

assert kmeans.hyperparameters() == dict(
init_method=kmeans.init_method,
local_lloyd_max_iter=str(kmeans.max_iterations),
local_lloyd_tol=str(kmeans.tol),
local_lloyd_num_trials=str(kmeans.num_trials),
local_lloyd_init_method=kmeans.local_init_method,
half_life_time_size=str(kmeans.half_life_time_size),
epochs=str(kmeans.epochs),
extra_center_factor=str(kmeans.center_factor),
k=str(kmeans.k),
force_dense='True',
)

kmeans.fit(kmeans.record_set(train_set[0][:100]), wait=False)
training_job_name = kmeans.latest_training_job.name

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ def test_all_hyperparameters(sagemaker_session):
assert kmeans.hyperparameters() == dict(
k=str(ALL_REQ_ARGS['k']),
init_method='random',
local_lloyd_max_iterations='3',
local_lloyd_max_iter='3',
local_lloyd_tol='0.5',
local_lloyd_num_trials='5',
local_lloyd_init_method='kmeans++',
half_life_time_size='0',
epochs='10',
extra_center_factor='2',
eval_metrics='[\'msd\', \'ssd\']',
force_dense='True'
force_dense='True',
)


Expand Down