$24
Please submit your homework report to iLMS before 23:59 on Jun 20. A link to a shared Google document ‘hw4 5 demo registration’ will be announced later for you to reserve a time slot for an individual demonstration with TA. You are encouraged to consult or collaborate with other students while solving the homework problems, however you are required to turn in your own version of the report and programs written in your own words with supporting materials. Copying will not be tolerated.
Aim
Please estimate a trend in a time series regression model, especially with deep neural network methods multilayer perceptrons and LSTM RNN model. The DNN models could predict the price curve within the nite steps. You may apply new methods or use new packages to improve the the quality of clustering, but if you do so, you have to give a brief introduction of the key concepts and provide necessary citations, instead of just direct copy paste or importing. However, in this assignment, you must have models utilizing multilayer perceptrons(MLP) and LSTM via keras(ver 2.2)[1] or tensor ow(ver 1.8).contrib.keras. In order to save your keras.model, please install h5py(ver. 2.8) with pip. Once an algorithm package is merged or imported into your code, please list the package link in your reference and describe its mathematical concepts in your report followed by the reason for adoption.
Dataset Description
The dataset ‘apple price close.csv’ is the minute APPLE stock close price downloaded from www.google.com/ nance. All the records in the dataset ars ordered by time stamp covering from May 21 to Jun 9. The headers in the dataset are time Taiwan, index min and close price. Note based on the trading time window, there are only 391 index min from 0 to 390 within a trading day. In this dataset, it covers the min-trading history for 14 days.
1
Submission Format
You have to submit a compressed le hw4 studentID.zip which contains the following les:
hw4 studentID.ipynb: detailed report, Python codes, results, discussion and math-ematical descriptions;
hw4 studentID.tplx: extra Latex related setting, including the bibliography;
hw4 studentID.bib: citations in the "bibtex" format;
hw4 studentID.pdf: the pdf version of your report which is exported by your ipynb with
%% jupyter nbconvert - -to latex - -template hw4 studentID.tplx hw4 studentID.ipynb
%% pd atex hw4 studentID.tex
%% bibtex hw4 studentID
%% pd atex hw4 studentID.tex
%% pd atex hw4 studentID.tex
Other les or folders in a workable path hierarchy to your jupyter notebook (ipynb).
Coding Guidelines
For the purpose of individual demonstration with TA, you are required to create a func-tion code in your jupyter notebook, as speci ed below, to reduce the data dimensionality, learn a classi cation model, and evaluate the performance of the learned model.
hw4 studentID demo(in x=None,in y=None,mode=None,model type=None, header=True)
{ in x: [string] CSV le for ‘data’.
{ in y: [string] CSV le for ‘labels’. Assign a le when mode=‘train’.
{ mode: [string] mode=‘preprocessing’ Please set in y=None. If you have any preprocessing, please do the preprocessing in this mode. After preprocessing, save
the processed data as ‘HW4 studentID MLP data.csv’ and ‘HW4 studentID MLP labels.csv’ (‘HW4 studentID LSTM data.csv’ and ‘HW4 studentID LSTM labels.csv’) with
header if header=True or without header when header=False. You can design your own ‘* data.csv’ format. For ‘* labels.csv’, there would be only one column for the prices. Assume timesteps= n and denote the sequence of price as fsrgmr=01. We want to predict sr under mode=‘train’. For example, when header=True, data dim=1, the in x=‘HW4 studentID MLP data.csv’ could be
2
x1
x2
xn
.
.
.
sr n
sr n+1
sr 1
.
.
.
and with (batch
size= ,timesteps= n, data
size=k),
the in
x=‘HW4
studentID
LSTM
data.csv’ could be
batch
idx
x
(0)
(0)
(0)
(1)
(1)
(n 1)
(n 1)
x0
x1
xk 1
x0
xk 1
x0
xk 1
(1)
(1)
(1)
(2)
(2)
(n)
(n)
0
x0
x1
xk 1
x0
xk 1
x0
xk 1
.
.
.
( 1)
( 1)
( 1)
( )
( )
( +n 2)
( +n 2)
x0
x1
xk 1
x0
xk 1
x0
xk 1
.
.
.
.
.
.
and in
y‘HW4
studentID
MLP
labels.csv’
labels.csv’ is set as
y
... .
sr
...
and in y=‘HW4 studentID LSTM
batch
idx
y
y(n
1)
0
y(n)
.
.
.
.
y( +n 2)
.
.
.
.
.
.
You can design your ‘HW4 studentID MLP data.csv’ and
‘HW4 studentID LSTM data.csv’ base on the timesteps and data di-mension in your models with data dim 1, including the price di er-ence, indicator for increase or decrease and so on. Just remember to reshape it to match your deployment of the model when mode=‘train’.
mode=‘train’ The ‘x in’ is assigned to ‘HW4 studentID MLP data.csv’
(or ‘HW4 studentID LSTM data.csv’). ‘y in’ is assigned to ‘HW4 studentID MLP labels.csv’ (or ‘HW4 studentID LSTM labels.csv’). Please do MLP and LSTM in this mode and output the corresponding les which are speci ed next.
{ model type:[string] when mode=‘train’. use model type=‘MLP’ or model type=‘LSTM’ to select training model.
3
{ header:[bool] if header=True, there has header in ‘HW4 studentID MLP data.csv’ (or ‘HW4 studentID LSTM data.csv’); if header=False, there is no header in the ‘HW4 studentID MLP data.csv’ (or ‘HW4 studentID LSTM data.csv’).
In mode=‘train’, please output the following ‘CSV’ les with headers and your model to ‘h5’ les. Also set your models as globel when mode=‘train’, model type=‘MLP’ or mode=‘train’, model type=‘LSTM’. Please set the loss function as loss=’mean squared error’.
MLP:
le 1 ’HW4 studentID MLP.csv’ with header
optimizer,loss, batch size, timesteps, data dim, avg loss, last loss
optimizer: type of optimizer[2];
loss: type of loss[3];
batch size: how many instances in one batch;
timesteps: time steps to look back;
data dim: data dimension for each instance;
avg loss: the average loss for overall batches;
last loss: the loss for the last batch training.
le 2 ‘HW4 studentID MLP model.h5’: save you model with keras
if your keras LSTM model is named with ‘model’ model.save(‘HW4 studentID MLP model.h5’)
LSTM:
le 1 ’HW4 studentID LSTM.csv’ with header
optimizer,loss, batch size, timesteps, data dim, avg loss, last loss
optimizer: type of optimizer[2];
loss: type of loss[3];
batch size: how many instances in one batch;
timesteps: time steps to look back;
data dim: data dimension for each instance;
avg loss: the average loss for overall batches;
last loss: the loss for the last batch training.
le 2 ‘HW4 studentID LSTM model.h5’: save you model with keras
if your keras LSTM model is named with ‘model’ model.save(‘HW4 studentID LSTM model.h5’)
4
In demonstration, the training dataset is the same as homework assignment. The score of the demonstration has two parts, MLP and LSTM. For each part, the score will be graded by the ranking of average batch loss value for the test dataset via your model. The test dataset will not be o ered. It is tested only on the given webpage and go through your preprocessing before evaluation. In the script le ‘hw4 studentID.py’, please add the following code to your program before you import keras.
import tensor ow as tf from keras.backend.tensor ow backend import set session con g = tf.Con gProto() con g.gpu options.allow growth = True
set session(tf.Session(con g=con g))
Note: the script you submit in demonstration will be referred when TA is grading your report and jupyter notebook. Make sure TA knows how to modify your code if TA can not execute your jupyter notebook properly.
Report Requirement
List names of packages used in your program;
A owchart for Preprocessing with explanation to your method. A diagram for your MLP model.
A diagram for your LSTM model.
Compare and conclude results between two methods,
5.1 Basic Requirement
Implement 2 methods after the pre-processing is nished.
Based on the average of loss value, decide the architecture of your models. The grading will also refer to this value.
Please make sure hw4 student ID demo is functional and can output the required les in both mode=‘preprocessing’ and mode=‘train’.
If you apply new methods or use new packages to improve the classi cation perfor-mance, you have to give a brief introduction of the key concepts and provide necessary citations/links, instead of just direct copy paste or importing.
Please submit your ‘report’ in English. Be aware that a ‘report’ is much more than a ‘program.’
5
References
Guideline for keras. https://keras.io/getting-started/sequential-model-guide/. Accessed: 2018-06-09.
optimizer function in keras. https://keras.io/optimizers/. Accessed: 2018-06-09.
loss function in keras. https://keras.io/losses/. Accessed: 2018-06-09.
6