import numpy as np from process import get_binary_data X, Y = get_binary_data() # data after one hot encoding D = X.shape[1] # D is the no of features w = np.random.randn(D) # w is a cloumn vector b = 0 def sigmoid(a): return 1 / (1 + np.exp(-a)) def forward(X, w, b): return sigmoid(X.dot(w) + b) P_Y_given_X = forward(X, w, b) print("P_Y_given_X=\n"), P_Y_given_X[1:10] predictions = np.round(P_Y_given_X) print("predictions=\n"), predictions[1:10] def classification_rate(Y, P): return np.mean(Y == P) print "Score", classification_rate(Y, predictions)
import numpy as np import matplotlib.pyplot as plt from sklearn.utils import shuffle from process import get_binary_data Xtrain, Ytrain, Xtest, Ytest = get_binary_data() #X, Y = shuffle(X, Y) # Separate out test and training data. # testsize = 100 # Xtrain = X[:-testsize] # Ytrain = Y[:-testsize] # Xtest = X[-testsize:] # Ytest = Y[-testsize:] # Randomly initialize weights D = Xtrain.shape[1] W = np.random.randn(D) b = 0 def sigmoid(z): return 1 / (1 + np.exp(-z)) def forward(X, W, b): return sigmoid(X.dot(W) + b) def classification_rate(Y, P):
import numpy as np from process import get_binary_data X, y = get_binary_data() D = X.shape[1] W = np.random.randn(D) b = 0 def sigmoid(a): return 1 / (1 + np.exp(-a)) def forward(X, W, b): return sigmoid(X.dot(W) + b) P_y_given_X = forward(X, W, b) predictions = np.round(P_y_given_X) def classification_rate(Y, P): return np.mean(Y == P) print("Score:", classification_rate(y, predictions))
import numpy as np from process import get_binary_data X, Y = get_binary_data() D = X.shape[1] W = np.random.randn(D) b = 0 def sigmoid(a): return 1 / (1 + np.exp(-a)) def forward(X, W, b): return sigmoid(X.dot(W) + b) P_Y_given_X = forward(X, W, b) predictions = np.round(P_Y_given_X) def classificaiton_rate(Y, P): return np.mean(Y == P) print("Score ", classificaiton_rate(Y, predictions))
from __future__ import print_function, division # Note: you may need to update your version of future # sudo pip install -U future import numpy as np from process import get_binary_data X, Y, _, _ = get_binary_data() print(X) print(X.shape) print(Y) print(Y.shape) # randomly initialize weights D = X.shape[1] W = np.random.randn(D) b = 0 # bias term # make predictions # sigmoid takes a function in form mx + b def sigmoid(a): return 1 / (1 + np.exp(-a)) def forward(X, W, b): return sigmoid(X.dot(W) + b)
import numpy as np from process import get_binary_data X, Y = get_binary_data() # randomly initialize weights D = X.shape[1] W = np.random.randn(D) b = 0 # bias term # make predictions def sigmoid(a): return 1 / (1 + np.exp(-a)) def forward(X, W, b): return sigmoid(X.dot(W) + b) P_Y_given_X = forward(X, W, b) predictions = np.round(P_Y_given_X) # calculate the accuracy def classification_rate(Y, P): return np.mean(Y == P) print "Score:", classification_rate(Y, predictions)
from __future__ import print_function, division from builtins import range # Note: you may need to update your version of future # sudo pip install -U future import numpy as np from process import get_binary_data X, Y, _, _ = get_binary_data() # randomly initialize weights D = X.shape[1] W = np.random.randn(D) b = 0 # bias term # make predictions def sigmoid(a): return 1 / (1 + np.exp(-a)) def forward(X, W, b): return sigmoid(X.dot(W) + b) P_Y_given_X = forward(X, W, b) predictions = np.round(P_Y_given_X) # calculate the accuracy def classification_rate(Y, P): return np.mean(Y == P) print("Score:", classification_rate(Y, predictions))
def __init__(self): self.X = DataPair() self.Y = DataPair() self.X.train, self.Y.train, self.X.test, self.Y.test = get_binary_data( )
from __future__ import print_function, division from builtins import range # Note: you may need to update your version of future # sudo pip install -U future import numpy as np import matplotlib.pyplot as plt from sklearn.utils import shuffle from process import get_binary_data # get the data Xtrain, Ytrain, Xtest, Ytest = get_binary_data() # randomly initialize weights D = Xtrain.shape[1] W = np.random.randn(D) b = 0 # bias term # make predictions def sigmoid(a): return 1 / (1 + np.exp(-a)) def forward(X, W, b): return sigmoid(X.dot(W) + b) # calculate the accuracy def classification_rate(Y, P): return np.mean(Y == P)