Changeset feed60b in git
- Timestamp:
- Jul 30, 2019, 12:24:25 AM (4 years ago)
- Branches:
- (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
- Children:
- de88e1d84f18979811df4c3d1dc68f221a3362ef
- Parents:
- 8d8fefe7898bd9e2156488544587049b7107d0c1
- Location:
- machine_learning
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
machine_learning/common/keyword_vector.py
r8d8fef rfeed60b 3 3 """Some vector logic""" 4 4 5 import numpy as np6 5 import os 7 6 import re 8 7 import sys 9 import traceback8 import numpy as np 10 9 11 10 from common.constants import KEYWORDS_FILE … … 19 18 if not os.path.isfile(filename): 20 19 print("Please provide a valid input file as argument") 21 return []20 return np.array([]) 22 21 23 22 dictionary = [] … … 148 147 149 148 print("Attempt to normalise the zero vector") 150 print(normalise_vector(np.array([0, 0,0,0,0])))149 print(normalise_vector(np.array([0, 0, 0, 0, 0]))) 151 150 print() 152 151 153 152 print("Attempt to normalise list") 154 print(normalise_vector([3, 4,0,0,0]))153 print(normalise_vector([3, 4, 0, 0, 0])) 155 154 print() 156 155 -
machine_learning/common/lookuptable.py
r8d8fef rfeed60b 120 120 test_vec = count_occurances(os.path.join(HELP_FILE_PATH, "html", 121 121 files[1]), dictionary) 122 print((test_vec ==vectors[1]).all())122 print((test_vec == vectors[1]).all()) 123 123 124 124 -
machine_learning/model/predictor.py
r8d8fef rfeed60b 3 3 """ 4 4 5 import cProfile5 # import cProfile 6 6 import os 7 7 import sys … … 56 56 # dist = vector_distance(x, vec) 57 57 # Dot product is much faster 58 dist = - np.dot(x, vec)58 dist = -1 * np.dot(x, vec) 59 59 if dist < min_val: 60 60 min_val = dist … … 68 68 69 69 70 def main():70 def basic_vector_tests(): 71 71 """ 72 Run some basictests72 Some basic sanity tests 73 73 """ 74 print("Running some tests")75 74 predictor = HelpPagePredictor() 76 vector1 = normalise_vector( [1, 4, 10])77 vector2 = normalise_vector( [2, 3, 1])78 vector3 = normalise_vector( [3, 9, 3])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])) 79 78 80 79 vectors = np.array([vector1, vector2, vector3]) … … 84 83 print() 85 84 86 testvec = normalise_vector( [1, 1, 1])85 testvec = normalise_vector(np.array([1, 1, 1])) 87 86 print("test vector:") 88 87 print(testvec) … … 105 104 print() 106 105 106 107 def main(): 108 """ 109 Run some basic tests 110 """ 111 print("Running some tests") 112 113 basic_vector_tests() 114 107 115 dictionary = read_dictionary(KEYWORDS_FILE) 108 116 … … 113 121 114 122 test_vec = count_occurances("extract.lib", dictionary) 123 predictor = HelpPagePredictor() 115 124 predictor.fit(vectors, file_list) 116 125 … … 124 133 print("prediction for zero vector") 125 134 zerovec = np.zeros(len(dictionary) - 2) 126 print(len(zerovec))127 135 start = time.time() 128 136 prediction = predictor.predict(np.array([zerovec])) … … 138 146 if not os.path.isfile(sys.argv[i]): 139 147 continue 140 print 148 print("predicting for file", sys.argv[i]) 141 149 test_vec = count_occurances(sys.argv[i], dictionary) 142 150 start = time.time()
Note: See TracChangeset
for help on using the changeset viewer.