| @@ -15,23 +15,6 @@ def sinus_cosinus(x): | |||
| def swish(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 = [snake] | |||
| @@ -49,9 +32,24 @@ def prepare_data(filename="WILL5000INDFC2.csv"): | |||
| y_test = df_test["WILL5000INDFC"] | |||
| y_test.to_numpy() | |||
| 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): | |||
| @@ -68,7 +66,8 @@ def create_model(activation): | |||
| model.summary() | |||
| 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 = [] | |||
| errors_train,errors_test = [],[] | |||
| mean_y_train,mean_y_test,std_y_test=[],[],[] | |||
| @@ -100,14 +99,19 @@ def training_testing(n,activations): | |||
| 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_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) | |||
| 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.plot(x_cut,y_true,label="True data") | |||
| plt.plot(x,future_preds,label="Predictions") | |||
| @@ -119,3 +123,4 @@ def final_plot(): | |||
| plt.show() | |||