add one model with tensorflow as sample
Browse files- README.md +0 -1
- kilomileprediction.py +94 -0
- requirements.txt +4 -0
README.md
CHANGED
@@ -13,7 +13,6 @@ thumbnail: "url to a thumbnail used in social sharing"
|
|
13 |
tags:
|
14 |
- speech
|
15 |
- audio
|
16 |
-
- flair
|
17 |
license: "any valid license identifier"
|
18 |
datasets:
|
19 |
- dataset1
|
|
|
13 |
tags:
|
14 |
- speech
|
15 |
- audio
|
|
|
16 |
license: "any valid license identifier"
|
17 |
datasets:
|
18 |
- dataset1
|
kilomileprediction.py
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
# In[ ]:
|
5 |
+
|
6 |
+
|
7 |
+
import tensorflow as tf
|
8 |
+
import pandas as pd
|
9 |
+
import seaborn as sns
|
10 |
+
import matplotlib.pyplot as plt
|
11 |
+
import os
|
12 |
+
|
13 |
+
# print(os.getcwd())
|
14 |
+
|
15 |
+
#df = pd.read_csv('/mnt/batch/tasks/shared/LS_root/mounts/clusters/computeforaml/code/Users/luolala701/Kilometres-miles.csv')
|
16 |
+
# df.info
|
17 |
+
df = pd.read_csv('C://Users//luona//Downloads//Kilometres-miles.csv')
|
18 |
+
|
19 |
+
|
20 |
+
# In[10]:
|
21 |
+
|
22 |
+
|
23 |
+
#print('Painting the correlations')
|
24 |
+
#sns.scatterplot(df['Kilometres'], df['Miles'])
|
25 |
+
#plt.show()
|
26 |
+
|
27 |
+
|
28 |
+
# In[13]:
|
29 |
+
|
30 |
+
|
31 |
+
print('Define input(X) and output(Y) variables')
|
32 |
+
X_train = df['Kilometres']
|
33 |
+
Y_train = df['Miles']
|
34 |
+
|
35 |
+
|
36 |
+
# In[16]:
|
37 |
+
|
38 |
+
|
39 |
+
print('Creating the model')
|
40 |
+
model = tf.keras.Sequential()
|
41 |
+
model.add(tf.keras.layers.Dense(units=1, input_shape=[1]))
|
42 |
+
|
43 |
+
|
44 |
+
# In[17]:
|
45 |
+
|
46 |
+
|
47 |
+
print('Compiling the model')
|
48 |
+
model.compile(optimizer=tf.keras.optimizers.Adam(1), loss='mean_squared_error')
|
49 |
+
|
50 |
+
|
51 |
+
# In[18]:
|
52 |
+
|
53 |
+
|
54 |
+
print('Training the model')
|
55 |
+
epochs_hist = model.fit(X_train, Y_train, epochs = 250)
|
56 |
+
|
57 |
+
|
58 |
+
# In[19]:
|
59 |
+
|
60 |
+
|
61 |
+
print('Evaluating the model')
|
62 |
+
print(epochs_hist.history.keys())
|
63 |
+
|
64 |
+
#graph
|
65 |
+
plt.plot(epochs_hist.history['loss'])
|
66 |
+
plt.title('Evolution of the error associated with the model')
|
67 |
+
plt.xlabel('Epoch')
|
68 |
+
plt.ylabel('Training Loss')
|
69 |
+
plt.legend('Training Loss')
|
70 |
+
plt.show()
|
71 |
+
|
72 |
+
|
73 |
+
# In[20]:
|
74 |
+
|
75 |
+
|
76 |
+
kilometers = 100
|
77 |
+
predictedMiles = model.predict([kilometers])
|
78 |
+
print("The conversion from Kilometres to Miles is as follows: " + str(predictedMiles))
|
79 |
+
|
80 |
+
|
81 |
+
# In[21]:
|
82 |
+
|
83 |
+
|
84 |
+
milesByFormula = kilometers * 0.6214
|
85 |
+
print("The conversion from kilometers to miles using the mathematical formula is as follows:" + str(milesByFormula))
|
86 |
+
diference = milesByFormula - predictedMiles
|
87 |
+
print("Prediction error:" + str(diference))
|
88 |
+
|
89 |
+
|
90 |
+
# In[ ]:
|
91 |
+
|
92 |
+
|
93 |
+
|
94 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
pandas
|
3 |
+
seaborn
|
4 |
+
matplotlib
|