# ElasticNet y_predicted_en = algorithm.elastic_net2(x_train, y_train, x_train) rmse = compare(y_train, y_predicted_en) print('RMSE Elastic %.3f' % (rmse)) print('------- Test --------') # No Prediction y_hat_predicted = y_test rmse = compare(y_test, y_hat_predicted) print('RMSE NoPredic %.3f' % (rmse)) # Dummy y_predicted_dummy = x_test[:, 0] rmse = compare(y_test, y_predicted_dummy) print('RMSE Dummy %.3f' % (rmse)) # ElasticNet y_predicted_en, y_future_en = algorithm.elastic_net( x_train, y_train, x_test, y_test) rmse = compare(y_test, y_predicted_en) print('RMSE Elastic %.3f' % (rmse)) rmse = compare(y_test, y_future_en) print('RMSE Elastic Future %.3f' % (rmse)) print(' ') titles = ['Y test', 'ElasticNet', 'ElasticNet Future'] data = [y_test, y_predicted_en, y_future_en] date_test = date[split:] misc.plot_lines_graph('Raw Data, Test Data, Window size ' + str(x), date_test, titles, data)
# https://machinelearningmastery.com/time-series-data-stationary-python/ from matplotlib import pyplot from pandas import read_csv from Util import data_misc from Util import misc from Util import data_misc import pandas as pd series = read_csv('../Thesis/Bitcoin_historical_data_processed_1f.csv', header=0, sep='\t') # transform data to be stationary raw_values = series['Avg'].values date = series['Date'].values diff = data_misc.difference(raw_values, 1) rolmean = pd.rolling_mean(raw_values, window=15) rolstd = pd.rolling_std(raw_values, window=15) titles = ['Raw Data', 'Rolling Mean', 'Standard Mean'] data = [raw_values, rolmean, rolstd] misc.plot_lines_graph('Data ', date, titles, data) misc.plot_data_graph2('Stationary ', date, diff)
y_predicted_la_es = algorithm.lasso(x_train, y_train, x_test, normalize=False) rmse, y_predicted_la = compare_test(y_test, y_predicted_la_es) print('RMSE Lasso %.3f' % (rmse)) # titles = ['Y', 'ElasticNet', 'ElasticNet Future', 'KNN5', 'KNN10'] # y_future_en = y_future_en[1] # data = [y_hat_predicted, y_predicted_en, y_future_en, y_predicted_knn5, y_predicted_knn10] titles = ['Y', 'ElasticNet', 'KNN5', 'KNN10', 'SGD', 'Lasso'] data = [y_hat_predicted, y_predicted_en, y_predicted_knn5, y_predicted_knn10, [], y_predicted_la] date_test = date[split + 1:] print('Length date test:' + str(len(date_test))) print('Length data test:' + str(len(y_test))) misc.plot_lines_graph('Stationary, Test Data ', date_test, titles, data) data = [y_test, y_predicted_en_es, y_future_en_es, y_predicted_knn5_es, y_predicted_knn10_es] misc.plot_lines_graph('Stationary, Test Data ', date_test, titles, data) """ y = list() y_1 = list() y_2 = list() y_3 = list() y_4 = list() for i in range(len(y_train)): y.append(float(y_train[i])) y_1.append(float(y_train[i])) y_2.append(float(y_train[i]))
print('RMSE SGD %.3f' % (rmse)) # print('Y_test') # print(y_test) titles = [' ', 'Y', 'ElasticNet', 'KNN5', 'KNN10'] data = [[], y_test, y_predicted_en, y_predicted_knn5, y_predicted_knn10] #titles = [' ', 'Y', 'ElasticNet', 'ElasticNet Future', 'KNN5', 'KNN10'] #data = [[], y_test, y_predicted_en, y_future_en, y_predicted_knn5, y_predicted_knn10] date_test = date[split:] print('Length date test:' + str(len(date_test))) print('Length data test:' + str(len(y_test))) misc.plot_lines_graph('Raw Data, Test Data ', date_test, titles, data) y = list() y_1 = list() y_2 = list() for i in range(len(y_train)): y.append(float(y_train[i])) y_1.append(float(y_train[i])) y_2.append(float(y_train[i])) for i in range(len(y_test)): y.append(float(y_test[i])) y_1.append(float(y_predicted_en[i])) y_2.append(float(y_future_en[i])) titles = ['Y', 'ElasticNet', 'ElasticNet Future']
# KNN5 y_hat_predicted = algorithm.knn_regressor(x_train, y_train, x_test, 5) rmse, y_predicted_knn5 = compare_test(test_scaled, y_hat_predicted) print('RMSE KNN(5) %.3f' % (rmse)) # KNN10 y_hat_predicted = algorithm.knn_regressor(x_train, y_train, x_test, 10) rmse, y_predicted_knn10 = compare_test(test_scaled, y_hat_predicted) print('RMSE KNN(10) %.3f' % (rmse)) # SGD y_hat_predicted = algorithm.sgd_regressor(x_train, y_train, x_test) rmse, y_predicted_sgd = compare_test(test_scaled, y_hat_predicted) print('RMSE SGD %.3f' % (rmse)) # Lasso y_hat_predicted = algorithm.lasso(x_train, y_train, x_test, normalize=False) rmse, y_predicted_la = compare_test(test_scaled, y_hat_predicted) print('RMSE Lasso %.3f' % (rmse)) # LSTM y_hat_predicted = algorithm.lstm(x_train, y_train, x_test, batch_size=1, nb_epoch=200, neurons=3) rmse, y_predicted_lstm = compare_test(test_scaled, y_hat_predicted) print('RMSE LSTM %.3f' % (rmse)) titles = ['X', 'Y', 'ElasticNet', 'KNN5', 'KNN10', 'SGD', 'Lasso','LSTM'] data = [raw_values[split:-1], y_predicted_real, y_predicted_en, y_predicted_knn5, y_predicted_knn10, y_predicted_sgd, y_predicted_la,y_predicted_lstm] misc.plot_lines_graph('Stationary - Normalization, Test Data ', date[split:], titles, data)
rmse, y_predicted_knn5 = compare_test(test_scaled, y_hat_predicted) print('RMSE KNN(5) %.3f' % (rmse)) # KNN10 y_hat_predicted = algorithm.knn_regressor(x_train, y_train, x_test, 10) rmse, y_predicted_knn10 = compare_test(test_scaled, y_hat_predicted) print('RMSE KNN(10) %.3f' % (rmse)) # SGD y_hat_predicted = algorithm.sgd_regressor(x_train, y_train, x_test) rmse, y_predicted_sgd = compare_test(test_scaled, y_hat_predicted) print('RMSE SGD %.3f' % (rmse)) # LSTM y_hat_predicted = algorithm.lstm(x_train, y_train, x_test, batch_size=1, nb_epoch=3, neurons=1) rmse, y_predicted_lstm = compare_test(test_scaled, y_hat_predicted) print('RMSE LSTM %.3f' % (rmse)) titles = ['X', 'Y', 'ElasticNet', 'KNN5', 'KNN10', 'SGD', 'LSTM'] data = [ test[:, 0], test[:, 1], y_predicted_en, y_predicted_knn5, y_predicted_knn10, y_predicted_sgd, y_predicted_lstm ] misc.plot_lines_graph('Normalization, Test Data ', date[split + 1:], titles, data)
rmse, y_predicted_knn5 = compare_test(test_scaled, y_hat_predicted) print('RMSE KNN(5) %.3f' % (rmse)) # KNN10 y_hat_predicted = algorithm.knn_regressor(x_train, y_train, x_test, 10) rmse, y_predicted_knn10 = compare_test(test_scaled, y_hat_predicted) print('RMSE KNN(10) %.3f' % (rmse)) # SGD y_hat_predicted = algorithm.sgd_regressor(x_train, y_train, x_test) rmse, y_predicted_sgd = compare_test(test_scaled, y_hat_predicted) print('RMSE SGD %.3f' % (rmse)) # LSTM y_hat_predicted = algorithm.lstm(x_train, y_train, x_test, batch_size=1, nb_epoch=3, neurons=1) rmse, y_predicted_lstm = compare_test(test_scaled, y_hat_predicted) print('RMSE LSTM %.3f' % (rmse)) titles = ['X', 'Y', 'y_predicted_Real', 'KNN5', 'KNN10', 'SGD', 'LSTM'] #data = [x_test, y_test,y_predicted_real, y_predicted_knn5, y_predicted_knn10, y_predicted_sgd, y_predicted_lstm] #data = [y_predicted_real, y_predicted_en, y_predicted_knn5, y_predicted_knn10, y_predicted_sgd, y_predicted_lstm] #data = [raw_values[1+split:], y_predicted_en, y_predicted_knn5, y_predicted_knn10, y_predicted_sgd,y_predicted_lstm] misc.plot_lines_graph('Models, Test Data ', date[1 + split:], titles, data)
print('RMSE Elastic %.3f' % (rmse)) # KNN5 y_hat_predicted = algorithm.knn_regressor(x_train, y_train, x_test, 5) rmse, y_predicted_knn5 = compare_test(test, y_hat_predicted) print('RMSE KNN(5) %.3f' % (rmse)) # KNN10 y_hat_predicted = algorithm.knn_regressor(x_train, y_train, x_test, 10) rmse, y_predicted_knn10 = compare_test(test, y_hat_predicted) print('RMSE KNN(10) %.3f' % (rmse)) # SGD y_hat_predicted = algorithm.sgd_regressor(x_train, y_train, x_test) rmse, y_predicted_sgd = compare_test(test, y_hat_predicted) print('RMSE SGD %.3f' % (rmse)) # LSTM y_hat_predicted = algorithm.lstm(x_train, y_train, x_test, batch_size=1, nb_epoch=3, neurons=1) rmse, y_predicted_lstm = compare_test(test, y_hat_predicted) print('RMSE LSTM %.3f' % (rmse)) titles = ['X', 'Y', 'ElasticNet', 'KNN5', 'KNN10'] data = [x_test, y_test, y_predicted_en, y_predicted_knn5, y_predicted_knn10] misc.plot_lines_graph('Raw Data, Test Data ', date[split:], titles, data) misc.plot_data_graph2('Realvalue', date, raw_values)
#rmse, y_predicted_lstm = compare_test(y_test, y_predicted_lstm) #print('RMSE LSTM %.3f' % (rmse)) # print('Y_test') # print(y_test) for i in range(0,len(y_hat_predicted)): titles = ['Y', 'ElasticNet', 'Lasso'] data = [y_hat_predicted[i], y_predicted_en[i], y_predicted_la[i]] # titles = ['', 'Y', 'ElasticNet', 'KNN5', 'KNN10', 'SGD'] # data = [[], y_test, y_predicted_en, y_predicted_knn5, y_predicted_knn10, y_predicted_sgd] date_test = date[split:] print('Length date test:' + str(len(date_test))) print('Length data test:' + str(len(y_test))) misc.plot_lines_graph('Normalization, Test Data ', date_test, titles, data) """ y = list() y_1 = list() y_2 = list() for i in range(len(y_train)): y.append(float(y_train[i])) y_1.append(float(y_train[i])) # y_2.append(float(y_train[i])) for i in range(len(y_test)): y.append(float(y_test[i])) y_1.append(float(y_predicted_en[i])) # y_2.append(float(y_future_en[i]))