pip install tensorflow
pip install numpy (Este módulo permite realizar cálculos con Python, por lo general viene instalado por defecto)
pip install matplotlib
import tensorflow as tf import numpy as np
celsius = np.array([-40, -10, 0, 8, 15, 22, 38], dtype=float) fahrenheit= np.array([-40, 14, 32, 46, 59, 72, 100], dtype=float)
layer = tf.keras.layers.Dense(units=1, input_shape=[1]) model = tf.keras.Sequential([layer])
model.compile( optimizer=tf.keras.optimizers.Adam(0.1), loss='mean_squared_error' )
print("Starting training...") history = model.fit(celsius, fahrenheit, epochs=1000, verbose=False) print("Trained model")
import matplotlib.pyplot as plt plt.xlabel("# Period") plt.ylabel("Magnitude of loss") plt.plot(history.history["loss"]) plt.show()
print("Let's make a prediction!") result = model.predict([100.0]) print("The result is " + str(result) + " Fahrenheit")
print("Internal model variables") print(layer.get_weights())