| def swish(x): | def swish(x): | ||||
| return(x*tf.math.sigmoid(x)) | return(x*tf.math.sigmoid(x)) | ||||
| def arima_pred(y_train,y_test,orders=[[2,1,1],[2,2,1],[3,1,1],[2,1,2]],n=5): | |||||
| mse=[] | |||||
| for order in orders : | |||||
| mean_err=np.array() | |||||
| for k in range(n): | |||||
| train = y_train | |||||
| preds = [] | |||||
| for test in range(len(y_test)): | |||||
| model = ARIMA(train, order=(order[0],order[1],order[2])) | |||||
| model = model.fit() | |||||
| output = model.forecast() | |||||
| preds.append(output[0]) | |||||
| #train.append(y_test[te | |||||
| mean_err.append((np.square(np.array(preds) - np.array(y_test))).mean()) | |||||
| mse.append(mean_err.mean()) | |||||
| return(mse) | |||||
| #activations = [tf.keras.activations.relu,swish,sinus_cosinus,sinus,snake] | #activations = [tf.keras.activations.relu,swish,sinus_cosinus,sinus,snake] | ||||
| activations = [snake] | activations = [snake] | ||||
| y_test = df_test["WILL5000INDFC"] | y_test = df_test["WILL5000INDFC"] | ||||
| y_test.to_numpy() | y_test.to_numpy() | ||||
| x_test=x_test / maximum | x_test=x_test / maximum | ||||
| return x_train,x_test,y_train,y_test | |||||
| return x_train,x_test,y_train,y_test,maximum,index | |||||
| def arima_pred(y_train,y_test,orders=[[2,1,1],[2,2,1],[3,1,1],[2,1,2]],n=5): | |||||
| mse=[] | |||||
| for order in orders : | |||||
| mean_err=np.array() | |||||
| for k in range(n): | |||||
| train = y_train | |||||
| preds = [] | |||||
| for test in range(len(y_test)): | |||||
| model = ARIMA(train, order=(order[0],order[1],order[2])) | |||||
| model = model.fit() | |||||
| output = model.forecast() | |||||
| preds.append(output[0]) | |||||
| #train.append(y_test[te | |||||
| mean_err.append((np.square(np.array(preds) - np.array(y_test))).mean()) | |||||
| mse.append(mean_err.mean()) | |||||
| return(mse) | |||||
| def create_model(activation): | def create_model(activation): | ||||
| model.summary() | model.summary() | ||||
| return model | return model | ||||
| def training_testing(n,activations): | |||||
| def training_testing(n=5,activations = [tf.keras.activations.relu,swish,sinus_cosinus,sinus,snake]): | |||||
| x_train,x_test,y_train,y_test,maximum,index = prepare_data(filename="WILL5000INDFC2.csv") | |||||
| 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=[],[],[] | ||||
| return models,errors_train,errors_test | return models,errors_train,errors_test | ||||
| def final_plot(): | |||||
| def final_plot(models,errors_test,arima_err): | |||||
| x_train,x_test,y_train,y_test,maximum,index = prepare_data(filename="WILL5000INDFC2.csv") | |||||
| x = np.arange(9000) | x = np.arange(9000) | ||||
| x_n = x / maximum | 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 | |||||
| future_preds = models[-1].predict(x_n) ## Calculated with a website the number of working days between 01-06-2020 and 01-01-2024 | |||||
| #x=np.arange(df_train.shape[0]+df_test.shape[0]+908) | #x=np.arange(df_train.shape[0]+df_test.shape[0]+908) | ||||
| y_true = np.concatenate((y_train,y_test)) | y_true = np.concatenate((y_train,y_test)) | ||||
| x_cut = np.arange(df_train.shape[0]+df_test.shape[0]) | |||||
| x_cut = np.arange(x_train.shape[0]+x_test.shape[0]) | |||||
| print("----- ARIMA -----") | |||||
| print() | |||||
| 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.show() | plt.show() | ||||