| def swish(x): | def swish(x): | ||||
| return(x*tf.math.sigmoid(x)) | return(x*tf.math.sigmoid(x)) | ||||
| def arima_pred(x_train,y_test): | |||||
| train = x_train | |||||
| def arima_pred(y_train,y_test,order=[2,1,1]): | |||||
| train = y_train | |||||
| preds = [] | preds = [] | ||||
| for test in range(len(y_test)): | for test in range(len(y_test)): | ||||
| model = ARIMA(train, order=(2,1,1)) | |||||
| model = ARIMA(train, order=(order[0],order[1],order[2])) | |||||
| model = model.fit() | model = model.fit() | ||||
| output = model.forecast() | output = model.forecast() | ||||
| preds.append(output[0]) | preds.append(output[0]) | ||||
| train.append(y_test[test]) | train.append(y_test[test]) | ||||
| return((np.square(preds - test)).mean()) | |||||
| return((np.square(np.array(preds) - np.array(y_test))).mean(),preds) | |||||
| activations = [tf.keras.activations.relu,swish,sinus_cosinus,sinus,snake] | |||||
| #activations = [snake] | |||||
| #activations = [tf.keras.activations.relu,swish,sinus_cosinus,sinus,snake] | |||||
| activations = [snake] | |||||
| models = [] | models = [] | ||||
| errors_train,errors_test = [],[] | errors_train,errors_test = [],[] | ||||
| mean_y_train,mean_y_test,std_y_test=[],[],[] | mean_y_train,mean_y_test,std_y_test=[],[],[] | ||||
| print(y_test) | print(y_test) | ||||
| x_test=x_test / maximum | x_test=x_test / maximum | ||||
| #print(arima_pred(list(x_train),list(y_test))) | |||||
| print(arima_pred(list(y_train),list(y_test))) | |||||
| for activation in activations : | for activation in activations : | ||||
| model.compile(optimizer=opt, loss='mse') | model.compile(optimizer=opt, loss='mse') | ||||
| model.build() | model.build() | ||||
| model.summary() | model.summary() | ||||
| model.fit(x_train,y_train, batch_size=1, epochs=2) | |||||
| model.fit(x_train,y_train, batch_size=1, epochs=1) | |||||
| y_pred_test = model.predict(x_test) | y_pred_test = model.predict(x_test) | ||||
| y_pred_train = model.predict(x_train) | y_pred_train = model.predict(x_train) | ||||
| x = np.arange(9000) | x = np.arange(9000) | ||||
| x = x / maximum | |||||
| future_preds = model.predict(x) ## Calculated with a website the number of working days between 01-06-2020 and 01-01-2024 | |||||
| x_n = x / maximum | |||||
| future_preds = model.predict(x_n) ## Calculated with a website the number of working days between 01-06-2020 and 01-01-2024 | |||||
| def plot_total(x_train,y_train,y_pred_train,x_test,y_test,y_pred_test): | def plot_total(x_train,y_train,y_pred_train,x_test,y_test,y_pred_test): | ||||
| x = np.concatenate((x_train,x_test)) | x = np.concatenate((x_train,x_test)) | ||||
| plt.figure() | plt.figure() | ||||
| plt.plot(x_cut,y_true,label="True data") | plt.plot(x_cut,y_true,label="True data") | ||||
| plt.plot(x,future_preds,label="Predictions") | plt.plot(x,future_preds,label="Predictions") | ||||
| plt.xticks(range(0, 9000, 250), range(1995, 2030, 1)) | |||||
| plt.xticks(range(0, 9000, 250), range(1995, 2031, 1)) | |||||
| plt.xlabel("Années") | plt.xlabel("Années") | ||||
| plt.ylabel("Index Willshire5000 normalisé") | plt.ylabel("Index Willshire5000 normalisé") | ||||
| plt.vlines([index,index+85],ymin=0,ymax=1,colors="r",label="Test Samples") | plt.vlines([index,index+85],ymin=0,ymax=1,colors="r",label="Test Samples") |