Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Confidence intervals over time with polynomial regression
#1
I am having trouble replicating 95% confidence bands for a time-series polynomial regression model.

I have found the code below, however the resulting confidence bands do not become greater the further out the prediction is into the future - which is what I require. Am I missing something? I appreciate that an ARIMA model would be preferable for time-series forecasts, however I am stuck with replicating a polynomial regression for this task.

Thanks in advance,


    ## instantiate regression model.
    model = LinearRegression()
    ## train model on polynomial x data and y data.
    model.fit(x, y)

    y_poly_pred = model.predict(x)

    ## reshape predictions
    predictions = predictions.values.reshape((n_value,1))

    ## RMSE & R2
    rmse = np.sqrt(mean_squared_error(y, y_poly_pred_test))
    r2 = r2_score(y, y_poly_pred)
    ## calculate t_value
    t = stats.t.ppf(1-tail_value,n_value)
    ## predict y values of original data using the fit model.
    p_y = y_poly_pred_test

    # calculate the y-error (residuals)
    y_err = y - y_poly_pred

    # calculate confidence intervals for new test x-series
    mean_x = np.mean(x)
    n = len(x)
    s_err = np.sum(np.power(y_err,2))   # sum of the squares of the residuals
    confs = t * np.sqrt((s_err/(n-2))*(1.0/n + (np.power((predictions-mean_x),2)/
            ((np.sum(np.power(x,2)))-n*(np.power(mean_x,2))))))

    # get lower and upper confidence limits based on predicted y and confidence intervals
    lower = y_poly_pred - abs(confs)
    upper = y_poly_pred + abs(confs)

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Linear Regression on Time Series karlito 5 299 Jan-28-2020, 10:02 AM
Last Post: buran
  Can I evaluate a Chebyshev polynomial using a function player1681 1 297 Nov-22-2019, 06:33 AM
Last Post: scidam
  Machine Learning Polynomial Regression braveYug 0 229 Nov-13-2019, 11:41 AM
Last Post: braveYug
  datetime intervals - dataframe selection (via plotted data) karlito 0 203 Nov-12-2019, 08:16 AM
Last Post: karlito
  To draw a polynomial solution pianistseb 2 760 Nov-13-2018, 01:45 PM
Last Post: pianistseb
  Draw Weibull distribution probability function based on Confidence interval farzadtb 1 1,246 Jul-31-2018, 03:21 PM
Last Post: Vysero
  linspace not dividing equal intervals sheel 0 900 Jan-16-2018, 04:28 PM
Last Post: sheel
  pandas Dataframe as "confidence table" for matchmaking? takaa 1 1,258 Nov-28-2017, 07:48 PM
Last Post: takaa

Forum Jump:


Users browsing this thread: 1 Guest(s)