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

09_score.py 2.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  1. import os
  2. import pickle
  3. import sys
  4. import argparse
  5. import numpy as np
  6. import pandas as pd
  7. import seaborn as sns
  8. # testing
  9. from pandas.testing import assert_frame_equal
  10. from tqdm import tqdm
  11. import j_utils.munging as mg
  12. from lendingclub.lc_utils import gen_datasets
  13. from lendingclub import config
  14. from lendingclub.modeling.models import Model
  15. parser = argparse.ArgumentParser()
  16. parser.add_argument('--model', '-m', help='specify model(s) to train')
  17. parser.add_argument('--combine', '-c', help='Boolean, if model scores need to be combined in some way')
  18. if not len(sys.argv) > 1:
  19. models = ['baseline'] # , 'A', 'B', 'C', 'D', 'E', 'F', 'G'
  20. args = parser.parse_args()
  21. if args.model:
  22. models = args.model.split()
  23. combine = args.combine
  24. # load in relevant dataframes
  25. base_loan_info = pd.read_feather(os.path.join(config.data_dir, 'base_loan_info.fth'))
  26. try:
  27. eval_loan_info = pd.read_feather(os.path.join(config.data_dir, 'eval_loan_info_scored.fth'))
  28. print('found an existing eval_loan_info_scored.fth to add scores')
  29. all_scores = pd.read_feather(os.path.join(config.data_dir, 'all_eval_loan_info_scored.fth'))
  30. print('found an existing all_eval_loan_info_scored.fth to add scores')
  31. except:
  32. eval_loan_info = pd.read_feather(os.path.join(config.data_dir, 'eval_loan_info.fth'))
  33. print('no existing eval_loan_info_scored.fth')
  34. print('this is the first time adding scores')
  35. all_scores = pd.read_feather(os.path.join(config.data_dir, 'eval_loan_info.fth'))
  36. print('no existing all_eval_loan_info_scored.fth')
  37. print('this is the first time adding scores')
  38. # check that loans are all in correct order
  39. assert (base_loan_info['id'] == eval_loan_info['id']).all()
  40. # score relevant dataframes
  41. for model_n in models:
  42. m = Model(model_n)
  43. scores = m.score(base_loan_info)
  44. eval_loan_info['{0}_score'.format(model_n)] = scores
  45. all_scores['{0}_score'.format(model_n)] = scores
  46. # one more step if using combination scores:
  47. print(combine)
  48. print('saving scored dataframe at {0}'.format(os.path.join(config.data_dir,'eval_loan_info_scored.fth')))
  49. eval_loan_info.to_feather(os.path.join(config.data_dir,'eval_loan_info_scored.fth'))
  50. print('saving dvc non-tracked scored dataframe at {0}'.format(os.path.join(config.data_dir,'all_eval_loan_info_scored.fth')))
  51. eval_loan_info.to_feather(os.path.join(config.data_dir,'all_eval_loan_info_scored.fth'))
Tip!

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

Comments

Loading...