YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

California Housing Predictor

使用 scikit-learn 在 California Housing 数据集上训练随机森林回归模型,并通过 GitHub Actions 在推送到 main 时自动训练并上传到 Hugging Face Hub。

本地运行

python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -r requirements.txt
python train.py

训练后会生成:model.joblib、metrics.json、config.json。

一次性配置(建议顺序)

1. Hugging Face

  1. 在 Hugging Face 新建 Model 仓库(例如 california-housing-predictor)。
  2. 在 Settings → Access Tokens 创建带 Write 权限的 token。
  3. 记下 Hub 路径:你的HF用户名/仓库名(例如 EmporioSabo/california-housing-predictor)。

2. GitHub 仓库与密钥

  1. 在 GitHub 新建空仓库(不要勾选自动添加 README,避免首次推送冲突)。
  2. 打开 Settings → Secrets and variables → Actions,添加:
    • HF_TOKEN:上一步的 Hugging Face token。
    • HF_REPO:上一步的 Hub 完整路径(同上例)。

3. 推送代码

在本项目目录执行(将 YOUR_USER/REPO 换成你的 GitHub 仓库):

cd california-housing-predictor
git init -b main
git add train.py requirements.txt .gitignore README.md .github/workflows/train-and-upload.yml
git commit -m "Add California housing model and HF upload workflow"
git remote add origin https://github.com/YOUR_USER/REPO.git
git push -u origin main

推送后可在 Actions 查看 Train and Upload to Hugging Face 是否成功;也可在 Actions 里手动 Run workflow 重跑。

验收

  • GitHub Actions 最近一次运行通过(绿色)。
  • Hugging Face 仓库 Files 页在 main 分支可见:model.joblib、metrics.json、config.json、README.md。

交付

将 GitHub 仓库 URL 与 Hugging Face 仓库 URL 发到课程微信群。

Downloads last month
5
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support