Przeglądaj źródła

maj de la météo pour meilleur précision avec optuna et prédiction plus loingtaine

Emile
Emile Siboulet 4 lat temu
rodzic
commit
073d1a72f1
66 zmienionych plików z 107 dodań i 71 usunięć
  1. BIN
      code/RNN_prediction_meteo/164_126_fig2.png
  2. BIN
      code/RNN_prediction_meteo/164_126_fig3.png
  3. BIN
      code/RNN_prediction_meteo/164_126_fig4.png
  4. 2
    0
      code/RNN_prediction_meteo/Model.py
  5. BIN
      code/RNN_prediction_meteo/images/126_421_fig2.png
  6. BIN
      code/RNN_prediction_meteo/images/126_421_fig3.png
  7. BIN
      code/RNN_prediction_meteo/images/126_421_fig4.png
  8. BIN
      code/RNN_prediction_meteo/images/12_357_fig2.png
  9. BIN
      code/RNN_prediction_meteo/images/12_357_fig3.png
  10. BIN
      code/RNN_prediction_meteo/images/12_357_fig4.png
  11. BIN
      code/RNN_prediction_meteo/images/164_126_fig2.png
  12. BIN
      code/RNN_prediction_meteo/images/164_126_fig3.png
  13. BIN
      code/RNN_prediction_meteo/images/164_126_fig4.png
  14. BIN
      code/RNN_prediction_meteo/images/17_397_fig2.png
  15. BIN
      code/RNN_prediction_meteo/images/17_397_fig3.png
  16. BIN
      code/RNN_prediction_meteo/images/17_397_fig4.png
  17. BIN
      code/RNN_prediction_meteo/images/181_116_fig2.png
  18. BIN
      code/RNN_prediction_meteo/images/181_116_fig3.png
  19. BIN
      code/RNN_prediction_meteo/images/181_116_fig4.png
  20. BIN
      code/RNN_prediction_meteo/images/202_170_fig2.png
  21. BIN
      code/RNN_prediction_meteo/images/202_170_fig3.png
  22. BIN
      code/RNN_prediction_meteo/images/202_170_fig4.png
  23. BIN
      code/RNN_prediction_meteo/images/203_131_fig2.png
  24. BIN
      code/RNN_prediction_meteo/images/203_131_fig3.png
  25. BIN
      code/RNN_prediction_meteo/images/203_131_fig4.png
  26. BIN
      code/RNN_prediction_meteo/images/210_226_fig2.png
  27. BIN
      code/RNN_prediction_meteo/images/210_226_fig3.png
  28. BIN
      code/RNN_prediction_meteo/images/210_226_fig4.png
  29. BIN
      code/RNN_prediction_meteo/images/251_140_fig2.png
  30. BIN
      code/RNN_prediction_meteo/images/251_140_fig3.png
  31. BIN
      code/RNN_prediction_meteo/images/251_140_fig4.png
  32. BIN
      code/RNN_prediction_meteo/images/253_153_fig2.png
  33. BIN
      code/RNN_prediction_meteo/images/253_153_fig3.png
  34. BIN
      code/RNN_prediction_meteo/images/253_153_fig4.png
  35. BIN
      code/RNN_prediction_meteo/images/256_188_fig2.png
  36. BIN
      code/RNN_prediction_meteo/images/256_188_fig3.png
  37. BIN
      code/RNN_prediction_meteo/images/256_188_fig4.png
  38. BIN
      code/RNN_prediction_meteo/images/25_428_fig2.png
  39. BIN
      code/RNN_prediction_meteo/images/25_428_fig3.png
  40. BIN
      code/RNN_prediction_meteo/images/25_428_fig4.png
  41. BIN
      code/RNN_prediction_meteo/images/64_419_fig2.png
  42. BIN
      code/RNN_prediction_meteo/images/64_419_fig3.png
  43. BIN
      code/RNN_prediction_meteo/images/64_419_fig4.png
  44. BIN
      code/RNN_prediction_meteo/images/71_195_fig2.png
  45. BIN
      code/RNN_prediction_meteo/images/71_195_fig3.png
  46. BIN
      code/RNN_prediction_meteo/images/71_195_fig4.png
  47. BIN
      code/RNN_prediction_meteo/images/76_224_fig2.png
  48. BIN
      code/RNN_prediction_meteo/images/76_224_fig3.png
  49. BIN
      code/RNN_prediction_meteo/images/76_224_fig4.png
  50. BIN
      code/RNN_prediction_meteo/images/76_98_fig2.png
  51. BIN
      code/RNN_prediction_meteo/images/76_98_fig3.png
  52. BIN
      code/RNN_prediction_meteo/images/76_98_fig4.png
  53. BIN
      code/RNN_prediction_meteo/images/78_138_fig2.png
  54. BIN
      code/RNN_prediction_meteo/images/78_138_fig3.png
  55. BIN
      code/RNN_prediction_meteo/images/78_138_fig4.png
  56. BIN
      code/RNN_prediction_meteo/images/81_492_fig2.png
  57. BIN
      code/RNN_prediction_meteo/images/81_492_fig3.png
  58. BIN
      code/RNN_prediction_meteo/images/81_492_fig4.png
  59. BIN
      code/RNN_prediction_meteo/images/8_255_fig2.png
  60. BIN
      code/RNN_prediction_meteo/images/8_255_fig3.png
  61. BIN
      code/RNN_prediction_meteo/images/8_255_fig4.png
  62. BIN
      code/RNN_prediction_meteo/images/99_64_fig2.png
  63. BIN
      code/RNN_prediction_meteo/images/99_64_fig3.png
  64. BIN
      code/RNN_prediction_meteo/images/99_64_fig4.png
  65. 12
    0
      code/RNN_prediction_meteo/rep.txt
  66. 93
    71
      code/RNN_prediction_meteo/training.py

BIN
code/RNN_prediction_meteo/164_126_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/164_126_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/164_126_fig4.png Wyświetl plik


+ 2
- 0
code/RNN_prediction_meteo/Model.py Wyświetl plik

@@ -24,3 +24,5 @@ class MyModel(tf.keras.Model):
x = self.dense2(x)
x = self.denselast(x)
return x



BIN
code/RNN_prediction_meteo/images/126_421_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/126_421_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/126_421_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/12_357_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/12_357_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/12_357_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/164_126_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/164_126_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/164_126_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/17_397_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/17_397_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/17_397_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/181_116_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/181_116_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/181_116_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/202_170_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/202_170_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/202_170_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/203_131_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/203_131_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/203_131_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/210_226_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/210_226_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/210_226_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/251_140_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/251_140_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/251_140_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/253_153_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/253_153_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/253_153_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/256_188_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/256_188_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/256_188_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/25_428_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/25_428_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/25_428_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/64_419_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/64_419_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/64_419_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/71_195_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/71_195_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/71_195_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/76_224_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/76_224_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/76_224_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/76_98_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/76_98_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/76_98_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/78_138_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/78_138_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/78_138_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/81_492_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/81_492_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/81_492_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/8_255_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/8_255_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/8_255_fig4.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/99_64_fig2.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/99_64_fig3.png Wyświetl plik


BIN
code/RNN_prediction_meteo/images/99_64_fig4.png Wyświetl plik


+ 12
- 0
code/RNN_prediction_meteo/rep.txt Wyświetl plik

@@ -0,0 +1,12 @@
Epoch 1/5
78/78 [==============================] - 9s 90ms/step - loss: 0.6500 - binary_crossentropy: 0.6500 - mse: 0.0126
Epoch 2/5
78/78 [==============================] - 7s 90ms/step - loss: 0.6390 - binary_crossentropy: 0.6390 - mse: 0.0074
Epoch 3/5
78/78 [==============================] - 7s 91ms/step - loss: 0.6380 - binary_crossentropy: 0.6380 - mse: 0.0069
Epoch 4/5
78/78 [==============================] - 7s 90ms/step - loss: 0.6370 - binary_crossentropy: 0.6370 - mse: 0.0065
Epoch 5/5
78/78 [==============================] - 7s 91ms/step - loss: 0.6357 - binary_crossentropy: 0.6357 - mse: 0.0059

Trial 9 finished with value: 2.1265121155803857 and parameters: {'len_seq': 164, 'hidden': 126}. Best is trial 9 with value: 2.1265121155803857.

+ 93
- 71
code/RNN_prediction_meteo/training.py Wyświetl plik

@@ -2,74 +2,96 @@ import tensorflow as tf
from matplotlib import pyplot as plt
import numpy as np
from Model import MyModel


LEN_SEQ = 64
PRED = 0.05
HIDDEN = 32

model = MyModel(HIDDEN)

dataset = np.load('dataset.npy')
scale = (np.max(dataset) - np.min(dataset))
data = dataset/scale
shift = np.min(data)
data = data - shift

annee = np.array(list(range(len(data))))/365
annee = annee - annee[-1]
start_pred = int(len(data)*(1-PRED))
print(len(data))
print(start_pred)
plt.figure(1)
plt.plot(annee[:start_pred],data[:start_pred], label="apprentissage")
plt.plot(annee[start_pred:],data[start_pred:], label="validation")
plt.legend()
plt.show()

X_train_tot = [data[0:start_pred-1]]
Y_train_tot = [data[1:start_pred]]

X_train_tot = np.expand_dims(np.array(X_train_tot),2)
Y_train_tot = np.expand_dims(np.array(Y_train_tot),2)

X_train = X_train_tot[:,:LEN_SEQ,:]
Y_train = Y_train_tot[:,:LEN_SEQ,:]

for i in range(len(X_train_tot[0]) - LEN_SEQ) :
X_train = np.concatenate((X_train, X_train_tot[:,i:i+LEN_SEQ,:]),0)
Y_train = np.concatenate((Y_train, Y_train_tot[:,i:i+LEN_SEQ,:]),0)
print(X_train_tot.shape)
print(X_train.shape)


model.compile(optimizer='adam',
loss='binary_crossentropy',
metrics=['binary_crossentropy'])
import os
os.system("rm -rf log_dir")

model.fit(x=X_train, y=Y_train, batch_size=16, epochs=5, shuffle=True)

Pred = X_train_tot.copy()
while len(Pred[0]) < len(data) :
print(len(data) - len(Pred[0]))
Pred = np.concatenate((Pred, np.array([[model.predict(Pred)[0][-1]]])),1)
Pred = Pred + shift
Pred = Pred * scale

data_Pred = np.squeeze(Pred)

plt.figure(2)
plt.plot(annee[:start_pred],dataset[:start_pred], label="apprentissage")
plt.plot(annee[start_pred:],dataset[start_pred:], label="validation")
plt.plot(annee, data_Pred, label="prediction")
plt.legend()

fig, axs = plt.subplots(2)
axs[0].plot(annee[:start_pred],dataset[:start_pred], label="apprentissage")
axs[0].plot(annee[start_pred:],dataset[start_pred:], label="validation")
axs[1].plot(annee[:start_pred],dataset[:start_pred], label="données")
axs[1].plot(annee[start_pred:], data_Pred[start_pred:], label="prediction")
plt.legend()
plt.show()
import optuna

def objectif(trial) :
LEN_SEQ = trial.suggest_int('len_seq', 64,256)
PRED = 0.1
HIDDEN = trial.suggest_int('hidden',32,256)

model = MyModel(HIDDEN)

dataset = np.load('dataset.npy')
scale = (np.max(dataset) - np.min(dataset))
data = dataset/scale
shift = np.min(data)
data = data - shift

annee = np.array(list(range(len(data))))/365
annee = annee - annee[-1]
start_pred = int(len(data)*(1-PRED))
#print(len(data))
#print(start_pred)
plt.figure(1)
plt.plot(annee[:start_pred],data[:start_pred], label="apprentissage")
plt.plot(annee[start_pred:],data[start_pred:], label="validation")
plt.legend()
#plt.show()

X_train_tot = [data[0:start_pred-1]]
Y_train_tot = [data[1:start_pred]]

X_train_tot = np.expand_dims(np.array(X_train_tot),2)
Y_train_tot = np.expand_dims(np.array(Y_train_tot),2)

X_train = X_train_tot[:,:LEN_SEQ,:]
Y_train = Y_train_tot[:,:LEN_SEQ,:]

for i in range(len(X_train_tot[0]) - LEN_SEQ) :
X_train = np.concatenate((X_train, X_train_tot[:,i:i+LEN_SEQ,:]),0)
Y_train = np.concatenate((Y_train, Y_train_tot[:,i:i+LEN_SEQ,:]),0)
#print(X_train_tot.shape)
#print(X_train.shape)


model.compile(optimizer='adam',
loss='binary_crossentropy',
metrics=['binary_crossentropy','mse'])
import os
os.system("rm -rf log_dir")

model.fit(x=X_train, y=Y_train, batch_size=16, epochs=5, shuffle=True)

Pred = X_train_tot.copy()
while len(Pred[0]) < len(data)+500 :
print(len(data) - len(Pred[0]))
Pred = np.concatenate((Pred, np.array([[model.predict(Pred)[0][-1]]])),1)
Pred = Pred + shift
Pred = Pred * scale

data_Pred = np.squeeze(Pred)

plt.figure(2)
plt.clf()
plt.plot(annee[:start_pred],dataset[:start_pred], label="apprentissage")
plt.plot(annee[start_pred:],dataset[start_pred:], label="validation")
plt.plot(annee[start_pred:], data_Pred[start_pred:len(annee)], label="prediction")
plt.legend()
plt.savefig(f"images/{LEN_SEQ}_{HIDDEN}_fig2.png")

plt.figure(3)
plt.clf()
fig, axs = plt.subplots(2)
axs[0].plot(annee[:start_pred],dataset[:start_pred], label="apprentissage")
axs[0].plot(annee[start_pred:],dataset[start_pred:], label="validation")
axs[1].plot(annee[:start_pred],dataset[:start_pred], label="données")
axs[1].plot(annee[start_pred:], data_Pred[start_pred:len(annee)], label="prediction")
plt.legend()
plt.savefig(f"images/{LEN_SEQ}_{HIDDEN}_fig3.png")

annee_ex = np.array(list(range(len(data_Pred))))/365
annee_ex = annee_ex + annee[0]
plt.figure(4)
plt.clf()
plt.plot(annee[:start_pred],dataset[:start_pred], label="données")
plt.plot(annee_ex[start_pred:], data_Pred[start_pred:], label="prediction")
plt.legend()
plt.savefig(f"images/{LEN_SEQ}_{HIDDEN}_fig4.png")

loss = np.linalg.norm(dataset[start_pred:] - data_Pred[start_pred:len(dataset)])/(np.max(data_Pred[start_pred:]) - np.min(data_Pred[start_pred:]))
print(loss*100)
return loss
#plt.show()

study = optuna.create_study()
study.optimize(objectif, n_trials=10)

Ładowanie…
Anuluj
Zapisz