##### Confidence intervals over time with polynomial regression
 Confidence intervals over time with polynomial regression jjameson Unladen Swallow Posts: 1 Threads: 1 Joined: May 2019 Reputation: 0 May-16-2019, 02:22 PM (This post was last modified: May-16-2019, 02:22 PM by jjameson.) 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)``` Reply

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

Forum Jump:

### User Panel Messages ##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020