Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yingshaoxo/04dcd96f62b1782f05b65a33525e96ba to your computer and use it in GitHub Desktop.
Save yingshaoxo/04dcd96f62b1782f05b65a33525e96ba to your computer and use it in GitHub Desktop.
Keras simplest multiple variable regression example
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(units=3, input_dim=3)) #`input_dim`
model.add(Dense(units=1)) #`last layer's units
model.compile(loss='mean_squared_error',
optimizer='sgd',
metrics=['accuracy'])
import numpy as np
x = [[1,2,3], [1,2,1]] #you got 3 numbers in every sub-list, so `input_dim=3`
y = [[5], [4]] #you got 1 numbers in every target sub-list, so you have to make sure the `last layer's units = 1`
x = np.array(x)
y = np.array(y)
model.fit(x, y, epochs=1, batch_size=1)
print("\n\n\n" + "made by yingshaoxo" + "\n\n\n")
inputs = np.array([[1,1,1]])
print(model.predict(inputs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment