Advertisement
Guest User

Untitled

a guest
May 14th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. mypath = '/home/sheiser1/Desktop/zaychik_proj1-master/Dr_Zaychik_Data/selectedData/newData/1D_Data/ready' #'/home/sheiser1/Desktop/zaychik_proj1-master/Dr_Zaychik_Data/selectedData/newData/ready'
  2.  
  3. only_csv_files = [f for f in listdir(mypath) if isfile(join(mypath, f)) and os.path.splitext(f)[1] == '.csv']
  4.  
  5. train_files = [f for f in only_csv_files if f[-5] == 'n']
  6. test_files = [f for f in only_csv_files if f[-5] == 't']
  7.  
  8. def runModel(file_list, train_list, test_list, plot=False):
  9.  
  10.   for file1 in train_list: #train_list #was --> file_list
  11.     save = False
  12.     file_name = os.path.splitext(file1)[0]
  13.     ## MAYBE CHANGE PATH?
  14.     #path = '/home/sheiser1/Desktop/zaychik_proj1-master/Dr_Zaychik_Data/selectedData/newData/ready$' + file_name
  15.     path = '/home/sheiser1/nupic/examples/opf/clients/hotgym/anomaly/one_gym$' + file_name  
  16.     model = None
  17.     if os.path.exists(path):
  18.       model = Model.load(path)
  19.     else:
  20.       model = createModel(getModelParamsFromName(GYM_NAME))
  21.       save = True
  22.      
  23.     print ("Creating model from %s..." % file_name)
  24.     inputData = "%s/%s.csv" % (DATA_DIR, file_name.replace(" ", "_"))
  25.     runIoThroughNupic(inputData, model, file_name, plot)
  26.     if save:
  27.       model.save(path)
  28.  
  29.     for file2 in test_list: #was --> file_list
  30.       file2_name = os.path.splitext(file2)[0]
  31.       model.disableLearning()    
  32.       print ("Running model: " + file_name + ' on: ' + file2_name)
  33.       inputData = "%s/%s.csv" % (DATA_DIR, file2_name.replace(" ", "_"))
  34.       runIoThroughNupic(inputData, model, file2_name, plot)
  35.       os.rename(file2_name + '_out.csv', file_name + '_' + file2_name + '_out.csv')  
  36.  
  37. if __name__ == "__main__":
  38.   print (DESCRIPTION)
  39.   plot = False
  40.   new_model = False
  41.   args = sys.argv[1:]
  42.   if "--plot" in args:
  43.     plot = True
  44.   runModel(only_csv_files,train_files,test_files,plot=plot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement