-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph1.py
More file actions
37 lines (31 loc) · 869 Bytes
/
Graph1.py
File metadata and controls
37 lines (31 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import keras
from keras import layers
from keras import models
from keras import optimizers
import numpy as np
import matplotlib.pyplot as plt
X = np.arange(0, 100, 0.1)
Y = np.sin(2*np.pi*X/50)*np.sin(2*np.pi*X/73)
plt.plot(X, Y)
model = models.Sequential()
model.add(layers.Dense(64, input_shape=([1,]), activation='tanh'))
model.add(layers.Dense(32, activation='tanh'))
model.add(layers.Dense(1))
model.compile(loss='mse',
optimizer='adam',
metrics=['acc'])
history = model.fit(X, Y,
epochs = 1000,
batch_size = 50)
model.save('Graph.h5')
data = model.predict(X)
plt.plot(X, data)
plt.title('result')
plt.show()
acc = history.history['acc']
loss = history.history['loss']
epochs = range(1, len(acc) + 1)
plt.plot(epochs, loss, 'b', label='Loss')
plt.title('loss')
plt.legend()
plt.show()