Skip to content

Instantly share code, notes, and snippets.

@hangj
Created January 26, 2025 15:54
Show Gist options
  • Save hangj/43dbbe364eb7b96d8b3844468dabe667 to your computer and use it in GitHub Desktop.
Save hangj/43dbbe364eb7b96d8b3844468dabe667 to your computer and use it in GitHub Desktop.
import tensorflow as tf
import tensorflow.keras as keras
import numpy as np
model = keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
model.compile(optimizer='sgd', loss='mean_squared_error')
xs = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float)
ys = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float)
model.fit(xs, ys, epochs=500)
model.predict(np.array([10.0], dtype=float))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment