-
Notifications
You must be signed in to change notification settings - Fork 378
/
08_less_magic.py
executable file
·37 lines (29 loc) · 1.01 KB
/
08_less_magic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""A standard machine learning task without much sacred magic."""
from sacred import Experiment
from sacred.observers import FileStorageObserver
from sklearn import svm, datasets, model_selection
ex = Experiment("svm")
ex.observers.append(FileStorageObserver("my_runs"))
ex.add_config(
{ # Configuration is explicitly defined as dictionary.
"C": 1.0,
"gamma": 0.7,
"kernel": "rbf",
"seed": 42,
}
)
def get_model(C, gamma, kernel):
return svm.SVC(C=C, kernel=kernel, gamma=gamma)
@ex.main # Using main, command-line arguments will not be interpreted in any special way.
def run(_config):
X, y = datasets.load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = model_selection.train_test_split(
X, y, test_size=0.2
)
clf = get_model(
_config["C"], _config["gamma"], _config["kernel"]
) # Parameters are passed explicitly.
clf.fit(X_train, y_train)
return clf.score(X_test, y_test)
if __name__ == "__main__":
ex.run()