National Cheng Kung UniversityLAiMM
Machine Learning in Engineering Science / Fall 2026 / Homework

Build and Explain a Stock Forecasting System

Can an LSTM forecast the next trading day's closing price better than a simple baseline, under an honest evaluation protocol?

Submission: individual project and a five-minute video in English. Due date and submission platform: to be announced by the instructor.

Start your implementation

Open starter notebook in Colab · Download Jupyter notebook · Back to course website

English, step-by-step scaffolding: frozen data and CSV fallback, chronological windows, persistence, Ridge, LSTM, validation selection, final-test gate, plots, reproducibility export, and video checklist. The starter has not been executed before publication; students must run it and report their actual results.

This is an ML experiment, not an investment recommendation. You are assessed on correctness, reproducibility, interpretation, and communication, not on profits or whether your LSTM wins. A well-explained negative result can receive full marks.

1. Learning objectives

2. The system you must build

Build one complete workflow: load a saved CSV, check the data, create chronological splits, construct windows, train the models, generate predictions, and display evaluation results. A clearly organized Colab or Jupyter notebook is a sufficient system. A separate web application, live trading connection, paid data feed, and cloud deployment are not required.

The prediction is issued after the market closes on trading day t. For a lookback of L observations, define:

Input: Xt = [Pt-L+1, ..., Pt]
Target: yt = Pt+1
Persistence prediction: P̂t+1 = Pt

Here P is your declared daily closing-price series. The horizon is the next trading observation, not necessarily the next calendar day. Begin with closing price as the only feature. Use L = 20 for the main model comparison; also compare L = 10 versus L = 20 for the LSTM on validation data.

3. Data and provenance

  1. Choose one stock or market ETF and obtain at least 750 daily trading observations from a permitted historical-data source. Do not use fabricated data as the final experiment.
  2. Save the exact CSV used in the experiment. Include at least date and close; record the ticker, market, currency, source URL, retrieval date, date range, and whether prices are adjusted or unadjusted.
  3. Use one consistent price definition across all models. Explain stock splits, dividends, or vendor adjustments that could affect interpretation. A retrospectively adjusted download is not proof that identical data were available historically.
  4. Sort dates in increasing order; check duplicates, missing values, and non-positive prices. Report your cleaning decisions. Do not invent weekend observations or interpolate prices using future values.
  5. Record a SHA-256 checksum of the saved CSV. Respect the provider's license; if redistribution is restricted, provide a permitted instructor-access route and exact acquisition instructions rather than publishing the data publicly.

4. Chronological evaluation: non-negotiable rules

Explain that rolling one-step prediction with newly observed history is different from forecasting an entire future month recursively. This HW requires only the former.

5. Required models and experiment

ModelRequired implementationPurpose
PersistencePredict the next close using the most recent observed close.Establish a meaningful no-training baseline.
Linear modelUse Ridge regression with the 20 lagged closing prices. Select any regularization setting using training/validation data only and record it.Ask whether a simpler learned relationship is sufficient.
LSTMUse a small single-layer LSTM, for example 16 hidden units followed by a one-value output layer. Compare lookbacks 10 and 20 on validation data; select one configuration.Evaluate whether a sequential nonlinear model adds useful evidence.

Keep the work practical for a free Colab session or local CPU: for example, no more than 20 training epochs per configuration, batch size 32, and early stopping based on validation loss. Record the actual architecture, loss, optimizer, learning rate, epoch limit, stopping rule, and seed. Transformer and attention models are optional extensions, not prerequisites for full marks.

6. Results and interpretation

Provide the following evidence, generated from your actual run:

  1. One split diagram: show the complete price history with training, validation, and test boundaries.
  2. One validation comparison: compare the two LSTM lookbacks and justify your selected configuration without consulting test results.
  3. One test-score table: MAE and RMSE for persistence, Ridge, and the selected LSTM, on identical dates. State which error is being averaged and the price units.
  4. One aligned forecast plot: show actual and predicted test prices with correct target dates. Include a zoomed interval so a smooth-looking curve cannot conceal errors.
  5. One learning-curve plot: show LSTM training and validation loss and explain evidence for underfitting or overfitting.
  6. One failure analysis: examine the date with the largest absolute LSTM test error. Report the observed price, prediction, persistence prediction, and error. Discuss plausible limitations without inventing a causal market explanation.

Calculate MAE = mean(|prediction - target|) and RMSE = sqrt(mean((prediction - target)2)) after converting predictions back to the original units. Explain why tracking the price level closely does not, by itself, demonstrate reliable direction prediction or a profitable strategy.

Interpretability requirement: explain the information each model receives, what the LSTM is intended to retain over time, and what your evidence cannot establish. The lookback comparison is a controlled sensitivity experiment, not a causal explanation. If you add attention weights or feature-attribution plots, do not present them as proof of causality.

7. Five-minute video: required storyboard

Record a screen presentation with your own English narration. Target 5:00 minutes; an acceptable range is 4:30-5:30. Show your notebook and actual results, not only prepared slides. A webcam is optional.

TimeWhat you must explain or demonstrate
0:00-0:30State the ticker, prediction horizon, available information, and research question.
0:30-1:20Show the data source, date boundaries, one window/target example, and how you prevented leakage.
1:20-2:20Explain persistence, Ridge, and your LSTM. Show the input shape, architecture, and validation-based lookback choice.
2:20-3:35Demonstrate your prediction workflow on a held-out test window and display the three-model score table and aligned plots. You may use previously saved training outputs; do not spend the video waiting for training.
3:35-4:30Explain the largest-error example, whether LSTM beat persistence, and one limitation of your conclusions.
4:30-5:00Show how another student can reproduce the run; disclose AI assistance and summarize what you personally checked and learned.

Do not replace your explanation with AI-generated narration. AI may help you draft the script, but you must understand and explain the submitted work yourself. Supply an instructor-accessible video link or an MP4; check viewing permissions before submission.

8. Submission checklist

Package these in one folder or ZIP. No trading account, paid AI subscription, paid API key, custom domain, or public repository is required.

9. Grading rubric

CriterionPointsEvidence
Data integrity and leakage prevention20Traceable data, chronological splits, training-only preprocessing, and correct window alignment.
Working forecasting system20Complete workflow, all three models, and a valid held-out prediction demonstration.
Fair evaluation and experimental evidence25Validation-based selection, matching test dates, correct original-unit metrics, and informative plots.
Interpretation and limitations15Lookback comparison, largest-error analysis, and conclusions supported by evidence.
Reproducibility and AI transparency10Runnable submission, data fingerprint, settings, environment, and truthful AI-use record.
Five-minute explanation10Clear English narration, actual system demonstration, and understanding of personal implementation decisions.
Total100High prediction accuracy is not a substitute for a valid experiment.

A missing baseline, future-data leakage, or tuning on the test set makes the affected model comparison invalid. Document a failed run honestly rather than inventing results. Scores are based on submitted evidence, not unsupported claims.

10. Official technical references