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

SVM Example Fixes #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 6 additions & 10 deletions examples/svm/svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# imported: as long as the module we want exists on the worker, it can be
# imported and used.
import numpy as np
import sklearn
from sklearn.svm import SVC
from sklearn.ensemble import BaggingClassifier
from sklearn.multiclass import OneVsRestClassifier
Expand Down Expand Up @@ -58,6 +59,7 @@ def main(params):
out : dict
Dictionary of performance metrics to send to SHADHO.
"""

# Extract the kernel name and parameters. This is just a short expression
# to get the only dictionary entry, which should have our hyperparameters.
kernel_params = list(params.values())[0]
Expand All @@ -68,14 +70,8 @@ def main(params):
X_train = X_train.astype(np.float32) / 255.0
X_test = X_test.astype(np.float32) / 255.0

# Set up the SVM with its parameterized kernel. The long form of instantiation
# is done here to show what `kernel_params` looks like internally.
# This can be shortened to `svc = SVC(**kernel_params)`
svc = SVC(kernel=kernel_params['kernel'],
C=kernel_params['C'],
gamma=kernel_params['gamma'] if 'gamma' in kernel_params else None,
coef0=kernel_params['coef0'] if 'coef0' in kernel_params else None,
degree=kernel_params['degree'] if 'degree' in kernel_params else None)
# Set up the SVM with its parameterized kernel.
svc = SVC(**kernel_params)

# Set up parallel training across as many cores as are available on the
# worker.
Expand All @@ -94,7 +90,7 @@ def main(params):
# Generate and encode testing set predictions, along with prediction time.
start = time.time()
predictions = s.predict(X_test)
test_time = time.time()
test_time = time.time() - start
encoder = LabelBinarizer()
loss_labels = encoder.fit_transform(predictions)

Expand All @@ -113,7 +109,7 @@ def main(params):
'accuracy': acc,
'precision': p,
'recall': r,
'params': svm,
'params': kernel_params,
'train_time': train_time,
'test_time': test_time
}
Expand Down
2 changes: 1 addition & 1 deletion shadho/spaces.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from shadho.scaling import linear, ln, log_10, log_2
from .scaling import linear, ln, log_10, log_2

from pyrameter import Scope, ContinuousDomain, DiscreteDomain
import scipy.stats
Expand Down