Advertisement
Guest User

Untitled

a guest
Dec 26th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. import numpy as np
  2. from sigmoid import *
  3.  
  4. def predict(X, Theta, num_layers=2):
  5.     """
  6.    Predict the label of an input given a tarined neural network
  7.  
  8.    Parameters:
  9.    -----------
  10.    X : 2D-array (m_examples, n_features)
  11.        input for the hypothesis to predict.
  12.  
  13.    Theta :
  14.        Array of weights between layers
  15.    """
  16.     m_examples, n_features = X.shape
  17.  
  18.     # Input Layer
  19.     a1 = np.r_[np.ones((1, m_examples)), X.T]
  20.  
  21.     # Hidden Layer
  22.     a2 = sigmoid(Theta[0].dot(a1))
  23.     a2 = np.r_[np.ones((1,m_examples)), a2]
  24.  
  25.     # Output Layer
  26.     a3 = sigmoid(Theta[1].dot(a2))
  27.  
  28.     # Return predictions
  29.     return np.argmax(a3, axis=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement