Skip to content

Instantly share code, notes, and snippets.

@sivsivsree
Created May 13, 2019 08:45
Show Gist options
  • Select an option

  • Save sivsivsree/565b15c36daf6325cfff9500a74b07e4 to your computer and use it in GitHub Desktop.

Select an option

Save sivsivsree/565b15c36daf6325cfff9500a74b07e4 to your computer and use it in GitHub Desktop.
Predict y = 5 ( x +1 )
import tensorflow as tf
import numpy as np
from tensorflow import keras
model = keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
model.compile(optimizer='sgd', loss='mean_squared_error')
xs = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], dtype=float)
ys = np.array([5.0,10.0,15.0,20.0,25.0,30.0, 35.0, 40.0, 45.0,50.0], dtype=float)
model.fit(xs, ys, epochs=2500)
print(model.predict([20.0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment