Guest User

Untitled

a guest
Jan 19th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import numpy as np
  2. import sys
  3. from numpy import genfromtxt
  4.  
  5. train_file = sys.argv[1]
  6. dev_file = sys.argv[2]
  7. learning = sys.argv[3]
  8.  
  9. X_train = np.genfromtxt(train_file, dtype='f', delimiter = ',', skip_header
  10. = 1,filling_values = 0, usecols =
  11. (3,4,5,6,8,9,10,11,12,13,14,15,17,18,19,20))
  12. y_train = np.genfromtxt(train_file, dtype='f', delimiter = ',', skip_header
  13. = 1,filling_values = 0, usecols = (2))
  14.  
  15. training_examples = X_train.shape[0]
  16. total_featues = X_train.shape[1]
  17.  
  18. Wprime = np.asarray([0]*total_featues)
  19. W = Wprime.reshape(-1,1)
  20.  
  21.  
  22. k = 0
  23. while k<total_featues :
  24. i=0
  25. temp_sum = 0
  26. #print(X_train[i][k])
  27. while i< training_examples:
  28. A = Wprime
  29. B = X_train[i]
  30. #print(y_train[i])
  31. f = abs(np.dot(A,B)-y_train[i])
  32. #print("this is f"+str(f))
  33. f = f*X_train[i][k]
  34. temp_sum = temp_sum + f
  35. i=i+1
  36. print("this is temp sum " + str(temp_sum))
  37. update = temp_sum*0.0001/training_examples
  38. print("this is update "+str(update))
  39. Wprime[k] = Wprime[k] - update
  40. print(Wprime)
  41. k = k+1
Add Comment
Please, Sign In to add comment