Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Lane 2 · kotlin-core] Precision/Recall/F1 — Averaging enum + internal ConfusionMatrixAccumulator

未关闭
#1,226 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
半天
新手友好度
48/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
kotlin

调研方向

First read Accuracy.kt, the helpers from #1225, and the contract decisions in #1224; this issue is blocked on both. Implement the public Averaging enum and the internal accumulator and reducer in sk.ainet.lang.nn.metrics, then test the reducer’s modes and zero-division case. Run ./gradlew :skainet-lang:skainet-lang-core:apiDump; done means the API dump adds Averaging only and the fixture produces the specified counts.

由索引模型根据 Issue 内容生成。

描述

coding size:s skill:kotlin-core sub-issue training

Sub-issue of #1222 (Precision, Recall and F1Score metrics).

Lane: 2 · Kotlin core
Skill needed: Kotlin; read Accuracy.kt and the helpers from #1225 first.
Size: s (~3–4 h)
Blocked by: #1225 (helpers) and the contract decisions from #1224 (zero-division, macro class set, binary mode).

What to do

  1. Add public enum class Averaging { BINARY, MACRO, MICRO } in
    sk.ainet.lang.nn.metrics (own file, KDoc on each value — this is public API).
    Semantics per #1224; the working definitions are:
    • BINARY — report class 1 (the positive class) only; requires ≤ 2 classes;
    • MACRO — unweighted mean of the per-class value over the class set decided in #1224;
    • MICRO — pool TP / FP / FN over all classes, then apply the formula once.
  2. Add internal class ConfusionMatrixAccumulator(dim: Int = -1, threshold: Float? = null)
    with
    • fun <T : DType, V> update(predictions: Tensor<T, V>, targets: Tensor<out DType, *>)
      — walks every sample via the #1225 helper and increments per-class tp / fp / fn
      (Long counters keyed by class index; a wrong prediction is one FP for the predicted
      class and one FN for the target class);
    • fun counts(): Map<Int, ClassCounts> (a small internal data class ClassCounts(tp, fp, fn));
    • fun reset().
  3. Add internal fun reduce(counts, averaging, perClass: (tp: Long, fp: Long, fn: Long) -> Double): Double
    implementing the three averaging modes and the zero-division convention from #1224
    in one place, so Precision, Recall and F1Score each contribute only a formula.
  4. Tests: the accumulator is internal to skainet-lang-core, and the metric tests live
    in skainet-backend-cpu (they need DirectCpuExecutionContext to build tensors). Two
    options — pick one and say which in the PR:
    • test it through Precision / Recall in #1227 / #1228 (then this PR ships
      with a reduce() unit test only, which needs no tensors), or
    • put an accumulator test in skainet-lang-core's commonTest, building tensors with
      DenseTensorDataFactory().fromFloatArray(...) + SimpleTensor(...) the way
      OperationExecutor.createTensor does.
  5. ./gradlew :skainet-lang:skainet-lang-core:apiDump — the dump gains Averaging and
    nothing else.

Acceptance

  • Averaging public, documented, in the API dump
  • ConfusionMatrixAccumulator + reduce() internal, no public surface
  • reduce() tested for macro / micro / binary and the zero-division case
  • Reference fixture from #1224 (pred [2,0,1,2], target [2,1,1,0]) yields counts
    {0: (0,1,1), 1: (1,0,1), 2: (1,1,0)} as (tp, fp, fn)

Notes

Don't build Precision / Recall / F1Score here even though it's tempting — they are
separate good first issues (#1227, #1228, #1229) precisely so three people can each
ship one small PR against this accumulator.

主要语言
Kotlin
星标
52
派生
15
平均合并
1 天 15 小时
30 天内合并 PR
36

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

SKaiNET-developers/SKaiNET 的其他 Issue

查看 SKaiNET-developers/SKaiNET 的全部 Issue

相似的 Issue

更多 Kotlin Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。