Adv Python HKPU 2025 (Under Construction)

 Advanced Python

L1: 29 Mar 2025

Github: https://github.com/1eo1ui/2025-advanced-python

Github tutorial beginning video: https://youtu.be/iv8rSLsi1xo?si=a9oKgYuUxFDh-YNe

Github   =   

   Data analyst / Programmer's cloud drive + their hub of Social media (like Facebook, Instagram)


Github basics (木子AI研究所): https://youtu.be/FopO8IQLX_E?si=8BEq6-PF4acPHAbS

  • Free open-source apps & tools + with the top-world-class resources: 
    • Learn English
    • Exam questions & solutions
    • Programming
    • e-Books
    • PPT templates / examples
    • Weekly / monthly magazine

1) Github interesting projects - Hello Github: https://hellogithub.com/en

2) Github Searching: a) search without an objective / a specific purpose; b) search to solve a problem

 a) search without an objective / a specific purpose: Github search --> Like a news page, Your clicking "Star" will tell your interest to the Github's AI engine, so that he can recommend some projects that may attract you!! Github > Home - it is a Dashboard ==> "Explore"



    • Explore   >   Topics



  • e.g. Chrome Extension   >   Chrome Extension of Video dwonload:

 

 



Download Github Desktop at: desktop.github.com


Learn Github: w3schools Github tutorial







  • YouTube: 股價預測AI實作,Python程式碼逐行解說,實測結果大公開 (Cantonese, by 解密遊俠)
    • AI有沒有可能跟據過往的股價紀錄,預測明天的股價呢?就算做不到很精準,只要預測到大致的走向,也足以用來操作賺錢了。如果我真的做到這個AI,豈不發大財?我立刻參考一些網上廣傳的範例,並根據自己的AI開發經驗做了些改良,最後得出更神準的AI!那麼,這個AI是否真的能用來賺錢呢?我將會大方地告訴大家確切的答案!我會毫無保留地展示這個AI的所有程式碼,和指出網上那些範例忽略了的重點!
    • 本片內容包括:
  • 0. 環境準備:Python、Jupyter Notebook、TensorFlow、Docker image 1. AI的功能設計(AI functional design) 2. 數據採集的方法(data collection):Yahoo Finance、Pandas、數據視覺化(data visualization)、日K、Scikit-Learn、MinMaxScaler、Numpy 3. AI模型的設計(AI modeling):Keras、LSTM(Long Short-Term Memory)、循環神經網絡(recurrent neural network)、optimizer、Adam、loss function、mean squared error 4. 訓練AI的方法(AI training strategy):訓練集(training set)、驗證集(validation set)、測試集(test set)、過度擬合(over-fit)、Early Stopping、epochs 5. 實測的結果(model evaluation):前進式回測(forward test) 6. 實用性的評價(practicality evaluation):CvRMSE(Coefficient of Variation of the Root Mean Squared Error)
    • 這條影片係教你用 Python + Jupyter Notebook + LSTM 去預測股票價格,步驟都好清晰,以下係重點流程同簡化版 notebook 範例:
    • 主要步驟:
      • 1. 安裝環境:Python、Jupyter Notebook、TensorFlow、Pandas、Scikit-Learn。
      • 2. 數據採集:用 Yahoo Finance 下載股票歷史數據(例如匯豐控股 0005.HK),只用收市價。
      • 3. 數據處理:用 MinMaxScaler 標準化數據,製作 60 天收市價預測第 61 天收市價的訓練集和測試集。
      • 4. 建立模型:用 Keras 建立兩層 LSTM + 兩層 Dense 的神經網絡。
      • 5. 訓練模型:用 Early Stopping 防止 overfit,分 training/validation/test set。
      • 6. 預測及評估:將預測結果還原回原始價格,與實際股價比較。
    • 簡化 Jupyter Notebook 範例:
python
import yfinance as yf
import pandas as pd
import numpy as np
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense
from tensorflow.keras.callbacks import EarlyStopping
import matplotlib.pyplot as plt

# 下載數據
df = yf.download('0005.HK', period='10y')
data = df[['Close']].rename(columns={'Close':'GT'})

# 標準化
scaler = MinMaxScaler()
scaled = scaler.fit_transform(data)

# 製作訓練資料
x, y = [], []
for i in range(60, len(scaled)):
    x.append(scaled[i-60:i])
    y.append(scaled[i])
x, y = np.array(x), np.array(y)

# 分割訓練/測試集
split = int(0.8 * len(x))
x_train, x_test = x[:split], x[split:]
y_train, y_test = y[:split], y[split:]

# 建立模型
model = Sequential([
    LSTM(50, return_sequences=True, input_shape=(60,1)),
    LSTM(50),
    Dense(25),
    Dense(1)
])
model.compile(optimizer='adam', loss='mse')

# 訓練
es = EarlyStopping(patience=10, restore_best_weights=True)
model.fit(x_train, y_train, epochs=1000, validation_split=0.2, callbacks=[es])

# 預測
pred = model.predict(x_test)
pred = scaler.inverse_transform(pred)
y_test_inv = scaler.inverse_transform(y_test)

# 畫圖
plt.plot(y_test_inv, label='GT')
plt.plot(pred, label='Prediction')
plt.legend()
plt.show()
  • 重點提醒:  
  • 影片最後都有講,這種 AI 其實多數只係預測「明天等於今日」,真正賺錢未必得,但學習 AI 實作就好有用!









留言

這個網誌中的熱門文章

Intro to Data Science in Python

Get started with Python - Google

AI Learning Roadmap from Beginners to Experts - Getting Started from 2025 - Phase 2: Programming Fundamentals - 01a: Linux Training Academy