# report代做 | 代做Machine learning | project代做 | Python | 代写assignment – QBUS6840 Assignment 1 Homework

### QBUS6840 Assignment 1 Homework

report代做 | 代做Machine learning | project代做 | Python | 代做html | 代写assignment – 该题目是一个常规的html的练习题目代写, 是有一定代表意义的report/Machine learning/Python/html等代写方向, 该题目是值得借鉴的assignment代写的题目 This assignment has been designed to help students to develop basic predictive analytics skills on synthetic and possible real applied problems, including data visualization, model building and analysis in terms of understanding in theory, practices with raw data and programming in Python.

1. Consider the (odd order) centred MA-( 2 + 1 ) (i.e. CMA-( 2 + 1 )) and the two layer (2m+1)x(2n+1)-MA.
``````(a) Show that a 3x5-MA is equivalent to a 7-term weighted moving average and find out
all the weights. For general nonnegative integers m and n, argue that a
(2m+1)x(2n+1)-MA is equivalent to a X-term weighted moving average. What is X?
``````
``````(b) Write out the formula  for the CMA-( 2 + 1 ), and use your general formula to write
out the formula  for CMA-11.
``````
``````(c) Prove that when the given time series {} is periodic with the period 2 + 1 , the
smoothed time series {} by the CMA-( 2 + 1 ) is a constant series. Find out the
value of that constant.
``````
``````(d) Again assume that the time series {} is periodic with the period 2 + 1. Its first
order difference time series {} is defined as
``````
``````=+1, for =1, 2, 3, ....
``````
``````Prove that the new time series {} is also periodic with the period M, and identify
the smallest value for M.
``````
``````Apply CMA-(M) to {} and find out the resulting smoothed time series {}.
``````

You must clearly show each step of reasoning.

[25 Marks]

1. The data set CBA_1991-2018.csv on Canvas (data was downloaded from https://au.finance.yahoo.com/quote/CBA.AX?p=CBA.AX) c ontains the monthly stock prices of Commonwealth Bank of Australia (CBA) from August 1991 to December 2018.

(a) Write Python script to load the data and extract High stock prices and make it as a time series with Datetime as index and store it as a new csv file CBA_1991- 2018High.csv.

``````Transform the time series data by the first order and the second order differencing and
produce their plots (three plots) in order to become familiar with it. Include the plots
in your submission. You must use Datetime index as the x-axis of your plots.
``````

(b) Write your own Python script to implement smoothing using the CMA-24 method and plot the smoothed time series of the original time series series in (a) against it. And write Python code to use pandas packages rolling_mean function (ver 0.17) or rolling function (ver 0.20+) to re-do the CMA-24 smoothing. Compare results of your own implementation and the results of pandas implementation. Have you got the same results? Why? Please refer to pandas documentation regarding how to use rolling or rolling_mean.

(c) report the scale-dependent measures Root Mean Squared Error (RMSE) and Mean Absolute Error (MAE) for the methods in (b) [the errors between your smoothed prices and the true prices (be careful of missing smoothed values at the beginning and/or the ending sides!)].

(d) The CMA-5 smoothing can be turned into a forecasting method to do one-step ahead forecasting as follows

#### (+1+2+3+4)

``````Use this forecasting method to forecast the last four months in the time series of (a)
(i.e., we assume we dont know them when doing forecasting). Write your own
``````

(e) It may not be of much accuracy using the CMA-5 forecasting method for a given time series. However, for the time series in (a), you may seek for a forecasting method defined as

``````+1= 0 + 1 1+ 2 2+ 3 3+ 4 4,
``````
``````where  0 + 1 + 2 + 3 + 4 = 1 , by using linear regression.
``````
``````For the given time series in (a), formulate a least squared linear regression problem
and write your Python program to implement this regression task to work out weights
0 , 1 , 2 , 3 , 4. You may use all the data except for the last four months in the
time series of (a).
``````
``````With the newly learned weights  0 , 1 , 2 , 3 , 4 , do one-step ahead forecasting for
the last four months.
``````
``````Hint: Given the special condition  0 + 1 + 2 + 3 + 4 = 1 on
``````
`````` 0 , 1 , 2 , 3 , 4 , you may design your regression problem such that there are only 4
weights (e.g.,  1 , 2 , 3 , 4 ) to be solved. Think about what the training data should
be in this case.
``````
``````(f) Report the scale-dependent measures Root Mean Squared Error (RMSE) and Mean
Absolute Error (MAE) for the methods in (d) and (e) [the errors between predicted
prices and the true prices.].
``````

[25 Marks]

1. Consider the dataset plastic.csv which consists of the monthly sales (in thousands) of product A for a plastics manufacturer for fives years.
``````(a) Plot the time series of sales of product A. Analyze and identify seasonal fluctuations
and/or a trend-cycle?
``````
``````(b) Write your own Python program to implement the classical multiplicative
decomposition to calculate the trend-cycle and seasonal indices. Discuss whether
the results support the graphical interpretation from part (a).
``````
``````(c) Compute and plot the seasonally adjusted data.
``````
``````(d) Change one observation to be an outliner (e.g., add 500 to one observation), and
recompute the seasonally adjusted data. What is the effect of the outlier?
``````
``````(e) To use the decomposition for forecasting, build a regression model for the trend-
cycle component, and then use this trend-cycle components and other components to
predictions).
``````

[20 Marks]

1. The data set Airline.csv is a famous time series of monthly total international airline passengers from Jan 1949 – Dec, 1960. You are required to forecast the next four months passenger numbers via using relevant models or methods as specified in the following tasks:
``````(a) Plot the series in your Python program and discuss the main features of the data.
``````
``````(b) Write your own Python script to implement the Holts linear trend method on the
Airline series. You may follow the Component form at
https://otexts.com/fpp2/holt. html to define a Python function which takes at least
three arguments, i.e., the time series y, the smoothing parameter for level  and the
smoothing parameter for the trend , and returns the smoothed time series. Make
your argument on setting a reasonable value for  0 and  0 , respectively. In your code,
explore the combination of different values of  and  e.g. 0.2, 0.4. 0.6 and 0.8.
Calculate and record the one-step ahead SSE (sum of the squared errors) for each pair
of values  and . Choose Four representative smoothed series to plot and use the
legends to indicate corresponding  and  values and SSE. Discuss the effect of  and
on the forecasts based on the 16 cases, report which values of  and  work best
``````
``````among 16 cases, and predict what the optimal  and  could be.
``````
``````(c) The Holts linear trend method also provides multi-horizon forecast, please refer to
https://otexts.com/fpp2/holt.html. In your Python program, write code to select the
optimal values of  and  with respect to the two-step ahead (or horizon) forecast
SSE. Plot the SSE for the two-step ahead (horizon) forecast against  and . Use the
optimal two-step ahead  and  to generate forecasts for the next four Months. Plot
the original data series and the smoothing series based on the optimal two-step ahead
alpha  and  with all the forecasts, against each other.
Hint: This is a 3D plot and you will need to iterate over a range of  and  values
``````

[30 Marks]

1. In your program, you may include the following code to implement SSE.
``````def sse(x, y):
return np.sum(np.power(x - y,2))
``````
1. In Task 3, you may need build a linear regression model. This can be easily done by using Python sklearn package (a Machine learning package). The following code section would be helpful
``````from sklearn import linear_model
lm = linear_model.LinearRegression(fit_intercept=True)
model = lm.fit(X,y) % Fitting linear model to data
``````
``````forecasts = lm.predict(x) % times series forecasting
``````
``````where X and y are input and dependence variables respectively.
``````
1. In answering question (c) in Task 4, you may produce about 100 alpha and 100 beta values, respectively, by using
``````alphas = np.arange(0.01,1,0.01)
betas = np.arange(0.01,1,0.01)
``````

Presentation

• Please submit your project through the electronic system on the Canvas.
• The assignment material to be handed in will consist of a PDF or WORD document that:
``````i) Details ALL steps.
``````
``````ii) Demonstrates an understanding of the relevant principles of forecasting by showing
``````iii) Clearly and appropriately presents any relevant tables, graphs and screen dumps from
``````iv) Provide your program code (if any) as separated py file(s). You will be instructed