Skip to content
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

Add set_params to Estimator base class #147

Merged
merged 3 commits into from
Feb 22, 2024
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ dmypy.json

# Pyre type checker
.pyre/

# VSCode project settings
.vscode/

# Mac OS X clutter
**/.DS_Store
8 changes: 7 additions & 1 deletion karateclub/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ def get_memberships(self):
def get_cluster_centers(self):
"""Getting the cluster centers."""
pass

def get_params(self):
"""Get parameter dictionary for this estimator.."""
rx = re.compile(r'^\_')
params = self.__dict__
params = {key: params[key] for key in params if not rx.search(key)}
return params

def set_params(self, **parameters):
"""Set the parameters of this estimator."""
for parameter, value in parameters.items():
setattr(self, parameter, value)
return self

def _set_seed(self):
"""Creating the initial random seed."""
random.seed(self.seed)
Expand Down
13 changes: 12 additions & 1 deletion test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,15 @@ def test_get_params():
params = model.get_params()
assert len(params) != 0
assert type(params) is dict
assert '_embedding' not in params
assert '_embedding' not in params

def test_set_params():
model = DeepWalk()
default_params = model.get_params()
params = {'dimensions': 1,
'seed': 123}
model.set_params(**params)
new_params = model.get_params()
assert new_params != default_params
assert new_params['dimensions'] == 1
assert new_params['seed'] == 123
Loading