Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Confidence intervals over time with polynomial regression jjameson Unladen Swallow Posts: 1 Threads: 1 Joined: May 2019 Reputation: 0 Likes received: 0 #1 May-16-2019, 02:22 PM (This post was last modified: May-16-2019, 02:22 PM by jjameson. Edited 1 time in total.) 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) ``` « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Can I evaluate a Chebyshev polynomial using a function player1681 1 156 Nov-22-2019, 06:33 AM Last Post: scidam Machine Learning Polynomial Regression braveYug 0 137 Nov-13-2019, 11:41 AM Last Post: braveYug datetime intervals - dataframe selection (via plotted data) karlito 0 107 Nov-12-2019, 08:16 AM Last Post: karlito Regression Event navigates 1 177 Oct-01-2019, 07:27 PM Last Post: Larz60+ sklearn regression to excel punksnotdead 1 455 Apr-14-2019, 12:32 PM Last Post: punksnotdead Logistic regression with Tensorflow kiton 1 724 Nov-28-2018, 07:34 PM Last Post: kiton To draw a polynomial solution pianistseb 2 615 Nov-13-2018, 01:45 PM Last Post: pianistseb Draw Weibull distribution probability function based on Confidence interval farzadtb 1 1,063 Jul-31-2018, 03:21 PM Last Post: Vysero linspace not dividing equal intervals sheel 0 778 Jan-16-2018, 04:28 PM Last Post: sheel pandas Dataframe as "confidence table" for matchmaking? takaa 1 1,077 Nov-28-2017, 07:48 PM Last Post: takaa

Forum Jump:

Users browsing this thread: 1 Guest(s)