目录

Moon Online Models

Moon Online Models (moon-online-models) is a MoonBit library for online regression and incremental learning. It is designed for real-time model updating and continuous learning scenarios such as CTR (Click-Through Rate) prediction, device metrics monitoring, and real-time business forecasting.

Architecture & Core Features

  • Recursive Least Squares (RLS): Online linear regression with a forgetting factor, suitable for time-series and non-stationary data streams.
  • Online Logistic Regression (FTRL-Proximal): Follow-The-Regularized-Leader proximal algorithm with L1 and L2 regularization support. Highly optimized for sparsity, ideal for CTR prediction.
  • Feature Standardization: Welford’s online algorithm to incrementally track the mean and variance, standardizing data streams on the fly.
  • Model Snapshot (Serialization): Built-in ToJson and FromJson serialization for all models using MoonBit’s core JSON derive macros.
  • Incremental Evaluation: Online tracking of metrics like LogLoss and Mean Squared Error (MSE).

Getting Started

Add the dependency to your project:

moon add phjphj676/moon-online-models

Example: FTRL Logistic Regression

test "ftrl example" {
  // Initialize FTRL model with 2 features
  let model = FTRL::new(2, alpha=0.1, l1=0.5, l2=1.0)
  
  // Update model incrementally with new data stream
  model.update([1.0, 0.0], 1.0)
  model.update([0.0, 1.0], 0.0)
  
  // Predict on new data
  let pred = model.predict([1.0, 0.0])
  inspect(pred > 0.5, content="true")
}

Example: Tracking Incremental Metrics

test "metrics example" {
  let metrics = MetricsTracker::new()
  metrics.update(0.9, 1.0) // predict 0.9, actual 1.0
  metrics.update(0.2, 0.0) // predict 0.2, actual 0.0
  
  let logloss = metrics.log_loss()
  let mse = metrics.mse()
  inspect(mse < 0.1, content="true")
}

Hackathon / OSC 2026 Declaration

This project is natively developed in MoonBit from scratch.

  • License: Apache-2.0
  • Scope: Implements machine learning models natively in MoonBit, addressing the lack of online learning libraries in the MoonBit ecosystem.
  • Extensibility: Future updates can easily extend the OnlineLearner trait to support sparse features, adaptive learning rates (Adagrad), and more.
关于

MoonBit 在线回归与增量学习库,包含递归最小二乘、在线逻辑回归、特征标准化和模型快照等功能

297.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号