Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

ensemble.py 1.2 KB

You have to be logged in to leave a comment. Sign In
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
38
  1. import plac
  2. from sklearn.ensemble import VotingClassifier
  3. from utils import read_data, load_model, evaluate_model, print_results, save_results, log_experiment, read_params
  4. @plac.annotations(
  5. data_path=("Path to source data", "option", "i", str),
  6. model_path=("Path to save trained Model", "option", "m", str),
  7. out_path=("Path to save trained Model", "option", "o", str)
  8. )
  9. def main(data_path='data/features/', model_path='data/models/', out_path='data/models/ensemble/'):
  10. X_train, X_test, y_train, y_test = read_data(data_path)
  11. name = 'Ensemble'
  12. params = read_params('params.yaml', 'ensemble')
  13. cl1 = load_model(f'{model_path}/logistic/')
  14. cl2 = load_model(f'{model_path}/svc/')
  15. cl3 = load_model(f'{model_path}/r_forrest/')
  16. estimators = [
  17. ('l_regression', cl1),
  18. ('l_svc', cl2),
  19. ('r_forrest', cl3)
  20. ]
  21. model = VotingClassifier(estimators, **params)
  22. model.fit(X_train, y_train)
  23. accuracy, c_matrix, fig = evaluate_model(model, X_test, y_test)
  24. print_results(accuracy, c_matrix, name)
  25. save_results(out_path, model, fig)
  26. log_experiment(out_path, params=params,
  27. metrics=dict(accuracy=accuracy, confusion_matrics=c_matrix))
  28. if __name__ == '__main__':
  29. plac.call(main)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...