#!/usr/bin/env python # coding: utf-8 # In[ ]: import tensorflow as tf import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import os # print(os.getcwd()) #df = pd.read_csv('/mnt/batch/tasks/shared/LS_root/mounts/clusters/computeforaml/code/Users/luolala701/Kilometres-miles.csv') # df.info df = pd.read_csv('C://Users//luona//Downloads//Kilometres-miles.csv') # In[10]: #print('Painting the correlations') #sns.scatterplot(df['Kilometres'], df['Miles']) #plt.show() # In[13]: print('Define input(X) and output(Y) variables') X_train = df['Kilometres'] Y_train = df['Miles'] # In[16]: print('Creating the model') model = tf.keras.Sequential() model.add(tf.keras.layers.Dense(units=1, input_shape=[1])) # In[17]: print('Compiling the model') model.compile(optimizer=tf.keras.optimizers.Adam(1), loss='mean_squared_error') # In[18]: print('Training the model') epochs_hist = model.fit(X_train, Y_train, epochs = 250) # In[19]: print('Evaluating the model') print(epochs_hist.history.keys()) #graph plt.plot(epochs_hist.history['loss']) plt.title('Evolution of the error associated with the model') plt.xlabel('Epoch') plt.ylabel('Training Loss') plt.legend('Training Loss') plt.show() # In[20]: kilometers = 100 predictedMiles = model.predict([kilometers]) print("The conversion from Kilometres to Miles is as follows: " + str(predictedMiles)) # In[21]: milesByFormula = kilometers * 0.6214 print("The conversion from kilometers to miles using the mathematical formula is as follows:" + str(milesByFormula)) diference = milesByFormula - predictedMiles print("Prediction error:" + str(diference)) # In[ ]: