Celsius to Fahrenheit convertor
steps involved are:
1) Importing necessary dependencies:
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
2) Set up training data:
celsius_q = np.array([0, 8, 15, 22,100 ], dtype=float )
fahrenheit_a = np.array([32, 46.4, 59, 71.6,180], dtype=float )
for i,c in enumerate(celsius_q):
print("{} degree Celcius = {} degree Fahrenhet" .format(c, fahrenheit_a[i]))
3) Defining the layer for CNN:
l0 = tf.keras.layers.Dense(units = 1, input_shape=[1] )
4) Assembling layer into model:
model = tf.keras.Sequential([l0])
5)Compile the model with loss and optimizer function:
model.compile(loss = 'mean_squared_error',
optimizer = tf.keras.optimizers.Adam(0.1))
6)Training the model:
history = model.fit(celsius_q, fahrenheit_a, epochs = 500, verbose = False )
print("Finished training the model")
7) Displaying trained statistics:
plt.xlabel('Epoch Number')
plt.ylabel('Loss Magnitude')
plt.plot(history.history['loss'])
8)predicting values:
print(model.predict([100]))
print(model.predict([0]))
by running above code in Jupyter notebook step by step you can observe how things are going on.
No comments:
Post a Comment