Skip to content

Instantly share code, notes, and snippets.

@macromaniac
Created September 17, 2016 18:47
Show Gist options
  • Save macromaniac/630df68eb42d881755a3e30343252f74 to your computer and use it in GitHub Desktop.
Save macromaniac/630df68eb42d881755a3e30343252f74 to your computer and use it in GitHub Desktop.
simple linear regression example using keras
import numpy as np
from keras.layers import Dense, Input
from keras.models import Model
x = Input((1,))
y = Dense(1, activation ='linear')(x)
m = Model(x,y)
m.compile(loss = 'mse', optimizer='sgd')
_x = np.linspace(1,2, num = 1e3)
m.fit(_x, 2*_x + 1, batch_size=1)
print m.get_weights()
@regivm
Copy link

regivm commented Dec 27, 2019

I have been desperately trying to create an ANN and match it with Regression coefficients. This work saved my day. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment