Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Implementing linear regression in keras
"""
Author: Shubhanshu Mishra
Posted this on the keras issue tracker at: https://github.com/fchollet/keras/issues/108
Implementing a linear regression using Keras.
"""
from keras.models import Sequential
from keras.layers.core import Dense, Activation
model = Sequential()
model.add(Dense(2,1,init='uniform', activation='linear'))
model.compile(loss='mse', optimizer='rmsprop')
model.fit(X_train, y_train, nb_epoch=1000, batch_size=16,verbose=0)
model.fit(X_train, y_train, nb_epoch=1, batch_size=16,verbose=1)
score = model.evaluate(X_test, y_test, batch_size=16)
@scottlawsonbc

This comment has been minimized.

Copy link

scottlawsonbc commented Jun 17, 2016

No longer works on the latest version of Keras

@riders994

This comment has been minimized.

Copy link

riders994 commented Jun 12, 2017

@scottlawsonbc This will work if you reformat the Dense layer to the new format.

@qks1lver

This comment has been minimized.

Copy link

qks1lver commented Jul 12, 2017

Hello, I'm knew to Keras. Can you show me how to write it with the new Dense format? Thanks!

@peachthiefmedia

This comment has been minimized.

Copy link

peachthiefmedia commented Aug 7, 2017

@qks1lver it should be model.add(Dense(1, input_dim=2)) for the new api I think assuming 1 output from two input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.