Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. adjustment = dot(training_set_inputs.T, error * self.__sigmoid_derivative(output)) ValueError: shapes (3,2736,1) and (1,2736,1) not aligned: 1 (dim 2) != 2736 (dim 1)
  2.  
  3. Model | Trim | Cost
  4. 6 | 102 | 1200
  5. 8 | 105 | 1500
  6. 15 | 110 | 3000
  7.  
  8.  
  9. df = pd.read_csv('fulldata.csv')
  10. y = np.array(df[['Success']])
  11. y.reshape(y.size, 1)
  12.  
  13. df.drop(['Success'],1 , inplace=True)
  14.  
  15. t_in = df.values.tolist()
  16.  
  17. class NeuralNetwork():
  18. def __init__(self):
  19. # Seed the random number generator
  20. random.seed(1)
  21. self.synaptic_weights = 2 * random.random((3,1)) - 1
  22.  
  23. def __sigmoid(self, x):
  24. return 1 /(1 + exp(-x))
  25.  
  26. def __sigmoid_derivative(self, x):
  27. return x * (1-x)
  28.  
  29. def train(self, training_set_inputs, training_set_outputs, number_of_training_iterations):
  30. for iteration in xrange(number_of_training_iterations):
  31. output = self.predict(training_set_inputs)
  32.  
  33. error = training_set_outputs - output
  34.  
  35. adjustment = dot(training_set_inputs.T, error * self.__sigmoid_derivative(output))
  36.  
  37. self.synaptic_weights += adjustment
  38.  
  39.  
  40. def predict(self, inputs):
  41. return self.__sigmoid(dot(inputs, self.synaptic_weights))
  42.  
  43.  
  44. if __name__=="__main__":
  45.  
  46. #initialize a single neuron neural network
  47. neural_network = NeuralNetwork()
  48.  
  49. # training data inputs / outputs
  50. training_set_inputs = array([t_in])
  51. training_set_outputs = array([y]).T
  52.  
  53. # number of iterations
  54. neural_network.train(training_set_inputs, training_set_outputs, 10000)
  55.  
  56. # new input to predict
  57. my_input = array([6,102,3000])
  58.  
  59. print 'New synaptic weights after training'
  60. print neural_network.synaptic_weights
  61.  
  62. print 'Predicting'
  63.  
  64. my_prediction = neural_network.predict(my_input)
  65. print (my_prediction)
  66.  
  67. # t_in = [[6.0, 102.0, 0.0], [61.0, 138.0, 12414.0], [224.0, 291.0, 30309.0]]
  68.  
  69. #y = [[ 1.]
  70. [ 1.]
  71. [ 1.]
  72. ...,
  73. [ 0.]
  74. [ 0.]
  75. [ 0.]]
  76.  
  77. adjustment = dot(training_set_inputs.T, error * self.__sigmoid_derivative(output)) ValueError: shapes (3,2736,1) and (1,2736,1) not aligned: 1 (dim 2) != 2736 (dim 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement