Changeset 50e872 in git for machine_learning/model/predictor.py
- Timestamp:
- Jul 30, 2019, 8:28:06 PM (5 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- fece1392f8e9ff07b64d0ed4e5ec57bfa6dbf258
- Parents:
- da892581a52069935f084604d05c0ecd6d19d5c9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
machine_learning/model/predictor.py
rda8925 r50e872 66 66 ret_list.append(file) 67 67 return np.array(ret_list) 68 69 70 def basic_vector_tests():71 """72 Some basic sanity tests73 """74 predictor = HelpPagePredictor()75 vector1 = normalise_vector(np.array([1, 4, 10]))76 vector2 = normalise_vector(np.array([2, 3, 1]))77 vector3 = normalise_vector(np.array([3, 9, 3]))78 79 vectors = np.array([vector1, vector2, vector3])80 files = np.array(["file1", "file2", "file3"])81 print(vectors)82 print(files)83 print()84 85 testvec = normalise_vector(np.array([1, 1, 1]))86 print("test vector:")87 print(testvec)88 print()89 90 print("distance to 1")91 print(vector_distance(testvec, vector1))92 print()93 print("distance to 2")94 print(vector_distance(testvec, vector2))95 print()96 print("distance to 3")97 print(vector_distance(testvec, vector3))98 print()99 100 predictor.fit(vectors, files)101 prediction = predictor.predict(np.array([testvec]))102 print("Prediction:")103 print(prediction)104 print()105 106 107 def main():108 """109 Run some basic tests110 """111 print("Running some tests")112 113 basic_vector_tests()114 115 dictionary = read_dictionary(KEYWORDS_FILE)116 117 start = time.time()118 vectors, file_list = create_table(dictionary=dictionary)119 end = time.time()120 print(end - start, "seconds to create_table")121 122 predictor = HelpPagePredictor()123 predictor.fit(vectors, file_list)124 125 start = time.time()126 test_vec = count_occurances("extract.lib", dictionary)127 prediction = predictor.predict(np.array([test_vec]))128 end = time.time()129 print(end - start, "seconds to make prediction")130 print(prediction)131 print()132 133 print("prediction for zero vector")134 start = time.time()135 zerovec = np.zeros(len(dictionary) - 2)136 prediction = predictor.predict(np.array([zerovec]))137 end = time.time()138 print(end - start, "seconds to make prediction")139 print(prediction)140 print()141 142 if len(sys.argv) >= 2:143 for i in range(len(sys.argv)):144 if i == 0:145 continue146 if not os.path.isfile(sys.argv[i]):147 continue148 print("predicting for file", sys.argv[i])149 start = time.time()150 test_vec = count_occurances(sys.argv[i], dictionary)151 prediction = predictor.predict(np.array([test_vec]))152 end = time.time()153 print(end - start, "seconds to make prediction")154 print(prediction)155 print()156 157 158 if __name__ == '__main__':159 #cProfile.run("main()")160 main()
Note: See TracChangeset
for help on using the changeset viewer.