Created
August 11, 2018 15:17
-
-
Save yingshaoxo/04dcd96f62b1782f05b65a33525e96ba to your computer and use it in GitHub Desktop.
Keras simplest multiple variable regression example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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