Skip to content

Instantly share code, notes, and snippets.

View cedricconol's full-sized avatar

Cedric Conol cedricconol

  • Philippines
View GitHub Profile
@cedricconol
cedricconol / linregtftrain.py
Created May 23, 2020 03:43
Linear regression TF2 train
def train(self, X, y, learning_rate=0.01, epochs=5):
if len(X.shape)==1:
X=tf.reshape(X,[X.shape[0],1])
self.m.assign([self.var]*X.shape[-1])
for i in range(epochs):
print("Epoch: ", i)
@cedricconol
cedricconol / linregtf.py
Created May 23, 2020 03:48
Linear regression in TF2
class SimpleLinearRegression:
def __init__(self, initializer='random'):
if initializer=='ones':
self.var = 1.
elif initializer=='zeros':
self.var = 0.
elif initializer=='random':
selfx.var = tf.random.uniform(shape=[], minval=0., maxval=1.)
self.m = tf.Variable(1., shape=tf.TensorShape(None))