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
|
- import plac
- from sklearn.svm import LinearSVC
- from src.utils import (
- dump_yaml,
- evaluate_model,
- print_results,
- read_data,
- read_yaml,
- save_results,
- )
- @plac.annotations(
- data_path=("Path to source data", "option", "i", str),
- out_path=("Path to save trained Model", "option", "o", str),
- )
- def main(data_path="data/features/", out_path="models/svc/"):
- X_train, X_test, y_train, y_test = read_data(data_path)
- name = "LinearSVC"
- params = read_yaml("params.yaml", "svc")
- model = LinearSVC(**params)
- model.fit(X_train, y_train)
- accuracy, c_matrix, fig = evaluate_model(model, X_test, y_test)
- print_results(accuracy, c_matrix, name)
- save_results(out_path, model, fig)
- dump_yaml(
- dict(accuracy=accuracy, confusion_matrix=c_matrix),
- f"{out_path}metrics.yaml",
- )
- if __name__ == "__main__":
- plac.call(main)
|