Skip to content

Instantly share code, notes, and snippets.

View 97k's full-sized avatar
🎯
Learning... 👨‍💻 🛠️

Aditya Kaushik 97k

🎯
Learning... 👨‍💻 🛠️
View GitHub Profile
@97k
97k / backpropagation.py
Last active April 12, 2019 08:48
Backpropagation code for deep neural net
def backprop_this_layer(self, da_curr, z_curr, W_curr, b_curr, A_prev, activation_function):
if activation_function is 'sigmoid':
activation_back = self.sigmoid_backward
elif activation_function is 'relu':
activation_back = self.relu_backward
else:
return
m = A_prev.shape[1]
dz_curr = activation_back(da_curr, z_curr)
@97k
97k / ForwardPass.py
Created March 19, 2019 12:04
Forward Propagation
def forward_prop_this_layer(self, A_prev, W_curr, b_curr, activation_function):
z_curr = np.dot(W_curr, A_prev) + b_curr
if activation_function is 'relu':
activation = relu
elif activation_function is 'sigmoid':
activation = sigmoid
else:
raise Exception(f"{activation_function} is currently not supported, Only sigmoid, relu are supported")
def initialize_params(self, architecture):
# We'll save parameters in a dictionary so that, we can acess them later on
params = {}
for id_, layer in enumerate(architecture):
# We're starting our layer from 1, There's a reason for this, think about it.
layer_id = id_ + 1
# With help of architecture provided, we'll get dimensions for each layer.
input_dim = layer['input_dim']
output_dim = layer['output_dim']
@97k
97k / architecture.py
Last active March 18, 2019 09:29
neural network architecture
NN_ARCHITECTURE = [
{"input_dim": 3, "output_dim": 4, "activation": "relu"},# First Hidden Layer
{"input_dim": 4, "output_dim": 4, "activation": "relu"},# Second Hidden Layer
{"input_dim": 4, "output_dim": 1, "activation": "sigmoid"},# Output Layer
]
@97k
97k / Kmeans.py
Created July 12, 2018 11:32
Sample Code which represent Kmeans algo and plots the result using matplotlib. Dataset was made using make_blobs(sklearn.dataset.make_blobs)
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import make_blobs
# data is a tuple with 2 columns, one is the dataset that we made, and second is the labels representing centre.
data = make_blobs(n_samples = 200, n_features=2, centers=3, cluster_std=1.5)
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=3)
kmeans.fit(data[0])
@97k
97k / Codeheat.md
Created February 1, 2018 18:37
CodeHeat 2017-18 | Final Gist

CodeHeat 2017-18

Code Contributions:

I have worked on following projects in this contest :