Skip to content

Instantly share code, notes, and snippets.

@piEsposito
Created April 14, 2020 21:41
Show Gist options
  • Save piEsposito/e81cbee84f51085c69e23ae4cbaf8b78 to your computer and use it in GitHub Desktop.
Save piEsposito/e81cbee84f51085c69e23ae4cbaf8b78 to your computer and use it in GitHub Desktop.
def get_confidence_intervals(preds_test, ci_multiplier):
global scaler
preds_test = torch.tensor(preds_test)
pred_mean = preds_test.mean(1)
pred_std = preds_test.std(1).detach().cpu().numpy()
pred_std = torch.tensor((pred_std))
upper_bound = pred_mean + (pred_std * ci_multiplier)
lower_bound = pred_mean - (pred_std * ci_multiplier)
#gather unscaled confidence intervals
pred_mean_final = pred_mean.unsqueeze(1).detach().cpu().numpy()
pred_mean_unscaled = scaler.inverse_transform(pred_mean_final)
upper_bound_unscaled = upper_bound.unsqueeze(1).detach().cpu().numpy()
upper_bound_unscaled = scaler.inverse_transform(upper_bound_unscaled)
lower_bound_unscaled = lower_bound.unsqueeze(1).detach().cpu().numpy()
lower_bound_unscaled = scaler.inverse_transform(lower_bound_unscaled)
return pred_mean_unscaled, upper_bound_unscaled, lower_bound_unscaled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment