Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

14.6 Moving Averages (Python) GDP File data: Year GDP 1980 2788.1 1981 3126.8 1982 3253.2 1983 3534.6 1984 3930.9 1985 4217.5 1986 4460.1 1987 4736.4

14.6 Moving Averages (Python)

image text in transcribed

image text in transcribed

image text in transcribed

GDP File data:

Year GDP
1980 2788.1
1981 3126.8
1982 3253.2
1983 3534.6
1984 3930.9
1985 4217.5
1986 4460.1
1987 4736.4
1988 5100.4
1989 5482.1
1990 5800.5
1991 5992.1
1992 6342.3
1993 6667.4
1994 7085.2
1995 7414.7
1996 7838.5
1997 8332.4
1998 8793.5
1999 9353.5
2000 9951.5
2001 10286.2
2002 10642.3
2003 11142.2
2004 11853.3
2005 12623
2006 13377.2
2007 14028.7
2008 14291.5
2009 13973.7
2010 14498.9
2011 15075.7
2012 15684.8
2013 16768
2014 17419
The GDP file contains GDP for an unspecified country from 1980 to 2014. Use the pandas rolling() method to forecast GDP with moving averages for the specified time period taken as input. Add the moving average forecast to the data frame in a new column called mov_avgtime period. Print off the head of the data frame. Then calculate the mean absolute error and the mean squared error for the actual GDP and the forecasted GDP for 2014 If the input is 2 Then the output should be: Year GDP mov_avg2 0 1980 2788.1 NaN 1 1981 3126.8 2957.45 2 1982 3253.2 3190.00 3 1983 3534.6 3393.90 4 1984 3930.9 3732.75 The mean absolute error for 2014 is 325.5 The mean squared error for 2014 is 105950.25 LAB ACTIVITY 14.6.1: Moving Averages 0/2 Downloadable files GDP.csv Download Load default template. 4 main.py 1 # Load necessary modules 2 import pandas as pd 3 from sklearn.metrics import mean_absolute_error, mean_squared_error 5 # Import dataset using pandas 6 GDP = pd.read_csv('GDP.CSW') 7 print(GDP) 9 # Get input 10 window int(input) 12 # calculate moving average and store it as a new column in existing data frame 8 11 13 14 15 #print data frame head 16 print(GDP.head() 17 | 18 # create variables for actual and forecasted values of GDP for 2014 19 #gdp_2014 = #store the actual GDP for 2014 here 22 #gdp_forecast_2014 = # Store the forecasted value of GDP for 2014 here 22 23 # calculate the mean absolute error of the the actual GDP and forecasted GDP for 2014 24 #mae_2014 = #calculate mean absolute error here 25 #print("The mean absolute error for 2014 is', mae_2014) 26 27 # calculate the mean squared error of the the actual GDP and forecasted GDP for 2014 28 #mse_2014 = #calculate mean squared error here 29 #print('The mean squared error for 2014 is',mse_2014)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions