Changeset 112c79 in git for machine_learning/predictor_runner.py
- Timestamp:
- Aug 2, 2019, 7:35:10 PM (5 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 58603fd7faac3d049f61ca0b65d89e4be0a664f9
- Parents:
- fece1392f8e9ff07b64d0ed4e5ec57bfa6dbf258
- git-author:
- Murray Heymann <heymann.murray@gmail.com>2019-08-02 19:35:10+02:00
- git-committer:
- Murray Heymann <heymann.murray@gmail.com>2019-08-02 19:35:13+02:00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
machine_learning/predictor_runner.py
rfece13 r112c79 5 5 import os 6 6 import sys 7 import time 7 8 import numpy as np 8 from model.predictor import * 9 10 from model.predictor import HelpPagePredictor 11 from common.keyword_vector import read_dictionary, count_occurances 12 from common.lookuptable import create_table 13 from common.constants import KEYWORDS_FILE 9 14 10 15 def find_prediction(filename): 16 """ 17 Given a file name as string, get the predicted help page name 18 """ 11 19 dictionary = read_dictionary(KEYWORDS_FILE) 20 12 21 start = time.time() 13 22 vectors, file_list = create_table(dictionary=dictionary) … … 15 24 print(end - start, "seconds to create_table") 16 25 26 return _find_prediction(filename, dictionary, vectors, file_list) 27 28 29 def _find_prediction(filename, dictionary, vectors, file_list): 30 """ 31 Train a predictor, get the predicted help page name 32 """ 17 33 predictor = HelpPagePredictor() 18 34 predictor.fit(vectors, file_list) … … 24 40 print(end - start, "seconds to make prediction") 25 41 return prediction 26 42 27 43 28 44 def main(): … … 42 58 predictor.fit(vectors, file_list) 43 59 44 start = time.time()45 test_vec = count_occurances("extract.lib", dictionary)46 prediction = predictor.predict(np.array([test_vec]))47 end = time.time()48 print(end - start, "seconds to make prediction")49 print(prediction)50 print()51 52 60 print("prediction for zero vector") 53 61 start = time.time() … … 59 67 print() 60 68 69 prediction = _find_prediction("extract.lib", 70 dictionary, 71 vectors, 72 file_list) 73 print(prediction) 74 print() 75 76 61 77 if len(sys.argv) >= 2: 62 78 for i in range(len(sys.argv)): … … 65 81 if not os.path.isfile(sys.argv[i]): 66 82 continue 83 67 84 print("predicting for file", sys.argv[i]) 68 start = time.time() 69 test_vec = count_occurances(sys.argv[i], dictionary) 70 prediction = predictor.predict(np.array([test_vec])) 71 end = time.time() 72 print(end - start, "seconds to make prediction") 85 prediction = _find_prediction(sys.argv[i], 86 dictionary, 87 vectors, 88 file_list) 73 89 print(prediction) 74 90 print()
Note: See TracChangeset
for help on using the changeset viewer.