โมเดลไม่ได้หยุดเรียนรู้
เมื่อเรา DeployA model does not stop learning
when we deploy it
Website → Features → Prediction → Drift → Retraining → Champion/ChallengerWebsite → Features → Prediction → Drift → Retraining → Champion/Challenger
0 2 1 * * · IDLEChampion v001 กับ v002 เปลี่ยนอะไร?What changed between Champion v001 and v002?
เลขเวอร์ชันหมายถึง model artifact ที่ deploy ไม่ได้แปลว่าต้องเปลี่ยน algorithm เสมอ โมเดลใหม่อาจใช้ algorithm เดิม แต่ฝึกใหม่ด้วยข้อมูลและ window ที่ต่างออกไปThe version identifies a deployed model artifact. It does not necessarily mean a new algorithm; a new artifact may retrain the same algorithm on different data and a different window.
| Champion | Algorithm | Feature set | Training window | ข้อมูลฝึกTraining data | สิ่งที่เปลี่ยนWhat changed | เหตุผล DeployDeployment reason |
|---|---|---|---|---|---|---|
| v001 | Logistic Regression | Engineered | Initial 2012 | Jan–Dec 2012 | รุ่นเริ่มต้นInitial artifact | ผ่าน design validationPassed design validation |
| v002 | Logistic Regression | Engineered | Expanding | Jan 2011–Oct 2013 | Window + ข้อมูล + coefficientsWindow + data + coefficients | 2013-11 · ΔF1 +0.0233 · PROMOTE |
| v003? | Random Forest candidate | Engineered | ต้องแข่งขัน 7 windowsMust compete across 7 windows | กำหนด ณ retraining eventDefined at the retraining event | Algorithm อาจเปลี่ยนจริงAlgorithm may truly change | ยังไม่ Deploy — ต้องผ่าน walk-forward และ guardrailsNot deployed—must pass walk-forward tests and guardrails |
Algorithm Benchmark — ก่อนเลือกโมเดลAlgorithm benchmark — before model selection
การทดลองนี้ควบคุมให้ทุก algorithm เห็น engineered features ชุดเดียวกัน ฝึกด้วย Jan–Sep 2012 และประเมินบนข้อมูลอนาคต Oct–Dec 2012 โดยไม่สุ่มสลับเวลา ไม่มี hyperparameter search และใช้ F1 เป็น primary metricEvery algorithm sees the same engineered features, trains on Jan–Sep 2012, and is evaluated on the later Oct–Dec 2012 holdout. There is no hyperparameter search; F1 is the primary metric.
| Algorithm | ลักษณะFamily | Accuracy | Balanced Acc. | Precision | Recall | F1 | ROC-AUC | ผลตาม F1F1 result |
|---|---|---|---|---|---|---|---|---|
| Random Forest | Bagging trees | 0.843 | 0.745 | 0.691 | 0.564 | 0.621 | 0.852 | WINNER ✓ |
| Logistic Regression | Linear | 0.776 | 0.755 | 0.507 | 0.716 | 0.593 | 0.829 | Teaching baselineTeaching baseline |
| Histogram Gradient Boosting | Boosted trees | 0.822 | 0.726 | 0.626 | 0.550 | 0.585 | 0.816 | — |
ข้อจำกัด: นี่เป็น holdout เดียวและ configuration ที่กำหนดไว้ล่วงหน้า ยังไม่ใช่ข้อสรุป production ควรเพิ่ม rolling-origin cross-validation, probability calibration, latency/model-size และ hyperparameter tuning แบบ nested temporal validation ก่อนอนุมัติเปลี่ยน algorithmLimitation: this is one holdout with preset configurations, not a production verdict. Add rolling-origin cross-validation, calibration, latency/model-size checks, and hyperparameter tuning with nested temporal validation before changing the deployed algorithm.
ข้อมูลและโจทย์ที่โมเดลแก้Data and prediction problem
ใช้ UCI ElectricityLoadDiagrams2011–2014 จากลูกค้าไฟฟ้า 36 รายที่ข้อมูลต่อเนื่อง รวมข้อมูลทุก 15 นาทีเป็นหนึ่งแถวต่อ client-day แล้วแบ่งพลังงานเป็น Night, Morning, Afternoon, Evening และ TotalWe use 36 continuous clients from UCI ElectricityLoadDiagrams2011–2014. The 15-minute readings are aggregated into one client-day row with Night, Morning, Afternoon, Evening, and Total energy.
Target label: HIGH / LOW — พยากรณ์ว่าโหลด “วันพรุ่งนี้” จะสูงกว่าค่ามัธยฐานแบบ expanding ของลูกค้ารายนั้น ในเดือนปฏิทินและวันในสัปดาห์เดียวกันหรือไม่ จึงรักษาขอบเขตการทำนายล่วงหน้า 1 วันpredict whether tomorrow's load exceeds that client's expanding historical median for the same calendar month and weekday, preserving a strict one-day prediction boundary.
สร้างกี่โมเดล และตัดสินใจอย่างไรHow many models, and how we decide
เดือนปกติใช้ Champion 1 โมเดลทำนายและไม่ฝึกใหม่ เมื่อ drift/performance trigger ทำงาน จึงฝึก Challenger 7 โมเดลจากหน้าต่างข้อมูลต่างกัน แล้วนำมาเทียบกับ Champion เดิม รวม 8 แถวในการแข่งขันIn a normal month, one Champion predicts and nothing is retrained. A drift/performance trigger trains seven Challengers on different windows and compares them with the current Champion: eight competition rows.
7 windows: Expanding · Recent 3M · Rolling 6M · Rolling 12M · Tumbling 3M · Seasonal-2Y · Hybrid
ผู้ชนะไม่ได้เป็น Champion อัตโนมัติ: ต้องเพิ่ม F1 อย่างน้อย 0.02 และผ่าน Balanced Accuracy guardrail ตลอด 24 เดือน lab สร้าง Challenger 28 artifacts จาก 4 retraining events และ Promote จริง 1 ครั้งA winner is not promoted automatically: it needs at least +0.02 F1 and must pass the Balanced Accuracy guardrail. Across 24 months, the lab creates 28 Challenger artifacts in four retraining events and promotes once.
โมเดลที่เลือกใช้: อะไรคงที่ อะไรเป็นตัวแข่งขัน?Selected model: what stays fixed, and what competes?
Algorithm: Logistic Regression
ทุก Champion และ Challenger ใช้ binary Logistic Regression แบบเดียวกัน โดยตั้ง class_weight=balanced, solver=lbfgs และ max_iter=2000 สิ่งที่แข่งขันใน lab คือ “ข้อมูลช่วงไหนควรใช้ฝึก” ไม่ใช่ “algorithm ใดชนะ”Every Champion and Challenger uses the same binary Logistic Regression with class_weight=balanced, solver=lbfgs, and max_iter=2000. The experiment varies the training history, not the algorithm.
ขั้น preprocessing อยู่ใน Pipeline เดียวกับโมเดล: ตัวเลขเติม missing ด้วย median แล้ว Standardize; หมวดหมู่เติมด้วย most frequent แล้ว One-hot encode จึงลด train/serve skew และป้องกัน preprocessing leakagePreprocessing ships in the same Pipeline: numeric values use median imputation plus standardization; categorical values use most-frequent imputation plus one-hot encoding. This reduces train/serve skew and prevents preprocessing leakage.
ทำไมเลือก Logistic Regression?Why Logistic Regression? เป็น baseline ที่ตีความ coefficient ได้ ฝึก Challenger 7 ตัวได้เร็ว และทำให้บทเรียนโฟกัส feature drift กับ window strategy ถ้าจะเปรียบเทียบ Random Forest/XGBoost ต้องทำเป็น experiment ชั้นถัดไปด้วย temporal validation เดียวกันIt is an interpretable, fast baseline that keeps the lesson focused on feature drift and window strategy. Random Forest/XGBoost would be a separate experiment under the same temporal validation.
ด่านที่ 1 — เลือก Feature Set ก่อน DeployGate 1 — feature-set selection before deployment
ฝึกบน Jan–Sep 2012 และตัดสินบน Oct–Dec 2012 ซึ่งมาทีหลังตามเวลาTrain on Jan–Sep 2012; decide on the later Oct–Dec 2012 validation period.
| Logistic Regression | Accuracy | Balanced Acc. | F1 | ROC-AUC | ผลResult |
|---|---|---|---|---|---|
| Raw features | 0.493 | 0.526 | 0.346 | 0.519 | — |
| Engineered features | 0.776 | 0.755 | 0.593 | 0.829 | SELECTED ✓ |
จึงเลือก Logistic Regression + engineered features เป็น v001 แล้ว refit ด้วยข้อมูล Jan–Dec 2012 ก่อนเริ่ม simulation ปี 2013Therefore v001 is Logistic Regression with engineered features, refit on Jan–Dec 2012 before the 2013 simulation begins.
ด่านที่ 2 — เมื่อ Drift trigger: Window ไหนชนะ และเปลี่ยนโมเดลหรือไม่?Gate 2 — after a drift trigger: which window wins, and do we deploy it?
ทุกแถวด้านล่างยังเป็น Logistic Regression + engineered features เหมือนกัน ต่างกันเฉพาะ training window ผู้ชนะเลือกจาก F1 ก่อน แล้วใช้ Balanced Accuracy และ ROC-AUC เป็นตัวแก้เสมอ การ Promote ต้องผ่านทั้ง ΔF1 ≥ +0.020, Balanced Accuracy ลดไม่เกิน 0.010 และมี positive examples อย่างน้อย 100 ตัวอย่างEvery row below is the same Logistic Regression plus engineered features; only the training window changes. Winner ranking uses F1, then Balanced Accuracy and ROC-AUC as tie-breakers. Promotion requires ΔF1 ≥ +0.020, no more than 0.010 Balanced Accuracy regression, and at least 100 positive examples.
| เดือนประเมินEvaluation month | Champion | Challenger ที่ชนะBest Challenger | Champion F1 | Winner F1 | ΔF1 | การตัดสินใจDecision |
|---|---|---|---|---|---|---|
| 2013-07 | v001 · Initial 2012 | Rolling 12M | 0.782 | 0.789 | +0.0067 | KEEP |
| 2013-11 | v001 · Initial 2012 | Expanding | 0.749 | 0.772 | +0.0233 | PROMOTE → v002 |
| 2014-04 | v002 · Expanding | Rolling 12M | 0.806 | 0.807 | +0.0016 | KEEP |
| 2014-10 | v002 · Expanding | Expanding | 0.824 | 0.827 | +0.0027 | KEEP |