Пример #1
0
X_train = X_train.sort_index()
y_train = y_train.sort_index()

regressor = LinearRegression()
regressor.fit(X_train, y_train)  #training the algorithm

y_pred = regressor.predict(X_test)

# print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))
# print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))
# print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
# print("R2:",  metrics.r2_score(y_test, y_pred))

predicted_Y_entire = regressor.predict(X)
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))
print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))
print('Root Mean Squared Error:',
      np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
mape_v = mape(y_pred.reshape(-1, 1), y_test.values.reshape(-1, 1))
print('mape:', mape_v)
r2 = metrics.r2_score(y_test, y_pred)
print("R2:", r2)
store_predict_points(
    Y_entire, predicted_Y_entire,
    'output/test_linear_without_prediction_r2_' + str(r2) + '.csv')

# df = pd.DataFrame({'Actual': y_test, 'Predicted': y_pred})
# df.plot(kind='bar',figsize=(10, 8))
# plt.grid(which='major', linestyle='-', linewidth='0.5', color='green')
# plt.grid(which='minor', linestyle=':', linewidth='0.5', color='black')
# plt.show()
Пример #2
0
           strides=1,
           activation='relu',
           dilation_rate=4))
model.add(Flatten())
model.add(Dropout(rate=0.05))
model.add(Dense(HORIZON, activation='linear'))

model.compile(optimizer='adam', loss='mse')
print(model.summary())
earlystop = EarlyStopping(monitor='val_loss', patience=10)
history = model.fit(X_train,
                    y_train,
                    batch_size=BATCH_SIZE,
                    epochs=EPOCHS,
                    callbacks=[earlystop],
                    verbose=1)

y_pred = model.predict(X_test)

predicted_Y_entire = model.predict(X)
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))
print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))
print('Root Mean Squared Error:',
      np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
mape_v = mape(y_pred.reshape(-1, 1), y_test.values.reshape(-1, 1))
print('mape:', mape_v)
r2 = metrics.r2_score(y_test, y_pred)
print("R2:", r2)
store_predict_points(
    Y_entire, predicted_Y_entire,
    'output/test_cnn_without_prediction_epochs_r2_' + str(r2) + '.csv')
Пример #3
0
Y_entire = entire_inputs['target_load']
predicted_Y_entire, predicted_trends_entire = model.predict(X_entire)

if y_scaler is not None:
    y1_test = y_scaler.inverse_transform(y1_test)
    y1_preds = y_scaler.inverse_transform(y1_preds)
    predicted_Y_entire = y_scaler.inverse_transform(predicted_Y_entire)

y1_test, y1_preds = flatten_test_predict(y1_test, y1_preds)
Y_entire, predicted_Y_entire = flatten_test_predict(Y_entire,
                                                    predicted_Y_entire)

mse = mean_squared_error(y1_test, y1_preds)

rmse_predict = sqrt(mse)
evs = explained_variance_score(y1_test, y1_preds)
mae = mean_absolute_error(y1_test, y1_preds)
mse = mean_squared_error(y1_test, y1_preds)

meae = median_absolute_error(y1_test, y1_preds)
r_square = r2_score(y1_test, y1_preds)

print('rmse_predict:', rmse_predict, "evs:", evs, "mae:", mae, "mse:", mse,
      "meae:", meae, "r2:", r_square)

# output_actual_y = np.concatenate((y_train, y_valid, y1_test), axis=0)
# output_predicted_y = np.concatenate((y_predicted_train, y_predicted_valid, y1_preds), axis=0)

store_predict_points(
    Y_entire, predicted_Y_entire,
    'output/test_lstm_prediction_epochs_' + str(EPOCHS) + '.csv')
Пример #4
0
predicted_counts = predictions_summary_frame['mean']
actual_counts = y_test['confirmed_cases']

y_pred = predicted_counts

nb2_train_predictions = nb2_training_results.get_prediction(X_train)
nb2_train_predictions_summary_frame = nb2_train_predictions.summary_frame()

predicted_Y_train = nb2_train_predictions_summary_frame['mean']

predicted_Y_entire = pd.concat([predicted_Y_train, y_pred], axis=0)

print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))
print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))
print('Root Mean Squared Error:',
      np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
mape_v = mape(y_pred.values.reshape(-1, 1), y_test.values.reshape(-1, 1))
print('mape:', mape_v)
r2 = metrics.r2_score(y_test, y_pred)
print("R2:", r2)

store_predict_points(Y_entire, predicted_Y_entire,
                     'output/test_nb2_prediction_r2_' + str(r2) + '.csv')

# fig = plt.figure()
# fig.suptitle('Predicted versus actual bicyclist counts on the Brooklyn bridge')
# predicted, = plt.plot(X_test.index, predicted_counts, 'go-', label='Predicted counts')
# actual, = plt.plot(X_test.index, actual_counts, 'ro-', label='Actual counts')
# plt.legend(handles=[predicted, actual])
# plt.show()