Ejemplo n.º 1
0
predictions = list()

y_predicted = neigh.predict(X_test)
print(neigh.score(X_test, y_test))

# raw_values[-365:]

for i in range(len(y_predicted)):
    X, y = test_scaled[i, 0:-1], test_scaled[i, -1]
    yhat = y_predicted[i]
    print("Scaled: Y_test: " + str(y) + " Yhat: " + str(yhat))

    yhat = data_misc.invert_scale(scaler, X, yhat)
    print("yhat no scaled:" + str(yhat))

    yhat = data_misc.inverse_difference(raw_values, yhat,
                                        len(test_scaled) + 0 - i)
    print("yhat no difference:" + str(yhat))
    predictions.append(yhat)

rmse = sqrt(mean_squared_error(raw_values[-365:], predictions))
print('Test RMSE: %.7f' % (rmse))

y = raw_values[-365:]

# plot
misc.plot_line_graph2('KNN(' + str(n_neighbors) + ')', date[-365:],
                      raw_values[-365:], predictions)
misc.plot_data_graph2('Data', date, raw_values)
Ejemplo n.º 2
0
# inverse transform
predicted_bcg_values_test_mae = sc.inverse_transform(
    predicted_bcg_values_test_mae)
y_test = sc.inverse_transform(y_test)

# creating y_test data
y_hat_1 = []
y_hat_2 = []
y_hat_3 = []
for j in range(0, testset_length - timesteps):
    y_hat_1 = numpy.append(y_hat_1, predicted_bcg_values_test_mae[j, 0])
    y_hat_2 = numpy.append(y_hat_2, predicted_bcg_values_test_mae[j, 1])
    y_hat_3 = numpy.append(y_hat_3, predicted_bcg_values_test_mae[j, 2])

# reshaping
y_hat_1 = y_hat_1.flatten()
y_hat_2 = y_hat_2.flatten()
y_hat_3 = y_hat_3.flatten()

y_test_1 = y_test[:, 0]
y_test_2 = y_test[:, 1]
y_test_3 = y_test[:, 2]
y_test_1 = y_test_1.flatten()
y_test_2 = y_test_2.flatten()
y_test_3 = y_test_3.flatten()

misc.plot_line_graph2('LSTM_rmse_1', date[-20:], y_hat_1, y_hat_1)
misc.plot_line_graph2('LSTM_rmse_2', date[-20:], y_hat_2, y_hat_2)
misc.plot_line_graph2('LSTM_rmse_3', date[-20:], y_hat_3, y_hat_3)
Ejemplo n.º 3
0
        y = data_misc.invert_scale(scaler, X, y)

        # invert differencing
        yhat = data_misc.inverse_difference(raw_values, yhat,
                                            len(test_scaled) + 0 - i)
        y = data_misc.inverse_difference(raw_values, y,
                                         len(test_scaled) + 0 - i)

        # print(" Y_test: " + str(y) + " Yhat: " + str(yhat) + " yraw:" + str(raw_values[i + len(train) + 1]))
        # store forecast
        predictions.append(yhat)

    # report performance

    rmse = sqrt(mean_squared_error(raw_values[-365:], predictions))
    print('%d) Test RMSE: %.3f' % (r + 1, rmse))
    # print(predictions)
    error_scores.append(rmse)

    # plot
    misc.plot_line_graph2('LSTM_rmse_' + str(rmse), date[-365:],
                          raw_values[-365:], predictions)

# summarize results
results = DataFrame()
results['rmse'] = error_scores
print(results.describe())
misc.plot_data_graph2('Data', date, raw_values)
# results.boxplot()
# pyplot.show()
Ejemplo n.º 4
0
# print(regr.intercept_)

y_predicted = regr.predict(X_test)

print('y_test: ')
print(y_test)
print('y_predicted: ')
print(y_predicted)

predictions = list()
for i in range(len(test_scaled)):
    X, y = test_scaled[i, 0:-1], test_scaled[i, -1]
    yhat = y_predicted[i]
    # print("Y_test: " + str(y) + " Yhat: " + str(yhat))

    yhat = data_misc.invert_scale(scaler, X, yhat)
    # print("yhat no scaled:" + str(yhat))

    yhat = data_misc.inverse_difference(raw_values, yhat,
                                        len(test_scaled) + 1 - i)
    # print("yhat no difference:" + str(yhat))
    # store forecast
    predictions.append(yhat)

rmse = sqrt(mean_squared_error(raw_values[-365:], predictions))
print('Test RMSE: %.7f' % (rmse))
misc.plot_line_graph2('ElasticNet', date[-365:], raw_values[-365:],
                      predictions)
misc.plot_data_graph2('Data', date, raw_values)
#misc.print_comparison_list('Raw', raw_values[-365:], predictions)
Ejemplo n.º 5
0
        # invert differencing test
        # We get the history and we cut because we pair with the supervised that was cut before. It was full of zeroes
        d = raw_values[split + window_size - 1:]
        y_predicted = data_misc.inverse_difference(d, y_predicted,
                                                   len(test_scaled) + 1 - i)
        y = data_misc.inverse_difference(d, y, len(test_scaled) + 1 - i)

        # print(" Y_test: " + str(y) + " Yhat: " + str(yhat) + " yraw:" + str(raw_values[i + len(train) + 1]))
        # store forecast
        normal_y.append(y)
        predictions.append(y_predicted)

    # report performance
    # the +1 represents the drop that we did when the data was diff
    y_raw = raw_values[split + 1 + window_size:]
    test_rmse = sqrt(mean_squared_error(y_raw, predictions))
    print('%d) Test RMSE: %.3f' % (r + 1, test_rmse))
    # print(predictions)
    error_scores.append(test_rmse)
    # plot
    misc.plot_line_graph2('LSTM_rmse_' + str(test_rmse),
                          date[split + 1 + window_size::], y_raw, predictions)

# summarize results
results = DataFrame()
results['rmse'] = error_scores
print(results.describe())
# misc.plot_data_graph2('Data', date, raw_values)
# results.boxplot()
# pyplot.show()
Ejemplo n.º 6
0
X = X.values
size = int(len(X) * 0.80)
train, test = X[0:size], X[size:len(X)]
history = [x for x in train]
predictions = list()

# p is the number of autoregressive terms,
# d is the number of nonseasonal differences needed for stationarity, and
# q is the number of lagged forecast errors in the prediction equation.

p = 1
d = 1
q = 0
print('P: %.2f, D: %.2f, Q: %.2f' % (p, d, q))

for t in range(len(test)):
    model = ARIMA(history, order=(p, d, q))
    model_fit = model.fit(disp=0)
    output = model_fit.forecast()
    yhat = output[0]
    predictions.append(yhat)
    obs = test[t]
    history.append(obs)
    print('predicted=%f, expected=%f' % (yhat, obs))
error = mean_squared_error(test, predictions)
print('Test MSE: %.3f' % error)
# plot
misc.plot_line_graph2('Arima', date[-365:], X[-365:], predictions)
misc.plot_data_graph2('Data', date, X)
Ejemplo n.º 7
0
clf = linear_model.SGDRegressor(max_iter=2000, verbose=True, shuffle=False)
clf.fit(X_train, y_train)

y_predicted = clf.predict(X_test)

predictions = list()

for i in range(len(y_predicted)):
    X, y = test_scaled[i, 0:-1], test_scaled[i, -1]
    yhat = y_predicted[i]
    print("Scaled: Y_test: " + str(y) + " Yhat: " + str(yhat))

    yhat = data_misc.invert_scale(scaler, X, yhat)
    print("yhat no scaled:" + str(yhat))

    yhat = data_misc.inverse_difference(raw_values, yhat,
                                        len(test_scaled) - 0 - i)
    print("yhat no difference:" + str(yhat))
    predictions.append(yhat)

rmse = sqrt(mean_squared_error(raw_values[-365:], predictions))
print('Test RMSE: %.7f' % (rmse))

y = raw_values[-365:]

misc.print_comparison_list('Raw', raw_values[-365:], predictions)

# plot
misc.plot_line_graph2('SGD', date[-365:], raw_values[-365:], predictions)
misc.plot_data_graph2('Data', date, raw_values)