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

train_model.py 1.4 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
39
40
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Oct 31 11:19:23 2019
  4. @author: Marvin
  5. """
  6. from __future__ import print_function
  7. from __future__ import division
  8. import joblib
  9. from best_model import get_best_model
  10. import pandas as pd
  11. # Imports for saving of params and metrics
  12. import json
  13. sj_train = pd.read_csv("./data/featurized_train_sj.csv")
  14. iq_train = pd.read_csv("./data/featurized_train_iq.csv")
  15. sj_train_subtrain = sj_train.head(800)
  16. sj_train_subtest = sj_train.tail(sj_train.shape[0] - 800)
  17. iq_train_subtrain = iq_train.head(400)
  18. iq_train_subtest = iq_train.tail(iq_train.shape[0] - 400)
  19. print("Finding the best model...")
  20. [sj_best_model, sj_best_alpha, sj_best_score] = get_best_model(sj_train_subtrain, sj_train_subtest)
  21. [iq_best_model, iq_best_alpha, iq_best_score] = get_best_model(iq_train_subtrain, iq_train_subtest)
  22. print("saving metrics and params...")
  23. params = {
  24. 'sj_best_alpha': sj_best_alpha,
  25. 'iq_best_alpha': iq_best_alpha,
  26. }
  27. with open('./code/params.json', 'w') as f:
  28. json.dump(params, f)
  29. with open('./metrics/sj_best_score.json', 'w') as f:
  30. json.dump({'sj_best_score': sj_best_score}, f)
  31. with open('./metrics/iq_best_score.json', 'w') as f:
  32. json.dump({'iq_best_score': iq_best_score}, f)
  33. print("saving model as joblib...")
  34. with open("./data/sj_model.pkl", 'wb') as f:
  35. joblib.dump(sj_best_model, f)
  36. with open("./data/iq_model.pkl", 'wb') as f:
  37. joblib.dump(iq_best_model, f)
Tip!

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

Comments

Loading...