vinayarun

Main program for neural network

Mar 16th, 2016
73
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. input_layer_size  = 3;  
  2. hidden_layer_size = 5;  
  3. num_labels = 1;
  4.  
  5. X = load('X.csv');
  6. y = load('y.csv');
  7.  
  8. fprintf('\nInitializing Neural Network Parameters ...\n')
  9.  
  10. initial_Theta1 = randInitializeWeights(input_layer_size, hidden_layer_size);
  11. initial_Theta2 = randInitializeWeights(hidden_layer_size, num_labels);
  12.  
  13. % Unroll parameters
  14. initial_nn_params = [initial_Theta1(:) ; initial_Theta2(:)];
  15.  
  16. options = optimset('MaxIter', 350);
  17. lambda = 0.5;
  18. costFunction = @(p) nnCostFunction(p, ...
  19.                                    input_layer_size, ...
  20.                                    hidden_layer_size, ...
  21.                                    num_labels, X, y, lambda);
  22.  
  23. [nn_params, cost] = fmincg(costFunction, initial_nn_params, options);
  24.  
  25. Theta1 = reshape(nn_params(1:hidden_layer_size * (input_layer_size + 1)), ...
  26.                  hidden_layer_size, (input_layer_size + 1));
  27.  
  28. Theta2 = reshape(nn_params((1 + (hidden_layer_size * (input_layer_size + 1))):end), ...
  29.                  num_labels, (hidden_layer_size + 1));
  30.  
  31. pred = predict(Theta1, Theta2, X);
  32.  
  33. fprintf('\nTraining Set Accuracy: %f\n', mean(double(pred == y)) * 100);
RAW Paste Data