Skip to content

Instantly share code, notes, and snippets.

@a46554
Created May 12, 2020 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a46554/9083288745907be2d37f72bc5d4ef0a6 to your computer and use it in GitHub Desktop.
Save a46554/9083288745907be2d37f72bc5d4ef0a6 to your computer and use it in GitHub Desktop.
import tensorflow as tf
iport numpy as np
from tensorflow import keras
# Create an 1*1 layer neuron
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
# Setting optimizer and loss function
model.compile(optimizer='sgd', loss='mean_squared_error')
# Training data
xs = np.array([1, 2, 3, 4], dtype=int)
ys = np.array([100, 150, 200, 250], dtype=int)
# Training mode for 500 iteration
model.fit(xs, ys, epochs=500)
# Predict the output
print(model.predict([7.0]))m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment