How to create a prediction interval with the fact that the residuals follow a specific distribution (in python) Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsSKNN regression problemUncertainty calculation through integration and correct analysis methodologyEstimate the normal distribution of the mean of a normal distribution given a set of samples?A statistic for testing if $mu$ which is known to be in subspace $H$, is also in subspace $H_0subseteq H$Correcting log-bias in the output of an XGBBest model for Machine LearningWasserstein distance between Gaussian and the empirical distributionHow to estimate the variance of regressors in scikit-learn?Custom conditional Keras metricMaking a model to predict the error of another model

Why weren't discrete x86 CPUs ever used in game hardware?

Is multiple magic items in one inherently imbalanced?

Tips to organize LaTeX presentations for a semester

Understanding p-Values using an example

How does the math work when buying airline miles?

In musical terms, what properties are varied by the human voice to produce different words / syllables?

New Order #6: Easter Egg

What does Turing mean by this statement?

License to disallow distribution in closed source software, but allow exceptions made by owner?

Is CEO the "profession" with the most psychopaths?

What does 丫 mean? 丫是什么意思?

What to do with repeated rejections for phd position

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

One-one communication

NERDTreeMenu Remapping

Why not send Voyager 3 and 4 following up the paths taken by Voyager 1 and 2 to re-transmit signals of later as they fly away from Earth?

Why is it faster to reheat something than it is to cook it?

Resize vertical bars (absolute-value symbols)

What is the difference between CTSS and ITS?

Universal covering space of the real projective line?

Simple Http Server

Positioning dot before text in math mode

Are the endpoints of the domain of a function counted as critical points?

Why datecode is SO IMPORTANT to chip manufacturers?



How to create a prediction interval with the fact that the residuals follow a specific distribution (in python)



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsSKNN regression problemUncertainty calculation through integration and correct analysis methodologyEstimate the normal distribution of the mean of a normal distribution given a set of samples?A statistic for testing if $mu$ which is known to be in subspace $H$, is also in subspace $H_0subseteq H$Correcting log-bias in the output of an XGBBest model for Machine LearningWasserstein distance between Gaussian and the empirical distributionHow to estimate the variance of regressors in scikit-learn?Custom conditional Keras metricMaking a model to predict the error of another model










2












$begingroup$


I am looking at a software development pipeline where I am predicting the lead time of different products flowing through the pipeline.



After applying a boxcox transformation on the lead time (target variable) and creating a XGBoost regressor model I can see that the residuals follow a t-locationScale distribution.
enter image description here



So now I looked at this guide which describes a method to create a prediction interval for any regression model assuming that the residuals are normally distributed. https://qucit.com/a-simple-technique-to-estimate-prediction-intervals-for-any-regression-model_en/



But I tried to tweak it to my distribution.



So a t-locationScale distribution has a $sigma$, $mu$ and $nu$ parameter. The variance is only defined for $nu>2$. My specific distribution has $nu = 2.56$ and $mu = 0.04$, $sigma = 0.97$ So I could take the 95% interval of this distribution and say that for any $haty$, the prediction interval is the 95% interval of the residual distribution.



But I want to take into consideration that the prediction interval should change with different inputs. I created a regressor model, which I trained and then made predictions using the validation set. I then took the square of the error and trained an additional error model on this data. Such that the error model could predict the variance of the residuals distribution.



 xgb = XGBoostRegressor()
xgb.fit(X_train,y_train)
y_hat = xgb.predict(X_val)
val_error = (y_hat-y_val)**2

xgb_error = XGBoostRegressor()
xgb_error.fit(X_val, val_error)

variance_hat_residuals = xgb_error.predict(X_test)


The relationship between variance and $sigma$ and $nu$ for a t-locationScale distribution is



var = $sigma^2 *fracnunu-2$



Now here is where I make an assumption which I am not sure makes sense.



I assume that the degrees of freedom $nu$ is the same as for all residuals, $nu = 2.56$ and then I solve for $sigma$ through the following.



$hatsigma = sqrtfrachatvar*(nu-2)nu$



And estimate the lower and upper quantiles from this distribution.



 residual_distribution_lower_quantile = scipy.stats.t.ppf(q = 0.025, df = 2.56, scale = sigma)
residual_distribution_upper_quantile = scipy.stats.t.ppf(q = 0.0975, df = 2.56, scale = sigma)


I then predict the lead time $haty$ and say that the mean of the distribution is $haty$



 pred = xgb.prediction(X_test)
lower_interval = pred + residual_distribution_lower_quantile
upper_interval = pred + residual_distribution_upper_quantile


Does it make sense to make the claim of $nu$ is static? My score for the prediction interval is now $81%$ since I am clearly simplifying the problem.



Any suggestions for improving my method?










share|improve this question











$endgroup$
















    2












    $begingroup$


    I am looking at a software development pipeline where I am predicting the lead time of different products flowing through the pipeline.



    After applying a boxcox transformation on the lead time (target variable) and creating a XGBoost regressor model I can see that the residuals follow a t-locationScale distribution.
    enter image description here



    So now I looked at this guide which describes a method to create a prediction interval for any regression model assuming that the residuals are normally distributed. https://qucit.com/a-simple-technique-to-estimate-prediction-intervals-for-any-regression-model_en/



    But I tried to tweak it to my distribution.



    So a t-locationScale distribution has a $sigma$, $mu$ and $nu$ parameter. The variance is only defined for $nu>2$. My specific distribution has $nu = 2.56$ and $mu = 0.04$, $sigma = 0.97$ So I could take the 95% interval of this distribution and say that for any $haty$, the prediction interval is the 95% interval of the residual distribution.



    But I want to take into consideration that the prediction interval should change with different inputs. I created a regressor model, which I trained and then made predictions using the validation set. I then took the square of the error and trained an additional error model on this data. Such that the error model could predict the variance of the residuals distribution.



     xgb = XGBoostRegressor()
    xgb.fit(X_train,y_train)
    y_hat = xgb.predict(X_val)
    val_error = (y_hat-y_val)**2

    xgb_error = XGBoostRegressor()
    xgb_error.fit(X_val, val_error)

    variance_hat_residuals = xgb_error.predict(X_test)


    The relationship between variance and $sigma$ and $nu$ for a t-locationScale distribution is



    var = $sigma^2 *fracnunu-2$



    Now here is where I make an assumption which I am not sure makes sense.



    I assume that the degrees of freedom $nu$ is the same as for all residuals, $nu = 2.56$ and then I solve for $sigma$ through the following.



    $hatsigma = sqrtfrachatvar*(nu-2)nu$



    And estimate the lower and upper quantiles from this distribution.



     residual_distribution_lower_quantile = scipy.stats.t.ppf(q = 0.025, df = 2.56, scale = sigma)
    residual_distribution_upper_quantile = scipy.stats.t.ppf(q = 0.0975, df = 2.56, scale = sigma)


    I then predict the lead time $haty$ and say that the mean of the distribution is $haty$



     pred = xgb.prediction(X_test)
    lower_interval = pred + residual_distribution_lower_quantile
    upper_interval = pred + residual_distribution_upper_quantile


    Does it make sense to make the claim of $nu$ is static? My score for the prediction interval is now $81%$ since I am clearly simplifying the problem.



    Any suggestions for improving my method?










    share|improve this question











    $endgroup$














      2












      2








      2





      $begingroup$


      I am looking at a software development pipeline where I am predicting the lead time of different products flowing through the pipeline.



      After applying a boxcox transformation on the lead time (target variable) and creating a XGBoost regressor model I can see that the residuals follow a t-locationScale distribution.
      enter image description here



      So now I looked at this guide which describes a method to create a prediction interval for any regression model assuming that the residuals are normally distributed. https://qucit.com/a-simple-technique-to-estimate-prediction-intervals-for-any-regression-model_en/



      But I tried to tweak it to my distribution.



      So a t-locationScale distribution has a $sigma$, $mu$ and $nu$ parameter. The variance is only defined for $nu>2$. My specific distribution has $nu = 2.56$ and $mu = 0.04$, $sigma = 0.97$ So I could take the 95% interval of this distribution and say that for any $haty$, the prediction interval is the 95% interval of the residual distribution.



      But I want to take into consideration that the prediction interval should change with different inputs. I created a regressor model, which I trained and then made predictions using the validation set. I then took the square of the error and trained an additional error model on this data. Such that the error model could predict the variance of the residuals distribution.



       xgb = XGBoostRegressor()
      xgb.fit(X_train,y_train)
      y_hat = xgb.predict(X_val)
      val_error = (y_hat-y_val)**2

      xgb_error = XGBoostRegressor()
      xgb_error.fit(X_val, val_error)

      variance_hat_residuals = xgb_error.predict(X_test)


      The relationship between variance and $sigma$ and $nu$ for a t-locationScale distribution is



      var = $sigma^2 *fracnunu-2$



      Now here is where I make an assumption which I am not sure makes sense.



      I assume that the degrees of freedom $nu$ is the same as for all residuals, $nu = 2.56$ and then I solve for $sigma$ through the following.



      $hatsigma = sqrtfrachatvar*(nu-2)nu$



      And estimate the lower and upper quantiles from this distribution.



       residual_distribution_lower_quantile = scipy.stats.t.ppf(q = 0.025, df = 2.56, scale = sigma)
      residual_distribution_upper_quantile = scipy.stats.t.ppf(q = 0.0975, df = 2.56, scale = sigma)


      I then predict the lead time $haty$ and say that the mean of the distribution is $haty$



       pred = xgb.prediction(X_test)
      lower_interval = pred + residual_distribution_lower_quantile
      upper_interval = pred + residual_distribution_upper_quantile


      Does it make sense to make the claim of $nu$ is static? My score for the prediction interval is now $81%$ since I am clearly simplifying the problem.



      Any suggestions for improving my method?










      share|improve this question











      $endgroup$




      I am looking at a software development pipeline where I am predicting the lead time of different products flowing through the pipeline.



      After applying a boxcox transformation on the lead time (target variable) and creating a XGBoost regressor model I can see that the residuals follow a t-locationScale distribution.
      enter image description here



      So now I looked at this guide which describes a method to create a prediction interval for any regression model assuming that the residuals are normally distributed. https://qucit.com/a-simple-technique-to-estimate-prediction-intervals-for-any-regression-model_en/



      But I tried to tweak it to my distribution.



      So a t-locationScale distribution has a $sigma$, $mu$ and $nu$ parameter. The variance is only defined for $nu>2$. My specific distribution has $nu = 2.56$ and $mu = 0.04$, $sigma = 0.97$ So I could take the 95% interval of this distribution and say that for any $haty$, the prediction interval is the 95% interval of the residual distribution.



      But I want to take into consideration that the prediction interval should change with different inputs. I created a regressor model, which I trained and then made predictions using the validation set. I then took the square of the error and trained an additional error model on this data. Such that the error model could predict the variance of the residuals distribution.



       xgb = XGBoostRegressor()
      xgb.fit(X_train,y_train)
      y_hat = xgb.predict(X_val)
      val_error = (y_hat-y_val)**2

      xgb_error = XGBoostRegressor()
      xgb_error.fit(X_val, val_error)

      variance_hat_residuals = xgb_error.predict(X_test)


      The relationship between variance and $sigma$ and $nu$ for a t-locationScale distribution is



      var = $sigma^2 *fracnunu-2$



      Now here is where I make an assumption which I am not sure makes sense.



      I assume that the degrees of freedom $nu$ is the same as for all residuals, $nu = 2.56$ and then I solve for $sigma$ through the following.



      $hatsigma = sqrtfrachatvar*(nu-2)nu$



      And estimate the lower and upper quantiles from this distribution.



       residual_distribution_lower_quantile = scipy.stats.t.ppf(q = 0.025, df = 2.56, scale = sigma)
      residual_distribution_upper_quantile = scipy.stats.t.ppf(q = 0.0975, df = 2.56, scale = sigma)


      I then predict the lead time $haty$ and say that the mean of the distribution is $haty$



       pred = xgb.prediction(X_test)
      lower_interval = pred + residual_distribution_lower_quantile
      upper_interval = pred + residual_distribution_upper_quantile


      Does it make sense to make the claim of $nu$ is static? My score for the prediction interval is now $81%$ since I am clearly simplifying the problem.



      Any suggestions for improving my method?







      machine-learning python statistics distribution






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 3 at 12:19







      kspr

















      asked Apr 3 at 12:08









      ksprkspr

      112




      112




















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48514%2fhow-to-create-a-prediction-interval-with-the-fact-that-the-residuals-follow-a-sp%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48514%2fhow-to-create-a-prediction-interval-with-the-fact-that-the-residuals-follow-a-sp%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Marja Vauras Lähteet | Aiheesta muualla | NavigointivalikkoMarja Vauras Turun yliopiston tutkimusportaalissaInfobox OKSuomalaisen Tiedeakatemian varsinaiset jäsenetKasvatustieteiden tiedekunnan dekaanit ja muu johtoMarja VaurasKoulutusvienti on kestävyys- ja ketteryyslaji (2.5.2017)laajentamallaWorldCat Identities0000 0001 0855 9405n86069603utb201588738523620927

          Which is better: GPT or RelGAN for text generation?2019 Community Moderator ElectionWhat is the difference between TextGAN and LM for text generation?GANs (generative adversarial networks) possible for text as well?Generator loss not decreasing- text to image synthesisChoosing a right algorithm for template-based text generationHow should I format input and output for text generation with LSTMsGumbel Softmax vs Vanilla Softmax for GAN trainingWhich neural network to choose for classification from text/speech?NLP text autoencoder that generates text in poetic meterWhat is the interpretation of the expectation notation in the GAN formulation?What is the difference between TextGAN and LM for text generation?How to prepare the data for text generation task

          Is this part of the description of the Archfey warlock's Misty Escape feature redundant?When is entropic ward considered “used”?How does the reaction timing work for Wrath of the Storm? Can it potentially prevent the damage from the triggering attack?Does the Dark Arts Archlich warlock patrons's Arcane Invisibility activate every time you cast a level 1+ spell?When attacking while invisible, when exactly does invisibility break?Can I cast Hellish Rebuke on my turn?Do I have to “pre-cast” a reaction spell in order for it to be triggered?What happens if a Player Misty Escapes into an Invisible CreatureCan a reaction interrupt multiattack?Does the Fiend-patron warlock's Hurl Through Hell feature dispel effects that require the target to be on the same plane as the caster?What are you allowed to do while using the Warlock's Eldritch Master feature?